Exemple #1
0
        public async Task DownloadAsync(VideoDownloadOption videoOption, Video downloaVideo, Progress <double> progress,
                                        CancellationToken cancellationToken, string fileName)
        {
            if (videoOption.StreamInfos == null)
            {
                throw new InvalidOperationException($"Video '{downloaVideo.Id}' contains no streams.");
            }

            if (fileName == null)
            {
                throw new ArgumentNullException(nameof(fileName));
            }

            var conversion = new ConversionRequestBuilder(fileName)
                             .SetFormat(videoOption.Format)
                             .SetPreset(ConversionPreset.Medium)
                             .Build();

            IsLoading = true;

            await _youtube.Videos.DownloadAsync(
                videoOption.StreamInfos,
                conversion,
                progress,
                cancellationToken
                );
        }
Exemple #2
0
        public static DownloadViewModel CreateDownloadViewModel(
            this IViewModelFactory factory,
            Video video,
            string filePath,
            string format,
            VideoDownloadOption videoOption,
            SubtitleDownloadOption?subtitleOption)
        {
            var viewModel = factory.CreateDownloadViewModel();

            viewModel.Video          = video;
            viewModel.FilePath       = filePath;
            viewModel.Format         = format;
            viewModel.VideoOption    = videoOption;
            viewModel.SubtitleOption = subtitleOption;

            return(viewModel);
        }
Exemple #3
0
        public async Task DownloadAsync(
            VideoDownloadOption videoDownloadOption,
            SubtitleDownloadOption?subtitleDownloadOption,
            string filePath,
            IProgress <double>?progress         = null,
            CancellationToken cancellationToken = default)
        {
            await EnsureThrottlingAsync(cancellationToken);

            try
            {
                var conversion = new ConversionRequestBuilder(filePath)
                                 .SetFormat(videoDownloadOption.Format)
                                 .SetPreset(ConversionPreset.Medium)
                                 .Build();

                await _youtube.Videos.DownloadAsync(
                    videoDownloadOption.StreamInfos,
                    conversion,
                    progress,
                    cancellationToken
                    );

                if (subtitleDownloadOption != null)
                {
                    var subtitleFilePath = Path.ChangeExtension(filePath, "srt");

                    // Not passing progress because it's insignificant and would require splitting
                    await _youtube.Videos.ClosedCaptions.DownloadAsync(
                        subtitleDownloadOption.TrackInfo,
                        subtitleFilePath,
                        null,
                        cancellationToken
                        );
                }
            }
            finally
            {
                Interlocked.Decrement(ref _concurrentDownloadCount);
            }
        }