diff --git a/zotify/__pycache__/album.cpython-314.pyc b/zotify/__pycache__/album.cpython-314.pyc new file mode 100644 index 0000000..7f46fc7 Binary files /dev/null and b/zotify/__pycache__/album.cpython-314.pyc differ diff --git a/zotify/__pycache__/config.cpython-314.pyc b/zotify/__pycache__/config.cpython-314.pyc new file mode 100644 index 0000000..74770a3 Binary files /dev/null and b/zotify/__pycache__/config.cpython-314.pyc differ diff --git a/zotify/__pycache__/track.cpython-314.pyc b/zotify/__pycache__/track.cpython-314.pyc index 1c297ac..b05e7fa 100644 Binary files a/zotify/__pycache__/track.cpython-314.pyc and b/zotify/__pycache__/track.cpython-314.pyc differ diff --git a/zotify/album.py b/zotify/album.py index 5101dbb..99ddb81 100644 --- a/zotify/album.py +++ b/zotify/album.py @@ -63,12 +63,25 @@ def download_album(album): # inject these values into the template; track-level localized metadata will be used. get_album_name(album) tracks = get_album_tracks(album) + + # Only create Disc folders when the album truly has multiple discs. + disc_numbers = { + (t.get('disc_number') if isinstance(t, dict) else None) or 1 + for t in tracks + } + album_multi_disc = len(disc_numbers) > 1 + for n, track in Printer.progress(enumerate(tracks, start=1), unit_scale=True, unit='Song', total=len(tracks)): # Only pass dynamic numbering and album_id (useful for custom templates using {album_id}). download_track( 'album', track[ID], - extra_keys={'album_num': str(n).zfill(2), 'album_id': album}, + extra_keys={ + 'album_num': str(n).zfill(2), + 'album_id': album, + # Used by download_track() to decide whether to insert a Disc folder. + 'album_multi_disc': '1' if album_multi_disc else '0', + }, disable_progressbar=True ) diff --git a/zotify/config.py b/zotify/config.py index a5f3798..4fcc58e 100644 --- a/zotify/config.py +++ b/zotify/config.py @@ -50,7 +50,7 @@ CONFIG_VALUES = { SONG_ARCHIVE: { 'default': '', 'type': str, 'arg': '--song-archive' }, ROOT_PATH: { 'default': '', 'type': str, 'arg': '--root-path' }, ROOT_PODCAST_PATH: { 'default': '', 'type': str, 'arg': '--root-podcast-path' }, - SPLIT_ALBUM_DISCS: { 'default': 'False', 'type': bool, 'arg': '--split-album-discs' }, + SPLIT_ALBUM_DISCS: { 'default': 'True', 'type': bool, 'arg': '--split-album-discs' }, DOWNLOAD_LYRICS: { 'default': 'False', 'type': bool, 'arg': '--download-lyrics' }, LYRICS_LOCATION: { 'default': '', 'type': str, 'arg': '--lyrics-location' }, LYRICS_FILENAME: { 'default': '{artist}_{song_name}', 'type': str, 'arg': '--lyrics-filename' }, @@ -338,10 +338,6 @@ class Config: else: raise ValueError() - if cls.get_split_album_discs() and mode == 'album': - base = PurePath(v) - return str(base.parent / 'Disc {disc_number}' / base.name) - return v @classmethod diff --git a/zotify/track.py b/zotify/track.py index 1283f50..1e80afc 100644 --- a/zotify/track.py +++ b/zotify/track.py @@ -274,6 +274,24 @@ def download_track(mode: str, track_id: str, extra_keys=None, disable_progressba output_template = output_template.replace("{track_id}", fix_filename(track_id)) output_template = output_template.replace("{ext}", ext) + # SPLIT_ALBUM_DISCS should only create a Disc folder when the album truly has multiple discs. + # - When downloading via zotify.album.download_album(), we pass extra_keys['album_multi_disc']. + # - As a fallback, any track with disc_number > 1 implies multi-disc. + if mode == 'album' and Zotify.CONFIG.get_split_album_discs(): + flag_raw = extra_keys.get('album_multi_disc') + flag = str(flag_raw).strip().lower() in ('1', 'true', 'yes') + try: + disc_number_int = int(disc_number) + except Exception: + disc_number_int = 1 + + should_create_disc_dir = flag or disc_number_int > 1 + if should_create_disc_dir: + tpl_path = PurePath(output_template) + disc_dir_name = f"Disc {disc_number_int}" + if disc_dir_name not in tpl_path.parts: + output_template = str(tpl_path.parent / disc_dir_name / tpl_path.name) + filename = PurePath(Zotify.CONFIG.get_root_path()).joinpath(output_template) filedir = PurePath(filename).parent