예제 #1
0
        public async Task <ChannelVideosStored> GetAndUpdateChannelVideos(ChannelData c)
        {
            var cv = await ChannelVideosCollection.Get(c.Id);

            // fix updated if missing. Remove once all records have been updated
            var mostRecent = cv?.Vids.OrderByDescending(v => v.Updated).FirstOrDefault();

            if (cv != null && mostRecent != null && cv.Updated == default(DateTime))
            {
                cv.Updated = mostRecent.Updated;
            }

            var needsUpdate = cv == null || Expired(cv.Updated, RCfg.RefreshChannelVideos) ||
                              cv.From != RCfg.From;         // when from is chaged, update all videos

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

            if (cv == null)
            {
                cv = new ChannelVideosStored {
                    ChannelId = c.Id, ChannelTitle = c.Title, Updated = DateTime.UtcNow
                }
            }
            ;
            else
            {
                cv.Updated = DateTime.UtcNow;
            }

            var queryForm = cv.From != RCfg.From ? RCfg.From : mostRecent?.PublishedAt ?? RCfg.From;
            var created   = await Yt.VideosInChannel(c, queryForm, RCfg.To);

            cv.Vids.AddRange(created);
            cv.From = RCfg.From;
            await ChannelVideosCollection.Set(cv);

            return(cv);
        }
예제 #2
0
 public async Task <ChannelVideosStored> ChannelVideosStored(ChannelData c) => await ChannelVideosCollection.Get(c.Id);