From 75f98050b81a3c4775c40516a066b825afebb6fe Mon Sep 17 00:00:00 2001 From: CodeDevMLH <145071728+CodeDevMLH@users.noreply.github.com> Date: Mon, 11 Aug 2025 03:39:32 +0200 Subject: [PATCH] fix #230 --- routes/utils/watch/manager.py | 21 ++++++++++++++++++- .../src/components/config/FormattingTab.tsx | 4 ++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/routes/utils/watch/manager.py b/routes/utils/watch/manager.py index 894a076..6bc8d4c 100644 --- a/routes/utils/watch/manager.py +++ b/routes/utils/watch/manager.py @@ -950,6 +950,10 @@ def generate_track_file_path(track: Dict[str, Any], custom_dir_format: str, cust clean_album = clean_name(album_name) clean_main_artist = clean_name(main_artist) clean_title = clean_name(title) + + # Prepare artist and album artist lists + artist_list = [clean_name(a) for a in re.split(r"\s*,\s*", artist_names or "") if a.strip()] or [clean_main_artist] + album_artist_list = [clean_name(a) for a in re.split(r"\s*,\s*", album_artist_names or "") if a.strip()] or [clean_album_artist] # Prepare placeholder replacements replacements = { @@ -969,7 +973,22 @@ def generate_track_file_path(track: Dict[str, Any], custom_dir_format: str, cust "%explicit%": "", # Not available "%duration%": str(duration_ms // 1000) if duration_ms > 0 else "0", # Convert ms to seconds } - + + artist_indices = {int(i) for i in re.findall(r"%artist_(\d+)%", custom_dir_format + custom_track_format)} + ar_album_indices = {int(i) for i in re.findall(r"%ar_album_(\d+)%", custom_dir_format + custom_track_format)} + + # Replace artist placeholders with actual values + for i in artist_indices: + idx = i - 1 + value = artist_list[idx] if 0 <= idx < len(artist_list) else artist_list[0] + replacements[f"%artist_{i}%"] = value + + # Replace album artist placeholders with actual values + for i in ar_album_indices: + idx = i - 1 + value = album_artist_list[idx] if 0 <= idx < len(album_artist_list) else album_artist_list[0] + replacements[f"%ar_album_{i}%"] = value + # Apply replacements to directory format dir_path = custom_dir_format for placeholder, value in replacements.items(): diff --git a/spotizerr-ui/src/components/config/FormattingTab.tsx b/spotizerr-ui/src/components/config/FormattingTab.tsx index 48f51f9..3cdc070 100644 --- a/spotizerr-ui/src/components/config/FormattingTab.tsx +++ b/spotizerr-ui/src/components/config/FormattingTab.tsx @@ -31,9 +31,9 @@ const saveFormattingConfig = async (data: Partial) => { const placeholders = { Common: { "%music%": "Track title", - "%artist%": "Track artist", + "%artist%": "Track artist (use %arist_1%, %artist_2%, etc. for selecting specific artists)", "%album%": "Album name", - "%ar_album%": "Album artist", + "%ar_album%": "Album artist (use %ar_album_1%, %ar_album_2%, etc. for selecting specific album artists)", "%tracknum%": "Track number", "%year%": "Year of release", },