From 95d6cb749379d7c7deba32783fd22a7650f8325b Mon Sep 17 00:00:00 2001 From: fiso64 Date: Fri, 30 Aug 2024 22:01:10 +0200 Subject: [PATCH] commit --- README.md | 18 ++++++++++++++++-- changelog.md | 8 -------- slsk-batchdl/Config.cs | 4 ++++ slsk-batchdl/Data.cs | 2 +- slsk-batchdl/Extractors/Csv.cs | 17 ++++++++++++----- slsk-batchdl/Extractors/Spotify.cs | 11 +++++++++-- slsk-batchdl/Help.cs | 1 + slsk-batchdl/Program.cs | 17 +++++++++++------ 8 files changed, 54 insertions(+), 24 deletions(-) delete mode 100644 changelog.md diff --git a/README.md b/README.md index bd13b69..63c4502 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ Usage: sldl [OPTIONS] 'index' (default): Write a line indexing all downloaded files, required for skip-not-found or skip-existing=m3u 'all': Write the index and a list of paths and fails + --m3u-path Override default m3u path -s, --skip-existing Skip if a track matching file conditions is found in the output folder or your music library (if provided) @@ -558,7 +559,7 @@ sldl "title=MC MENTAL @ HIS BEST,length=242" --pref-format "flac,wav" Interactive album download: ``` -sldl "album=Some Album" --interactive +sldl "Some Album" --album --interactive ```
@@ -568,10 +569,23 @@ sldl "artist=MC MENTAL" --aggregate --skip-existing --music-dir "path/to/music" ```
-Download all albums by an artist that are on soulseek: +Download all albums by an artist found on soulseek: ``` sldl "artist=MC MENTAL" --aggregate --album ``` +
+ +#### Advanced example: Automatic wishlist downloader +Create a file named wishlist.txt, and add your wishlist items: +```bash +echo title=My Favorite Song, artist=Artist >> wishlist.txt +echo https://spotify/album/url >> wishlist.txt +``` +Set up a cron job (or scheduled task on windows) to periodically run sldl on every line of the wishlist file with the following options: +``` +--skip-existing --skip-mode m3u --m3u index --m3u-path wishlist-archive.sldl +``` +You can also use m3u-cond and specify some preferred conditions to e.g only stop searching for an item once a lossless version is downloaded. ## Notes - For macOS builds you can use publish.sh to build the app. Download dotnet from https://dotnet.microsoft.com/en-us/download/dotnet/6.0, then run `chmod +x publish.sh && sh publish.sh`. For intel macs, uncomment the x64 and comment the arm64 section in publish.sh. diff --git a/changelog.md b/changelog.md deleted file mode 100644 index 4cfd1b2..0000000 --- a/changelog.md +++ /dev/null @@ -1,8 +0,0 @@ -- configuration profiles, auto-profiles -- album aggregate download mode -- automatically browse user shares during album downloads to guarantee that all files from the parent folder are downloaded -- skip-existing is now much faster. Default mode is now m3u as it is more reliable. Changed how m3u skip-existing works (not backward compatible). Added `m3u-cond` skip mode. m3u modes can now skip album downloads. -- can now download entire bandcamp artist discographies -- added `--on-complete` to run a command whenever a file is downloaded -- now also looks in the user config directories for `sldl.conf` -- many bug fixes \ No newline at end of file diff --git a/slsk-batchdl/Config.cs b/slsk-batchdl/Config.cs index 7a2c0b4..8df14df 100644 --- a/slsk-batchdl/Config.cs +++ b/slsk-batchdl/Config.cs @@ -846,6 +846,10 @@ static class Config _ => throw new ArgumentException($"Invalid m3u option '{args[i]}'"), }; break; + case "--m3up": + case "--m3u-path": + m3uFilePath = args[++i]; + break; case "--lp": case "--port": case "--listen-port": diff --git a/slsk-batchdl/Data.cs b/slsk-batchdl/Data.cs index a3568fd..94fe1f7 100644 --- a/slsk-batchdl/Data.cs +++ b/slsk-batchdl/Data.cs @@ -47,7 +47,7 @@ namespace Data Other = other.Other; MinAlbumTrackCount = other.MinAlbumTrackCount; MaxAlbumTrackCount = other.MaxAlbumTrackCount; - CsvRow = other.CsvRow; + //CsvRow = other.CsvRow; } public string ToKey() diff --git a/slsk-batchdl/Extractors/Csv.cs b/slsk-batchdl/Extractors/Csv.cs index d7a308b..6da52a0 100644 --- a/slsk-batchdl/Extractors/Csv.cs +++ b/slsk-batchdl/Extractors/Csv.cs @@ -47,12 +47,19 @@ namespace Extractors { if (File.Exists(Config.input)) { - string[] lines = File.ReadAllLines(Config.input, System.Text.Encoding.UTF8); - - if (lines.Length > track.CsvRow) + try { - lines[track.CsvRow] = new string(',', Math.Max(0, csvColumnCount - 1)); - Utils.WriteAllLines(Config.input, lines, '\n'); + string[] lines = File.ReadAllLines(Config.input, System.Text.Encoding.UTF8); + + if (track.CsvRow > -1 && track.CsvRow < lines.Length) + { + lines[track.CsvRow] = new string(',', Math.Max(0, csvColumnCount - 1)); + Utils.WriteAllLines(Config.input, lines, '\n'); + } + } + catch (Exception e) + { + Printing.WriteLine($"Error removing from source: {e}", debugOnly: true); } } } diff --git a/slsk-batchdl/Extractors/Spotify.cs b/slsk-batchdl/Extractors/Spotify.cs index baeb4da..ef207c2 100644 --- a/slsk-batchdl/Extractors/Spotify.cs +++ b/slsk-batchdl/Extractors/Spotify.cs @@ -106,8 +106,15 @@ namespace Extractors public async Task RemoveTrackFromSource(Track track) { - if (playlistUri.Length > 0 && track.URI.Length > 0) - await spotifyClient.RemoveTrackFromPlaylist(playlistUri, track.URI); + try + { + if (playlistUri.Length > 0 && track.URI.Length > 0) + await spotifyClient.RemoveTrackFromPlaylist(playlistUri, track.URI); + } + catch (Exception e) + { + Printing.WriteLine($"Error removing from source: {e}", debugOnly: true); + } } } diff --git a/slsk-batchdl/Help.cs b/slsk-batchdl/Help.cs index c7ea2d5..ec06cc9 100644 --- a/slsk-batchdl/Help.cs +++ b/slsk-batchdl/Help.cs @@ -34,6 +34,7 @@ public static class Help 'index' (default): Write a line indexing all downloaded files, required for skip-not-found or skip-existing=m3u 'all': Write the index and a list of paths and fails + --m3u-path Override default m3u path -s, --skip-existing Skip if a track matching file conditions is found in the output folder or your music library (if provided) diff --git a/slsk-batchdl/Program.cs b/slsk-batchdl/Program.cs index e320dbe..df5168a 100644 --- a/slsk-batchdl/Program.cs +++ b/slsk-batchdl/Program.cs @@ -416,7 +416,7 @@ static partial class Program var downloadTasks = tracks.Select(async (track, index) => { - await DownloadTask(tle, track, semaphore, organizer, null, false); + await DownloadTask(tle, track, semaphore, organizer, null, false, true); m3uEditor.Update(); }); @@ -469,7 +469,7 @@ static partial class Program { var downloadTasks = tracks.Select(async track => { - await DownloadTask(tle, track, semaphore, organizer, cts, cancelOnFail: !Config.albumIgnoreFails); + await DownloadTask(tle, track, semaphore, organizer, cts, cancelOnFail: !Config.albumIgnoreFails, true); }); await Task.WhenAll(downloadTasks); @@ -491,7 +491,7 @@ static partial class Program tle.list.RemoveAt(index); } - if (tracks != null) + if (tracks != null && succeeded) { var downloadedAudio = tracks.Where(t => !t.IsNotAudio && t.State == TrackState.Downloaded && t.DownloadPath.Length > 0); @@ -499,6 +499,11 @@ static partial class Program { tle.source.State = TrackState.Downloaded; tle.source.DownloadPath = Utils.GreatestCommonDirectory(downloadedAudio.Select(t => t.DownloadPath)); + + if (Config.removeTracksFromSource) + { + await extractor.RemoveTrackFromSource(tle.source); + } } } @@ -620,7 +625,7 @@ static partial class Program foreach (var track in tracks) { - await DownloadTask(null, track, semaphore, organizer, null, false); + await DownloadTask(null, track, semaphore, organizer, null, false, false); if (track.State == TrackState.Downloaded) downloadedImages.Add(track); @@ -636,7 +641,7 @@ static partial class Program } - static async Task DownloadTask(TrackListEntry? tle, Track track, SemaphoreSlim semaphore, FileManager organizer, CancellationTokenSource? cts, bool cancelOnFail) + static async Task DownloadTask(TrackListEntry? tle, Track track, SemaphoreSlim semaphore, FileManager organizer, CancellationTokenSource? cts, bool cancelOnFail, bool removeFromSource) { if (track.State != TrackState.Initial) return; @@ -706,7 +711,7 @@ static partial class Program track.DownloadPath = savedFilePath; } - if (Config.removeTracksFromSource) + if (removeFromSource && Config.removeTracksFromSource) { try {