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 302cef9..164e81a 100644 Binary files a/tests/silence.flac and b/tests/silence.flac differ diff --git a/tests/test_config.py b/tests/test_config.py index 2d154c7..c8a9da2 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -43,6 +43,7 @@ def test_sample_config_data_fields(sample_config_data): downloads=DownloadsConfig( folder="test_folder", source_subdirectories=False, + disc_subdirectories=True, concurrency=True, max_connections=6, requests_per_minute=60, diff --git a/tests/test_config.toml b/tests/test_config.toml index 91e17df..ff7f160 100644 --- a/tests/test_config.toml +++ b/tests/test_config.toml @@ -3,6 +3,7 @@ folder = "test_folder" # Put Qobuz albums in a 'Qobuz' folder, Tidal albums in 'Tidal' etc. source_subdirectories = false +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 @@ -185,5 +186,5 @@ max_search_results = 100 [misc] # Metadata to identify this config file. Do not change. -version = "2.0.3" +version = "2.0.6" check_for_updates = true diff --git a/tests/test_meta.py b/tests/test_meta.py index ca5e426..4516f54 100644 --- a/tests/test_meta.py +++ b/tests/test_meta.py @@ -19,7 +19,7 @@ def test_album_metadata_qobuz(): assert info.explicit == False assert info.sampling_rate == 96 assert info.bit_depth == 24 - assert info.booklets == None + assert info.booklets is None assert m.album == "Rumours" assert m.albumartist == "Fleetwood Mac" @@ -29,19 +29,19 @@ def test_album_metadata_qobuz(): assert not m.covers.empty() assert m.albumcomposer == "Various Composers" - assert m.comment == None - assert m.compilation == None + assert m.comment is None + assert m.compilation is None assert ( m.copyright == "© 1977 Warner Records Inc. ℗ 1977 Warner Records Inc. Marketed by Rhino Entertainment Company, A Warner Music Group Company." ) assert m.date == "1977-02-04" - assert m.description == None + assert m.description == "" assert m.disctotal == 1 - assert m.encoder == None - assert m.grouping == None - assert m.lyrics == None - assert m.purchase_date == None + assert m.encoder is None + assert m.grouping is None + assert m.lyrics is None + assert m.purchase_date is None assert m.tracktotal == 11