diff --git a/Yosu.Youtube.Core/Downloading/VideoDownloader.cs b/Yosu.Youtube.Core/Downloading/VideoDownloader.cs index fc82932..d77f2f7 100644 --- a/Yosu.Youtube.Core/Downloading/VideoDownloader.cs +++ b/Yosu.Youtube.Core/Downloading/VideoDownloader.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Net; using System.Threading; using System.Threading.Tasks; using Gress; @@ -12,9 +13,9 @@ namespace Yosu.Youtube.Core.Downloading; -public class VideoDownloader +public class VideoDownloader(IReadOnlyList? initialCookies = null) { - private readonly YoutubeClient _youtube = new(Http.Client); + private readonly YoutubeClient _youtube = new(Http.Client, initialCookies ?? []); public async Task> GetDownloadOptionsAsync( VideoId videoId, @@ -41,16 +42,22 @@ public async Task DownloadVideoAsync( string filePath, IVideo video, VideoDownloadOption downloadOption, + bool includeSubtitles = true, IProgress? progress = null, CancellationToken cancellationToken = default ) { - // If the target container supports subtitles, embed them in the video too - var trackInfos = !downloadOption.Container.IsAudioOnly - ? ( - await _youtube.Videos.ClosedCaptions.GetManifestAsync(video.Id, cancellationToken) - ).Tracks - : Array.Empty(); + // Include subtitles in the output container + var trackInfos = new List(); + if (includeSubtitles && !downloadOption.Container.IsAudioOnly) + { + var manifest = await _youtube.Videos.ClosedCaptions.GetManifestAsync( + video.Id, + cancellationToken + ); + + trackInfos.AddRange(manifest.Tracks); + } var dirPath = Path.GetDirectoryName(filePath); if (!string.IsNullOrWhiteSpace(dirPath)) diff --git a/Yosu/Services/SettingsService.cs b/Yosu/Services/SettingsService.cs index 7cc6012..5017db5 100644 --- a/Yosu/Services/SettingsService.cs +++ b/Yosu/Services/SettingsService.cs @@ -19,6 +19,8 @@ public partial class SettingsService : SettingsBase, INotifyPropertyChanged public bool ShouldSkipExistingFiles { get; set; } + public bool ShouldInjectSubtitles { get; set; } = true; + public string SoundCloudFileNameTemplate { get; set; } = "$title"; public string SpotifyFileNameTemplate { get; set; } = "$title"; diff --git a/Yosu/ViewModels/YoutubeViewModel.cs b/Yosu/ViewModels/YoutubeViewModel.cs index 3f11524..afcda20 100644 --- a/Yosu/ViewModels/YoutubeViewModel.cs +++ b/Yosu/ViewModels/YoutubeViewModel.cs @@ -107,6 +107,7 @@ await _videoDownloader.DownloadVideoAsync( download.TempFilePath!, download.Video!, downloadOption, + _settingsService.ShouldInjectSubtitles, progress, download.CancellationToken ); diff --git a/Yosu/Views/SettingsPage.xaml b/Yosu/Views/SettingsPage.xaml index 063412a..aa1cdc0 100644 --- a/Yosu/Views/SettingsPage.xaml +++ b/Yosu/Views/SettingsPage.xaml @@ -156,6 +156,25 @@ Text="{Binding Settings.DownloadDir}" /> + + + +