From 0c74d92935f85cf1604fac6dc1e0b5c97addaaeb Mon Sep 17 00:00:00 2001 From: Josh Creek Date: Sun, 29 Aug 2021 15:47:53 +0100 Subject: [PATCH] feat(*): Add CheckForNewVideosAsync --- YouTubeChannelDownloader/Program.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/YouTubeChannelDownloader/Program.cs b/YouTubeChannelDownloader/Program.cs index 54022be..2df5d1c 100644 --- a/YouTubeChannelDownloader/Program.cs +++ b/YouTubeChannelDownloader/Program.cs @@ -47,5 +47,31 @@ namespace YouTubeChannelDownloader DeleteLocalFile(pathString); } } + + private static async Task> CheckForNewVideosAsync() + { + // Get the current videos on the channel + IReadOnlyList videos = await _youtube.Channels.GetUploadsAsync(_channelId); + + List indexedVideos = new List(); + + foreach (var (video, index) in videos.Reverse().WithIndex()) + { + YouTubeVideo youtubeVideo = new YouTubeVideo() + { + PlaylistVideo = video, + VideoNumber = index + 1, // These are zero-indexed but for episode counts we want 1 indexing + }; + + indexedVideos.Add(youtubeVideo); + } + + List downloadedVideoIds = _db.DownloadedVideos.Select(dv => dv.DownloadedVideoId).ToList(); + + // Make a new list of only the videos we've not alread downloaded + List newVideos = indexedVideos.Where(v => !downloadedVideoIds.Contains(v.PlaylistVideo.Id)).ToList(); + + return newVideos; + } } }