Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Audio Only option to mass downloader preferred quality #1159

Merged
merged 3 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions TwitchDownloaderCLI/Modes/DownloadVideo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
23 changes: 23 additions & 0 deletions TwitchDownloaderCore/Tools/FilenameService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions TwitchDownloaderWPF/PageVodDownload.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
{
Expand Down
7 changes: 6 additions & 1 deletion TwitchDownloaderWPF/WindowQueueOptions.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public WindowQueueOptions(List<TaskData> dataList)
if (Directory.Exists(queueFolder))
textFolder.Text = queueFolder;

if (_dataList.Any(x => x.Id.All(char.IsDigit)))
{
ComboPreferredQuality.Items.Add(new ComboBoxItem { Content = "Audio Only" });
}

var preferredQuality = Settings.Default.PreferredQuality;
for (var i = 0; i < ComboPreferredQuality.Items.Count; i++)
{
Expand Down Expand Up @@ -505,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) + ".mp4");
taskData.Views, taskData.Game) + FilenameService.GuessVodFileExtension(downloadOptions.Quality));

VodDownloadTask downloadTask = new VodDownloadTask
{
Expand Down
Loading