diff --git a/TwitchDownloaderCLI/Modes/DownloadVideo.cs b/TwitchDownloaderCLI/Modes/DownloadVideo.cs index fe0043df..df291fad 100644 --- a/TwitchDownloaderCLI/Modes/DownloadVideo.cs +++ b/TwitchDownloaderCLI/Modes/DownloadVideo.cs @@ -43,12 +43,7 @@ private static VideoDownloadOptions GetDownloadOptions(VideoDownloadArgs inputOp if (!Path.HasExtension(inputOptions.OutputFile) && inputOptions.Quality is { Length: > 0 }) { - if (inputOptions.Quality.Contains("audio", StringComparison.OrdinalIgnoreCase)) - inputOptions.OutputFile += ".m4a"; - else if (char.IsDigit(inputOptions.Quality[0]) - || inputOptions.Quality.Contains("source", StringComparison.OrdinalIgnoreCase) - || inputOptions.Quality.Contains("chunked", StringComparison.OrdinalIgnoreCase)) - inputOptions.OutputFile += ".mp4"; + inputOptions.OutputFile += FilenameService.GuessVodFileExtension(inputOptions.Quality); } VideoDownloadOptions downloadOptions = new() diff --git a/TwitchDownloaderCore/Tools/FilenameService.cs b/TwitchDownloaderCore/Tools/FilenameService.cs index 67796551..e59cb99e 100644 --- a/TwitchDownloaderCore/Tools/FilenameService.cs +++ b/TwitchDownloaderCore/Tools/FilenameService.cs @@ -124,6 +124,29 @@ public static string ReplaceInvalidFilenameChars([AllowNull] string filename) return newName.ReplaceAny(FilenameInvalidChars, '_'); } + [return: MaybeNull] + public static string GuessVodFileExtension([AllowNull] string qualityString) + { + if (string.IsNullOrWhiteSpace(qualityString)) + { + return ".mp4"; + } + + if (qualityString.Contains("audio", StringComparison.OrdinalIgnoreCase)) + { + return ".m4a"; + } + + if (char.IsDigit(qualityString[0]) + || qualityString.Contains("source", StringComparison.OrdinalIgnoreCase) + || qualityString.Contains("chunked", StringComparison.OrdinalIgnoreCase)) + { + return ".mp4"; + } + + return null; + } + public static FileInfo GetNonCollidingName(FileInfo fileInfo) { fileInfo.Refresh(); diff --git a/TwitchDownloaderWPF/PageVodDownload.xaml.cs b/TwitchDownloaderWPF/PageVodDownload.xaml.cs index 1202a5e2..a42d03b6 100644 --- a/TwitchDownloaderWPF/PageVodDownload.xaml.cs +++ b/TwitchDownloaderWPF/PageVodDownload.xaml.cs @@ -206,7 +206,7 @@ public VideoDownloadOptions GetOptions(string filename, string folder) Filename = filename ?? Path.Combine(folder, FilenameService.GetFilename(Settings.Default.TemplateVod, textTitle.Text, currentVideoId.ToString(), currentVideoTime, textStreamer.Text, checkStart.IsChecked == true ? new TimeSpan((int)numStartHour.Value, (int)numStartMinute.Value, (int)numStartSecond.Value) : TimeSpan.Zero, checkEnd.IsChecked == true ? new TimeSpan((int)numEndHour.Value, (int)numEndMinute.Value, (int)numEndSecond.Value) : vodLength, - viewCount, game) + (comboQuality.Text.Contains("Audio", StringComparison.OrdinalIgnoreCase) ? ".m4a" : ".mp4")), + viewCount, game) + FilenameService.GuessVodFileExtension(comboQuality.Text)), Oauth = TextOauth.Text, Quality = GetQualityWithoutSize(comboQuality.Text), Id = currentVideoId, @@ -425,7 +425,7 @@ private async void SplitBtnDownloader_Click(object sender, RoutedEventArgs e) FileName = FilenameService.GetFilename(Settings.Default.TemplateVod, textTitle.Text, currentVideoId.ToString(), currentVideoTime, textStreamer.Text, checkStart.IsChecked == true ? new TimeSpan((int)numStartHour.Value, (int)numStartMinute.Value, (int)numStartSecond.Value) : TimeSpan.Zero, checkEnd.IsChecked == true ? new TimeSpan((int)numEndHour.Value, (int)numEndMinute.Value, (int)numEndSecond.Value) : vodLength, - viewCount, game) + (comboQuality.Text.Contains("Audio", StringComparison.OrdinalIgnoreCase) ? ".m4a" : ".mp4") + viewCount, game) + FilenameService.GuessVodFileExtension(comboQuality.Text) }; if (saveFileDialog.ShowDialog() == false) { diff --git a/TwitchDownloaderWPF/WindowQueueOptions.xaml.cs b/TwitchDownloaderWPF/WindowQueueOptions.xaml.cs index ee7c529d..a65fdb5a 100644 --- a/TwitchDownloaderWPF/WindowQueueOptions.xaml.cs +++ b/TwitchDownloaderWPF/WindowQueueOptions.xaml.cs @@ -510,7 +510,7 @@ private void EnqueueDataList() downloadOptions.Filename = Path.Combine(folderPath, FilenameService.GetFilename(Settings.Default.TemplateVod, taskData.Title, taskData.Id, taskData.Time, taskData.Streamer, downloadOptions.TrimBeginning ? downloadOptions.TrimBeginningTime : TimeSpan.Zero, downloadOptions.TrimEnding ? downloadOptions.TrimEndingTime : TimeSpan.FromSeconds(taskData.Length), - taskData.Views, taskData.Game) + (downloadOptions.Quality != null && downloadOptions.Quality.Contains("audio", StringComparison.OrdinalIgnoreCase) ? ".m4a" : ".mp4")); // This is awful + taskData.Views, taskData.Game) + FilenameService.GuessVodFileExtension(downloadOptions.Quality)); VodDownloadTask downloadTask = new VodDownloadTask {