public async Task <Subscription> CreateSubscription(Uri uri) { // Fixup youtube channel url's (get "uploads" playlist) uri = YouTubeUrlHelper.FixYouTubeChannelUri(uri); // Running "ExtractInformation" here might be quite slow var info = await ytdlService.UsingYoutubeDL(async ytdl => await ytdl.ExtractInformation(uri.ToString(), false)); if (info.Type != YoutubeDLWrapper.UrlType.Playlist && info.Type != YoutubeDLWrapper.UrlType.MultiVideo) { logger.LogDebug($"Subscription type for {uri}: {info.Type}"); throw new Exception("Invalid or unsupported URL format!"); } // Fetch thumbnail, real channel title var metadata = new List <KeyValuePair <string, string> >(); if (uri.Host.EndsWith("youtube.com")) { metadata = MetadataScraper.ScrapeMetadata(uri).ToList(); } return(new Subscription() { SubscriptionId = info.Id, SubscriptionProviderId = Id, Name = GetFirst(metadata, "name", "og:title", "twitter:title") ?? info.Title, Description = info.Description, ThumbnailPath = GetFirst(metadata, "link:thumbnailUrl", "link:url", "og:image", "twitter:image") ?? info.Thumbnail?.ToString(), OriginalUrl = uri.ToString() }); }
public async Task <bool> CanHandleSubscriptionUrl(Uri uri) { try { uri = YouTubeUrlHelper.FixYouTubeChannelUri(uri); var info = await ytdlService.UsingYoutubeDL(async ytdl => await ytdl.ExtractInformation(uri.ToString(), false)); return(info.Type == YoutubeDLWrapper.UrlType.Playlist || info.Type == YoutubeDLWrapper.UrlType.MultiVideo); } catch (Exception ex) { logger.LogDebug(ex, $"Cannot handle subscription URL {uri}"); return(false); } }