From fa126ee33f2d9b8eb59012e83d1547e29365e06d Mon Sep 17 00:00:00 2001 From: fiso64 Date: Thu, 25 May 2023 21:55:02 +0200 Subject: [PATCH] .conf file support --- README.md | 7 +++++++ slsk-batchdl/Program.cs | 15 +++++++++++++-- slsk-batchdl/Properties/launchSettings.json | 3 +-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4e7a317..27c00f1 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,13 @@ Download youtube playlist: ``` To include unavailable videos, you will need to provide an api key with `--youtube-key`. Get it here https://console.cloud.google.com. Create a new project, click "Enable Api" and search for "youtube data", then follow the prompts. +Supports .conf files: Create a file named `slsk-batchdl.conf` in the same directory as the exe and write your arguments there, e.g: +``` +--username "fakename" +--password "fakepass" +--pref-format "flac" +``` + ## Notes: - YouTube playlist downloading is unreliable since there are no track name / artist tags - The CSV file must be saved with `,` as field delimiter and `"` as string delimiter, encoded with UTF8 diff --git a/slsk-batchdl/Program.cs b/slsk-batchdl/Program.cs index 2162c8d..371913e 100644 --- a/slsk-batchdl/Program.cs +++ b/slsk-batchdl/Program.cs @@ -4,7 +4,6 @@ using Soulseek; using Konsole; using System.Net.NetworkInformation; - class Program { static SoulseekClient client = new SoulseekClient(); @@ -52,7 +51,7 @@ class Program Console.WriteLine(" --yt-parse Enable if you have a csv file of YouTube video titles and channel names; attempt to parse."); Console.WriteLine(); Console.WriteLine(" -s --single Search & download a specific track"); - Console.WriteLine(" -a --album Search & download a specific album. DOES NOTHING"); + Console.WriteLine(" -a --album Does nothing"); Console.WriteLine(); Console.WriteLine(" --pref-format Preferred file format (default: mp3)"); Console.WriteLine(" --pref-length-tol Preferred length tolerance (if length col provided) (default: 3)"); @@ -163,6 +162,16 @@ class Program MaxSampleRate = -1, }; + string confPath = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), "slsk-batchdl.conf"); + if (System.IO.File.Exists(confPath)) + { + string confArgs = System.IO.File.ReadAllText(confPath); + List finalArgs = new List(); + finalArgs.AddRange(ParseCommand(confArgs)); + finalArgs.AddRange(args); + args = finalArgs.ToArray(); + } + for (int i = 0; i < args.Length; i++) { switch (args[i]) @@ -560,6 +569,8 @@ class Program if (reverse) tracks.Reverse(); + if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) + throw new Exception("No soulseek username or password"); await client.ConnectAsync(username, password); object lockObj = new object(); diff --git a/slsk-batchdl/Properties/launchSettings.json b/slsk-batchdl/Properties/launchSettings.json index a06b1b1..8467749 100644 --- a/slsk-batchdl/Properties/launchSettings.json +++ b/slsk-batchdl/Properties/launchSettings.json @@ -1,8 +1,7 @@ { "profiles": { "slsk-batchdl": { - "commandName": "Project", - "commandLineArgs": "-s \"nanoray mimicloq\"" + "commandName": "Project" }, "YouTube": { "commandName": "Project",