Beispiel #1
0
        public async Task UpdateMetadata(IEnumerable <Video> videos, bool updateMetadata, bool updateStatistics)
        {
            foreach (var video in videos)
            {
                var info = await ytdlService.UsingYoutubeDL(async ytdl =>
                                                            await ytdl.ExtractInformation(video.OriginalUrl, false));

                if (updateMetadata)
                {
                    video.Name          = info.Title;
                    video.Description   = info.Description;
                    video.Published     = info.Timestamp;
                    video.LastUpdated   = DateTimeOffset.Now;
                    video.ThumbnailPath = info.Thumbnail.ToString();
                    video.UploaderName  = info.Uploader;
                }

                if (updateStatistics)
                {
                    video.Views  = info.ViewCount;
                    video.Rating = ProviderHelpers.CalculateRating(info.LikeCount, info.DislikeCount);
                }
            }
        }
Beispiel #2
0
        public async IAsyncEnumerable <Video> FetchVideos(Subscription subscription)
        {
            int            tries = 3;
            UrlInformation info;

            do
            {
                info = await ytdlService.UsingYoutubeDL(async ytdl =>
                                                        await ytdl.ExtractInformation(subscription.OriginalUrl, true));
            }while (info == null && tries-- > 0);

            if (info == null)
            {
                throw new Exception("Failed to fetch videos (timed out)!");
            }

            Queue <UrlInformation> queue = new Queue <UrlInformation>();

            if (info.Entries != null)
            {
                info.Entries.ForEach(queue.Enqueue);
            }

            int index = 0;

            while (queue.Count > 0)
            {
                var entry = queue.Dequeue();
                switch (entry.Type)
                {
                case UrlType.Playlist:
                case UrlType.MultiVideo:
                    if (entry.Entries != null)
                    {
                        entry.Entries.ForEach(queue.Enqueue);
                    }
                    break;

                case UrlType.Video:
                    yield return(new Video()
                    {
                        SubscriptionProviderId = entry.Id,
                        VideoProviderId = Id,
                        VideoId = entry.Id,
                        Name = entry.Title,
                        Description = entry.Description,
                        Subscription = subscription,
                        PlaylistIndex = index++,
                        Published = (entry.Timestamp != DateTime.MinValue) ? entry.Timestamp : DateTimeOffset.Now,
                        LastUpdated = DateTimeOffset.Now,
                        ThumbnailPath = entry.Thumbnail?.ToString(),
                        UploaderName = entry.Uploader,
                        OriginalUrl = entry.WebpageUrl?.ToString(),
                        Views = entry.ViewCount,
                        Rating = ProviderHelpers.CalculateRating(entry.LikeCount, entry.DislikeCount)
                    });

                    break;
                }
            }
        }