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

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

            videos.ToList().ForEach(video =>
            {
                Console.WriteLine($"  0.00% Downloading {video.Title}");
                Console.SetCursorPosition(0, Console.CursorTop - 1);

                episodeNumber++;

                var videoFileNameBase = $"S01E{episodeNumber.ToString("N0").PadLeft(2, '0')} " + video.Title.Replace('|', '-');

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

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

                seenItems.SaveId(video.Id);

                Console.WriteLine();
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Downloads videos from a YouTube playlist and creates metadata for use in media players.
        /// </summary>
        /// <param name="playlistId">The ID of the YouTube playlist.</param>
        /// <param name="downloadFolder">The folder to download videos to.</param>
        public static void Main(string playlistId, string downloadFolder)
        {
            if (playlistId == null)
            {
                throw new ArgumentNullException(nameof(playlistId));
            }
            if (downloadFolder == null)
            {
                throw new ArgumentNullException(nameof(downloadFolder));
            }

            Directory.CreateDirectory(downloadFolder);

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

            EnsureFfmpegDependency(new Ffmpeg(httpClient));

            var playlist = GetPlaylist(playlistId);

            EnsureMetadata(playlist, downloadFolder, localMetadata);

            var allVideos = playlist.Videos;
            var newVideos = FilterAndSortVideos(allVideos, seenItems.GetIds());

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