Exemple #1
0
        public async Task <RecommendedVideoStored> GetAndUpdateRecommendedVideos(ChannelVideoListItem v)
        {
            var rv = await RecommendedVideosCollection.Get(v.VideoId);

            var age         = RecommendedRefreshAge(v);
            var needsUpdate = rv == null || Expired(rv.Updated, age);

            if (!needsUpdate)
            {
                return(rv);
            }

            if (rv == null)
            {
                rv = new RecommendedVideoStored {
                    VideoId = v.VideoId, VideoTitle = v.VideoTitle, Updated = DateTime.UtcNow
                }
            }
            ;

            var created = await Yt.GetRelatedVideos(v.VideoId);

            rv.Recommended.Add(new RecommendedVideos {
                Updated = DateTime.UtcNow, Top = RCfg.Related, Recommended = created
            });
            rv.Updated = DateTime.UtcNow;
            await RecommendedVideosCollection.Set(rv);

            return(rv);
        }
Exemple #2
0
        public async Task <RecommendedVideoStored> GetAndUpdateRecommendedVideos(ChannelVideoListItem v)
        {
            var rv = await RecommendedVideosCollection.Get(v.VideoId);

            if (Expired(v.PublishedAt, RCfg.VideoDead))
            {
                return(rv);
            }

            //var mostRecent = rv?.Recommended.OrderByDescending(r => r.Updated).FirstOrDefault();
            var needsUpdate = rv == null || Expired(rv.Updated, RCfg.RefreshRelatedVideos);

            if (!needsUpdate)
            {
                return(rv);
            }

            if (rv == null)
            {
                rv = new RecommendedVideoStored {
                    VideoId = v.VideoId, VideoTitle = v.VideoTitle, Updated = DateTime.UtcNow
                }
            }
            ;

            var created = await Yt.GetRelatedVideos(v.VideoId);

            rv.Recommended.Add(new RecommendedVideos {
                Updated = DateTime.UtcNow, Top = RCfg.Related, Recommended = created
            });
            rv.Updated = DateTime.UtcNow;
            await RecommendedVideosCollection.Set(rv);

            return(rv);
        }

        YoutubeClient ytScaper = new YoutubeClient();