Implement Disc folders (#679)

* Add disc subdirectories

* Smoother recovery on broken config
This commit is contained in:
Nathan Thomas 2024-05-14 15:18:58 -07:00 committed by GitHub
parent 527b52cae2
commit 22d6a9b137
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 30 additions and 15 deletions

View file

@ -1,4 +1,5 @@
"""A config class that manages arguments between the config file and CLI.""" """A config class that manages arguments between the config file and CLI."""
import copy import copy
import logging import logging
import os import os
@ -15,7 +16,7 @@ logger = logging.getLogger("streamrip")
APP_DIR = click.get_app_dir("streamrip") APP_DIR = click.get_app_dir("streamrip")
os.makedirs(APP_DIR, exist_ok=True) os.makedirs(APP_DIR, exist_ok=True)
DEFAULT_CONFIG_PATH = os.path.join(APP_DIR, "config.toml") 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) @dataclass(slots=True)
@ -181,6 +182,8 @@ class DownloadsConfig:
folder: str folder: str
# Put Qobuz albums in a 'Qobuz' folder, Tidal albums in 'Tidal' etc. # Put Qobuz albums in a 'Qobuz' folder, Tidal albums in 'Tidal' etc.
source_subdirectories: bool 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. # Download (and convert) tracks all at once, instead of sequentially.
# If you are converting the tracks, or have fast internet, this will # If you are converting the tracks, or have fast internet, this will
# substantially improve processing speed. # substantially improve processing speed.

View file

@ -3,7 +3,8 @@
folder = "" folder = ""
# Put Qobuz albums in a 'Qobuz' folder, Tidal albums in 'Tidal' etc. # Put Qobuz albums in a 'Qobuz' folder, Tidal albums in 'Tidal' etc.
source_subdirectories = false 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. # Download (and convert) tracks all at once, instead of sequentially.
# If you are converting the tracks, or have fast internet, this will # If you are converting the tracks, or have fast internet, this will
# substantially improve processing speed. # substantially improve processing speed.
@ -186,6 +187,6 @@ max_search_results = 100
[misc] [misc]
# Metadata to identify this config file. Do not change. # 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 # Print a message if a new version of streamrip is available
check_for_updates = true check_for_updates = true

View file

@ -148,11 +148,18 @@ class PendingTrack(Pending):
quality = self.config.session.get_source(source).quality quality = self.config.session.get_source(source).quality
downloadable = await self.client.get_downloadable(self.id, 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( return Track(
meta, meta,
downloadable, downloadable,
self.config, self.config,
self.folder, folder,
self.cover_path, self.cover_path,
self.db, self.db,
) )

View file

@ -101,7 +101,7 @@ class AlbumMetadata:
if isinstance(_label, dict): if isinstance(_label, dict):
_label = _label["name"] _label = _label["name"]
label = typed(_label or "", str) label = typed(_label or "", str)
description = typed(resp.get("description", "") or None, str) description = typed(resp.get("description", ""), str)
disctotal = typed( disctotal = typed(
max( max(
track.get("media_number", 1) track.get("media_number", 1)

View file

@ -153,6 +153,8 @@ def rip(ctx, config_path, folder, no_db, quality, codec, no_progress, verbose):
@coro @coro
async def url(ctx, urls): async def url(ctx, urls):
"""Download content from URLs.""" """Download content from URLs."""
if ctx.obj["config"] is None:
return
with ctx.obj["config"] as cfg: with ctx.obj["config"] as cfg:
cfg: Config cfg: Config
updates = cfg.session.misc.check_for_updates updates = cfg.session.misc.check_for_updates
@ -237,7 +239,7 @@ def config():
@click.pass_context @click.pass_context
def config_open(ctx, vim): def config_open(ctx, vim):
"""Open the config file in a text editor.""" """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}") console.print(f"Opening file at [bold cyan]{config_path}")
if vim: if vim:

Binary file not shown.

View file

@ -43,6 +43,7 @@ def test_sample_config_data_fields(sample_config_data):
downloads=DownloadsConfig( downloads=DownloadsConfig(
folder="test_folder", folder="test_folder",
source_subdirectories=False, source_subdirectories=False,
disc_subdirectories=True,
concurrency=True, concurrency=True,
max_connections=6, max_connections=6,
requests_per_minute=60, requests_per_minute=60,

View file

@ -3,6 +3,7 @@
folder = "test_folder" folder = "test_folder"
# Put Qobuz albums in a 'Qobuz' folder, Tidal albums in 'Tidal' etc. # Put Qobuz albums in a 'Qobuz' folder, Tidal albums in 'Tidal' etc.
source_subdirectories = false source_subdirectories = false
disc_subdirectories = true
# Download (and convert) tracks all at once, instead of sequentially. # Download (and convert) tracks all at once, instead of sequentially.
# If you are converting the tracks, or have fast internet, this will # If you are converting the tracks, or have fast internet, this will
@ -185,5 +186,5 @@ max_search_results = 100
[misc] [misc]
# Metadata to identify this config file. Do not change. # Metadata to identify this config file. Do not change.
version = "2.0.3" version = "2.0.6"
check_for_updates = true check_for_updates = true

View file

@ -19,7 +19,7 @@ def test_album_metadata_qobuz():
assert info.explicit == False assert info.explicit == False
assert info.sampling_rate == 96 assert info.sampling_rate == 96
assert info.bit_depth == 24 assert info.bit_depth == 24
assert info.booklets == None assert info.booklets is None
assert m.album == "Rumours" assert m.album == "Rumours"
assert m.albumartist == "Fleetwood Mac" assert m.albumartist == "Fleetwood Mac"
@ -29,19 +29,19 @@ def test_album_metadata_qobuz():
assert not m.covers.empty() assert not m.covers.empty()
assert m.albumcomposer == "Various Composers" assert m.albumcomposer == "Various Composers"
assert m.comment == None assert m.comment is None
assert m.compilation == None assert m.compilation is None
assert ( assert (
m.copyright m.copyright
== "© 1977 Warner Records Inc. ℗ 1977 Warner Records Inc. Marketed by Rhino Entertainment Company, A Warner Music Group Company." == "© 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.date == "1977-02-04"
assert m.description == None assert m.description == ""
assert m.disctotal == 1 assert m.disctotal == 1
assert m.encoder == None assert m.encoder is None
assert m.grouping == None assert m.grouping is None
assert m.lyrics == None assert m.lyrics is None
assert m.purchase_date == None assert m.purchase_date is None
assert m.tracktotal == 11 assert m.tracktotal == 11