Ejemplo n.º 1
0
        private void ProcessVideos(IEnumerable <YTVideo> videos, SeenItems seenItems, string downloadFolder, int season, LocalMetadata localMetadata)
        {
            var client       = new YoutubeClient();
            var seasonFolder = Path.Combine(downloadFolder, $"Season {season}");

            Directory.CreateDirectory(seasonFolder);
            var episodeNumber = GetLastEpisodeNumber(seasonFolder);

            videos.ToList().ForEach(video =>
            {
                episodeNumber++;

                Console.WriteLine($"  0.00% Downloading {video.Id} {episodeNumber} {video.Title}");
                Console.SetCursorPosition(0, Console.CursorTop - 1);

                var videoFileNameBase = $"S{season.ToString().PadLeft(2, '0')}E{episodeNumber.ToString("N0").PadLeft(2, '0')} " + video.Title.Aggregate("", (agg, cur) => Path.GetInvalidFileNameChars().Contains(cur) ? agg : agg + cur);

                var progress = new ConcurrentProgress <double>(d =>
                {
                    Console.SetCursorPosition(0, Console.CursorTop);
                    Console.Write((d * 100).ToString("N2").PadLeft(6));
                });

                Downloaders.DownloadVideo(client, video, seasonFolder, videoFileNameBase, progress);
                Downloaders.DownloadAllCaptions(client, video, seasonFolder, videoFileNameBase, progress);
                CreateMetadata(video, seasonFolder, videoFileNameBase, localMetadata);

                seenItems.SaveId(video.Id);

                Console.WriteLine();
            });
        }
Ejemplo n.º 2
0
        public void DownloadPlaylist(string id, bool doNotReorder, string downloadFolder, int season = 1)
        {
            if (id == null)
            {
                throw new ArgumentNullException(nameof(id));
            }
            if (downloadFolder == null)
            {
                throw new ArgumentNullException(nameof(downloadFolder));
            }

            Directory.CreateDirectory(downloadFolder);

            var seenItems     = new SeenItems(downloadFolder);
            var localMetadata = new LocalMetadata(HttpClient);

            var playlist = GetPlaylist(id);

            EnsureMetadata(playlist, downloadFolder, localMetadata);

            var allVideos    = playlist.Videos;
            var sortedVideos = doNotReorder ? allVideos : allVideos.OrderBy(item => item.UploadDate).ToList();
            var newVideos    = sortedVideos.Where(video => !seenItems.GetIds().Contains(video.Id.Value));

            ProcessVideos(newVideos, seenItems, downloadFolder, season, localMetadata);
        }