From e4505a53c72098120b2626844f537cb96c8085ec Mon Sep 17 00:00:00 2001 From: fiso64 Date: Mon, 13 May 2024 11:10:06 +0200 Subject: [PATCH] commit --- slsk-batchdl/Program.cs | 9 +++++++-- slsk-batchdl/YouTube.cs | 21 +++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/slsk-batchdl/Program.cs b/slsk-batchdl/Program.cs index 92ca664..4f6a314 100644 --- a/slsk-batchdl/Program.cs +++ b/slsk-batchdl/Program.cs @@ -139,6 +139,7 @@ static class Program static bool removeBrackets = false; static bool reverse = false; static bool useYtdlp = false; + static string ytdlpArgument = ""; static bool skipExisting = false; static string m3uOption = "fails"; static bool useTagsCheckExisting = false; @@ -186,7 +187,7 @@ static class Program // undocumented options: // --artist-col, --title-col, --album-col, --length-col, --yt-desc-col, --yt-id-col // --remove-brackets, --spotify, --csv, --string, --youtube, --random-login - // --danger-words, --pref-danger-words, --no-modify-share-count + // --danger-words, --pref-danger-words, --no-modify-share-count, --yt-dlp-argument Console.WriteLine("Usage: slsk-batchdl [OPTIONS]" + "\n" + "\n is one of the following:" + @@ -752,6 +753,9 @@ static class Program preferredCond.AcceptMissingProps = false; necessaryCond.AcceptMissingProps = false; break; + case "--yt-dlp-argument": + ytdlpArgument = args[++i]; + break; default: throw new ArgumentException($"Unknown argument: {args[i]}"); } @@ -1427,6 +1431,7 @@ static class Program } } + static List InteractiveModeAlbum(List> list) { int aidx = 0; @@ -1685,7 +1690,7 @@ static class Program string saveFilePathNoExt = GetSavePathNoExt(title); downloading = true; RefreshOrPrint(progress, 0, $"yt-dlp download: {track}", true); - saveFilePath = await YouTube.YtdlpDownload(id, saveFilePathNoExt); + saveFilePath = await YouTube.YtdlpDownload(id, saveFilePathNoExt, ytdlpArgument); RefreshOrPrint(progress, 100, $"Succeded: yt-dlp completed download for {track}", true); break; } diff --git a/slsk-batchdl/YouTube.cs b/slsk-batchdl/YouTube.cs index 5b0a8e6..30482fe 100644 --- a/slsk-batchdl/YouTube.cs +++ b/slsk-batchdl/YouTube.cs @@ -471,13 +471,16 @@ public static class YouTube return results; } - public static async Task YtdlpDownload(string id, string savePathNoExt) + public static async Task YtdlpDownload(string id, string savePathNoExt, string ytdlpArgument="") { Process process = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo(); + if (ytdlpArgument == "") + ytdlpArgument = "\"{id}\" -f bestaudio/best -ci -o \"{savepath-noext}.%(ext)s\" -x"; + startInfo.FileName = "yt-dlp"; - startInfo.Arguments = $"\"{id}\" -f bestaudio/best -ci -o \"{savePathNoExt}.%(ext)s\" -x"; + startInfo.Arguments = ytdlpArgument.Replace("{id}", id).Replace("{savepath-noext}", savePathNoExt); startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardError = true; @@ -489,13 +492,15 @@ public static class YouTube process.Start(); process.WaitForExit(); - string[] files = Directory.GetFiles(Path.GetDirectoryName(savePathNoExt), Path.GetFileName(savePathNoExt + ".ext") + ".*"); + if (File.Exists(savePathNoExt + ".opus")) + return savePathNoExt + ".opus"; - foreach (string file in files) - { - if (Utils.IsMusicFile(file)) - return file; - } + string parentDirectory = Path.GetDirectoryName(savePathNoExt); + string[] musicFiles = Directory.GetFiles(parentDirectory, "*", SearchOption.TopDirectoryOnly) + .Where(file => Utils.IsMusicFile(file)) + .ToArray(); + if (musicFiles.Length > 0) + return musicFiles[0]; return ""; }