diff --git a/README.md b/README.md index fae0086..64fcb64 100644 --- a/README.md +++ b/README.md @@ -164,6 +164,9 @@ Usage: sldl [OPTIONS] --max-samplerate Maximum file sample rate --min-bitdepth Minimum bit depth --max-bitdepth Maximum bit depth + --strict-title File name must contain title + --strict-artist File path must contain artist name + --strict-album File path must contain album name --banned-users Comma-separated list of users to ignore --pref-format Preferred file format(s), comma-separated (default: mp3) diff --git a/slsk-batchdl/FileManager.cs b/slsk-batchdl/FileManager.cs index 0dc6897..c3d12e8 100644 --- a/slsk-batchdl/FileManager.cs +++ b/slsk-batchdl/FileManager.cs @@ -14,6 +14,7 @@ public class FileManager readonly TrackListEntry tle; readonly HashSet organized = new(); public string? remoteCommonDir { get; private set; } + public string? defaultFolderName { get; private set; } public FileManager(TrackListEntry tle) { @@ -37,9 +38,10 @@ public class FileManager if (tle.source.Type == TrackType.Album && !string.IsNullOrEmpty(remoteCommonDir)) { - string dirname = Path.GetFileName(remoteCommonDir); - string relpath = Path.GetRelativePath(remoteCommonDir, Utils.NormalizedPath(sourceFname)); - parent = Path.Join(parent, dirname, Path.GetDirectoryName(relpath)); + string dirname = defaultFolderName != null ? defaultFolderName : Path.GetFileName(remoteCommonDir); + string normFname = Utils.NormalizedPath(sourceFname); + string relpath = normFname.StartsWith(remoteCommonDir) ? Path.GetRelativePath(remoteCommonDir, normFname) : ""; + parent = Path.Join(parent, dirname, Path.GetDirectoryName(relpath) ?? ""); } return Path.Join(parent, name); @@ -50,6 +52,11 @@ public class FileManager this.remoteCommonDir = remoteCommonDir != null ? Utils.NormalizedPath(remoteCommonDir) : null; } + public void SetDefaultFolderName(string? defaultFolderName) + { + this.defaultFolderName = defaultFolderName != null ? Utils.NormalizedPath(defaultFolderName) : null; + } + public void OrganizeAlbum(List tracks, List? additionalImages, bool remainingOnly = true) { foreach (var track in tracks.Where(t => !t.IsNotAudio)) diff --git a/slsk-batchdl/Help.cs b/slsk-batchdl/Help.cs index 16ebcb2..76efac5 100644 --- a/slsk-batchdl/Help.cs +++ b/slsk-batchdl/Help.cs @@ -1,7 +1,7 @@  // undocumented options // --login, --random-login, --no-modify-share-count, --unknown-error-retries -// --invalid-replace-str, --cond, --pref, --strict-title, --strict-artist, --strict-album +// --invalid-replace-str, --cond, --pref // --fast-search-delay, --fast-search-min-up-speed // --min-album-track-count, --max-album-track-count, --extract-max-track-count, --extract-min-track-count @@ -136,6 +136,9 @@ public static class Help --max-samplerate Maximum file sample rate --min-bitdepth Minimum bit depth --max-bitdepth Maximum bit depth + --strict-title File name must contain title + --strict-artist File path must contain artist name + --strict-album File path must contain album name --banned-users Comma-separated list of users to ignore --pref-format Preferred file format(s), comma-separated (default: mp3) diff --git a/slsk-batchdl/Program.cs b/slsk-batchdl/Program.cs index 7b3c9ce..0175045 100644 --- a/slsk-batchdl/Program.cs +++ b/slsk-batchdl/Program.cs @@ -540,7 +540,7 @@ static partial class Program if (Config.I.albumArtOnly || succeeded && Config.I.albumArtOption != AlbumArtOption.Default) { Console.WriteLine($"\nDownloading additional images:"); - additionalImages = await DownloadImages(tle.list, Config.I.albumArtOption, tracks, organizer); + additionalImages = await DownloadImages(tle, tle.list, Config.I.albumArtOption, tracks); tracks?.AddRange(additionalImages); } @@ -616,12 +616,20 @@ static partial class Program } - static async Task> DownloadImages(List> downloads, AlbumArtOption option, List? chosenAlbum, FileManager fileManager) + static async Task> DownloadImages(TrackListEntry tle, List> downloads, AlbumArtOption option, List? chosenAlbum) { var downloadedImages = new List(); long mSize = 0; int mCount = 0; + var fileManager = new FileManager(tle); + + if (chosenAlbum != null) + { + string dir = Utils.GreatestCommonDirectorySlsk(chosenAlbum.Select(t => t.FirstDownload.Filename)); + fileManager.SetDefaultFolderName(Path.GetFileName(Utils.NormalizedPath(dir))); + } + if (option == AlbumArtOption.Default) return downloadedImages; @@ -710,10 +718,7 @@ static partial class Program PrintAlbum(tracks); } - if (fileManager.remoteCommonDir == null) - { - fileManager.SetRemoteCommonDir(Utils.GreatestCommonDirectorySlsk(tracks.Select(t => t.FirstDownload.Filename))); - } + fileManager.SetRemoteCommonDir(Utils.GreatestCommonDirectorySlsk(tracks.Select(t => t.FirstDownload.Filename))); bool allSucceeded = true; var semaphore = new SemaphoreSlim(1); diff --git a/slsk-batchdl/slsk-batchdl.csproj b/slsk-batchdl/slsk-batchdl.csproj index 8c1b2e2..7efdf46 100644 --- a/slsk-batchdl/slsk-batchdl.csproj +++ b/slsk-batchdl/slsk-batchdl.csproj @@ -27,7 +27,7 @@ - +