From 22d6a9b137c578265654d6444fa144b8ffe2e11a Mon Sep 17 00:00:00 2001 From: Nathan Thomas Date: Tue, 14 May 2024 15:18:58 -0700 Subject: [PATCH] Implement Disc folders (#679) * Add disc subdirectories * Smoother recovery on broken config --- streamrip/config.py | 5 ++++- streamrip/config.toml | 5 +++-- streamrip/media/track.py | 9 ++++++++- streamrip/metadata/album.py | 2 +- streamrip/rip/cli.py | 4 +++- tests/silence.flac | Bin 29238 -> 33300 bytes tests/test_config.py | 1 + tests/test_config.toml | 3 ++- tests/test_meta.py | 16 ++++++++-------- 9 files changed, 30 insertions(+), 15 deletions(-) diff --git a/streamrip/config.py b/streamrip/config.py index 1ed3ce2..d8ee2cb 100644 --- a/streamrip/config.py +++ b/streamrip/config.py @@ -1,4 +1,5 @@ """A config class that manages arguments between the config file and CLI.""" + import copy import logging import os @@ -15,7 +16,7 @@ logger = logging.getLogger("streamrip") APP_DIR = click.get_app_dir("streamrip") os.makedirs(APP_DIR, exist_ok=True) DEFAULT_CONFIG_PATH = os.path.join(APP_DIR, "config.toml") -CURRENT_CONFIG_VERSION = "2.0.3" +CURRENT_CONFIG_VERSION = "2.0.6" @dataclass(slots=True) @@ -181,6 +182,8 @@ class DownloadsConfig: folder: str # Put Qobuz albums in a 'Qobuz' folder, Tidal albums in 'Tidal' etc. source_subdirectories: bool + # Put tracks in an album with 2 or more discs into a subfolder named `Disc N` + disc_subdirectories: bool # Download (and convert) tracks all at once, instead of sequentially. # If you are converting the tracks, or have fast internet, this will # substantially improve processing speed. diff --git a/streamrip/config.toml b/streamrip/config.toml index b420d0d..6bc2eef 100644 --- a/streamrip/config.toml +++ b/streamrip/config.toml @@ -3,7 +3,8 @@ folder = "" # Put Qobuz albums in a 'Qobuz' folder, Tidal albums in 'Tidal' etc. source_subdirectories = false - +# Put tracks in an album with 2 or more discs into a subfolder named `Disc N` +disc_subdirectories = true # Download (and convert) tracks all at once, instead of sequentially. # If you are converting the tracks, or have fast internet, this will # substantially improve processing speed. @@ -186,6 +187,6 @@ max_search_results = 100 [misc] # Metadata to identify this config file. Do not change. -version = "2.0.3" +version = "2.0.6" # Print a message if a new version of streamrip is available check_for_updates = true diff --git a/streamrip/media/track.py b/streamrip/media/track.py index 32ba531..695ad9b 100644 --- a/streamrip/media/track.py +++ b/streamrip/media/track.py @@ -148,11 +148,18 @@ class PendingTrack(Pending): quality = self.config.session.get_source(source).quality downloadable = await self.client.get_downloadable(self.id, quality) + + downloads_config = self.config.session.downloads + if downloads_config.disc_subdirectories and self.album.disctotal > 1: + folder = os.path.join(self.folder, f"Disc {meta.discnumber}") + else: + folder = self.folder + return Track( meta, downloadable, self.config, - self.folder, + folder, self.cover_path, self.db, ) diff --git a/streamrip/metadata/album.py b/streamrip/metadata/album.py index dcac729..aa0fb95 100644 --- a/streamrip/metadata/album.py +++ b/streamrip/metadata/album.py @@ -101,7 +101,7 @@ class AlbumMetadata: if isinstance(_label, dict): _label = _label["name"] label = typed(_label or "", str) - description = typed(resp.get("description", "") or None, str) + description = typed(resp.get("description", ""), str) disctotal = typed( max( track.get("media_number", 1) diff --git a/streamrip/rip/cli.py b/streamrip/rip/cli.py index cde7c09..0e0e517 100644 --- a/streamrip/rip/cli.py +++ b/streamrip/rip/cli.py @@ -153,6 +153,8 @@ def rip(ctx, config_path, folder, no_db, quality, codec, no_progress, verbose): @coro async def url(ctx, urls): """Download content from URLs.""" + if ctx.obj["config"] is None: + return with ctx.obj["config"] as cfg: cfg: Config updates = cfg.session.misc.check_for_updates @@ -237,7 +239,7 @@ def config(): @click.pass_context def config_open(ctx, vim): """Open the config file in a text editor.""" - config_path = ctx.obj["config"].path + config_path = ctx.obj["config_path"] console.print(f"Opening file at [bold cyan]{config_path}") if vim: diff --git a/tests/silence.flac b/tests/silence.flac index 302cef910cb7fa83a3f48ea74359cd7584360228..164e81a0a3777c9036c15249dfc3b58fa057019d 100644 GIT binary patch delta 17 Zcmdn?gmFp>(}IxA8#M3nZwfJ!0{}`n2Ymnl delta 13 UcmbQz!nExP