1
0
Fork 0
mirror of https://github.com/fiso64/slsk-batchdl.git synced 2024-12-31 18:52:41 +00:00
This commit is contained in:
fiso64 2024-05-13 11:10:06 +02:00
parent 6c70442449
commit e4505a53c7
2 changed files with 20 additions and 10 deletions

View file

@ -139,6 +139,7 @@ static class Program
static bool removeBrackets = false; static bool removeBrackets = false;
static bool reverse = false; static bool reverse = false;
static bool useYtdlp = false; static bool useYtdlp = false;
static string ytdlpArgument = "";
static bool skipExisting = false; static bool skipExisting = false;
static string m3uOption = "fails"; static string m3uOption = "fails";
static bool useTagsCheckExisting = false; static bool useTagsCheckExisting = false;
@ -186,7 +187,7 @@ static class Program
// undocumented options: // undocumented options:
// --artist-col, --title-col, --album-col, --length-col, --yt-desc-col, --yt-id-col // --artist-col, --title-col, --album-col, --length-col, --yt-desc-col, --yt-id-col
// --remove-brackets, --spotify, --csv, --string, --youtube, --random-login // --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 <input> [OPTIONS]" + Console.WriteLine("Usage: slsk-batchdl <input> [OPTIONS]" +
"\n" + "\n" +
"\n <input> <input> is one of the following:" + "\n <input> <input> is one of the following:" +
@ -752,6 +753,9 @@ static class Program
preferredCond.AcceptMissingProps = false; preferredCond.AcceptMissingProps = false;
necessaryCond.AcceptMissingProps = false; necessaryCond.AcceptMissingProps = false;
break; break;
case "--yt-dlp-argument":
ytdlpArgument = args[++i];
break;
default: default:
throw new ArgumentException($"Unknown argument: {args[i]}"); throw new ArgumentException($"Unknown argument: {args[i]}");
} }
@ -1427,6 +1431,7 @@ static class Program
} }
} }
static List<Track> InteractiveModeAlbum(List<List<Track>> list) static List<Track> InteractiveModeAlbum(List<List<Track>> list)
{ {
int aidx = 0; int aidx = 0;
@ -1685,7 +1690,7 @@ static class Program
string saveFilePathNoExt = GetSavePathNoExt(title); string saveFilePathNoExt = GetSavePathNoExt(title);
downloading = true; downloading = true;
RefreshOrPrint(progress, 0, $"yt-dlp download: {track}", 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); RefreshOrPrint(progress, 100, $"Succeded: yt-dlp completed download for {track}", true);
break; break;
} }

View file

@ -471,13 +471,16 @@ public static class YouTube
return results; return results;
} }
public static async Task<string> YtdlpDownload(string id, string savePathNoExt) public static async Task<string> YtdlpDownload(string id, string savePathNoExt, string ytdlpArgument="")
{ {
Process process = new Process(); Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo(); ProcessStartInfo startInfo = new ProcessStartInfo();
if (ytdlpArgument == "")
ytdlpArgument = "\"{id}\" -f bestaudio/best -ci -o \"{savepath-noext}.%(ext)s\" -x";
startInfo.FileName = "yt-dlp"; 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.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true; startInfo.RedirectStandardError = true;
@ -489,13 +492,15 @@ public static class YouTube
process.Start(); process.Start();
process.WaitForExit(); 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) string parentDirectory = Path.GetDirectoryName(savePathNoExt);
{ string[] musicFiles = Directory.GetFiles(parentDirectory, "*", SearchOption.TopDirectoryOnly)
if (Utils.IsMusicFile(file)) .Where(file => Utils.IsMusicFile(file))
return file; .ToArray();
} if (musicFiles.Length > 0)
return musicFiles[0];
return ""; return "";
} }