1
0
Fork 0
mirror of https://github.com/fiso64/slsk-batchdl.git synced 2024-12-22 14:32:40 +00:00

fix album art download bug

This commit is contained in:
fiso64 2024-09-28 14:42:21 +02:00
parent 4886744a67
commit 1828e3ff40
5 changed files with 29 additions and 11 deletions

View file

@ -164,6 +164,9 @@ Usage: sldl <input> [OPTIONS]
--max-samplerate <rate> Maximum file sample rate --max-samplerate <rate> Maximum file sample rate
--min-bitdepth <depth> Minimum bit depth --min-bitdepth <depth> Minimum bit depth
--max-bitdepth <depth> Maximum bit depth --max-bitdepth <depth> 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 <list> Comma-separated list of users to ignore --banned-users <list> Comma-separated list of users to ignore
--pref-format <formats> Preferred file format(s), comma-separated (default: mp3) --pref-format <formats> Preferred file format(s), comma-separated (default: mp3)

View file

@ -14,6 +14,7 @@ public class FileManager
readonly TrackListEntry tle; readonly TrackListEntry tle;
readonly HashSet<Track> organized = new(); readonly HashSet<Track> organized = new();
public string? remoteCommonDir { get; private set; } public string? remoteCommonDir { get; private set; }
public string? defaultFolderName { get; private set; }
public FileManager(TrackListEntry tle) public FileManager(TrackListEntry tle)
{ {
@ -37,9 +38,10 @@ public class FileManager
if (tle.source.Type == TrackType.Album && !string.IsNullOrEmpty(remoteCommonDir)) if (tle.source.Type == TrackType.Album && !string.IsNullOrEmpty(remoteCommonDir))
{ {
string dirname = Path.GetFileName(remoteCommonDir); string dirname = defaultFolderName != null ? defaultFolderName : Path.GetFileName(remoteCommonDir);
string relpath = Path.GetRelativePath(remoteCommonDir, Utils.NormalizedPath(sourceFname)); string normFname = Utils.NormalizedPath(sourceFname);
parent = Path.Join(parent, dirname, Path.GetDirectoryName(relpath)); string relpath = normFname.StartsWith(remoteCommonDir) ? Path.GetRelativePath(remoteCommonDir, normFname) : "";
parent = Path.Join(parent, dirname, Path.GetDirectoryName(relpath) ?? "");
} }
return Path.Join(parent, name); return Path.Join(parent, name);
@ -50,6 +52,11 @@ public class FileManager
this.remoteCommonDir = remoteCommonDir != null ? Utils.NormalizedPath(remoteCommonDir) : null; 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<Track> tracks, List<Track>? additionalImages, bool remainingOnly = true) public void OrganizeAlbum(List<Track> tracks, List<Track>? additionalImages, bool remainingOnly = true)
{ {
foreach (var track in tracks.Where(t => !t.IsNotAudio)) foreach (var track in tracks.Where(t => !t.IsNotAudio))

View file

@ -1,7 +1,7 @@
 
// undocumented options // undocumented options
// --login, --random-login, --no-modify-share-count, --unknown-error-retries // --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 // --fast-search-delay, --fast-search-min-up-speed
// --min-album-track-count, --max-album-track-count, --extract-max-track-count, --extract-min-track-count // --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 <rate> Maximum file sample rate --max-samplerate <rate> Maximum file sample rate
--min-bitdepth <depth> Minimum bit depth --min-bitdepth <depth> Minimum bit depth
--max-bitdepth <depth> Maximum bit depth --max-bitdepth <depth> 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 <list> Comma-separated list of users to ignore --banned-users <list> Comma-separated list of users to ignore
--pref-format <formats> Preferred file format(s), comma-separated (default: mp3) --pref-format <formats> Preferred file format(s), comma-separated (default: mp3)

View file

@ -540,7 +540,7 @@ static partial class Program
if (Config.I.albumArtOnly || succeeded && Config.I.albumArtOption != AlbumArtOption.Default) if (Config.I.albumArtOnly || succeeded && Config.I.albumArtOption != AlbumArtOption.Default)
{ {
Console.WriteLine($"\nDownloading additional images:"); 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); tracks?.AddRange(additionalImages);
} }
@ -616,12 +616,20 @@ static partial class Program
} }
static async Task<List<Track>> DownloadImages(List<List<Track>> downloads, AlbumArtOption option, List<Track>? chosenAlbum, FileManager fileManager) static async Task<List<Track>> DownloadImages(TrackListEntry tle, List<List<Track>> downloads, AlbumArtOption option, List<Track>? chosenAlbum)
{ {
var downloadedImages = new List<Track>(); var downloadedImages = new List<Track>();
long mSize = 0; long mSize = 0;
int mCount = 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) if (option == AlbumArtOption.Default)
return downloadedImages; return downloadedImages;
@ -710,10 +718,7 @@ static partial class Program
PrintAlbum(tracks); 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; bool allSucceeded = true;
var semaphore = new SemaphoreSlim(1); var semaphore = new SemaphoreSlim(1);

View file

@ -27,7 +27,7 @@
<PackageReference Include="SpotifyAPI.Web" Version="7.1.1" /> <PackageReference Include="SpotifyAPI.Web" Version="7.1.1" />
<PackageReference Include="SpotifyAPI.Web.Auth" Version="7.1.1" /> <PackageReference Include="SpotifyAPI.Web.Auth" Version="7.1.1" />
<PackageReference Include="TagLibSharp" Version="2.3.0" /> <PackageReference Include="TagLibSharp" Version="2.3.0" />
<PackageReference Include="YoutubeExplode" Version="6.4.0" /> <PackageReference Include="YoutubeExplode" Version="6.4.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>