From 34d4e5afab148bc281fbe4128616d33017a3b6ea Mon Sep 17 00:00:00 2001 From: ziadarafat Date: Thu, 26 Nov 2026 14:13:01 -0700 Subject: [PATCH] music-audit: parse numbering, years and bare disc folders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three folder-naming shapes broke artist/title detection, and each one turned into a pile of silent 'no candidates': '02. 1958- The Songs That Made Him Famous' the year was stripped but its dangling dash stayed, so the string split into artist '02.' — leading index prefixes are now dropped and the year takes its dash with it 'Stockholm 67/Disc 1' the folder said only 'Disc 1', so the album name is one level up and the artist two: resolve-albums now climbs out of bare disc folders '03. 1959- The Fabolous Johnny Cash' spelling as shipped; still no candidate, and correctly left alone rather than force-matched Johnny Cash went from 72/72 no-candidates to finding real releases (Hymns by Johnny Cash 12/12, Now There Was a Song 12/12, ...). --- tools/music-audit/mb-pick.py | 3 ++- tools/music-audit/resolve-albums.py | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/tools/music-audit/mb-pick.py b/tools/music-audit/mb-pick.py index 226697a..9f5d413 100755 --- a/tools/music-audit/mb-pick.py +++ b/tools/music-audit/mb-pick.py @@ -62,7 +62,8 @@ def parse_folder(name: str, artist_hint: str | None = None) -> tuple[str, str, i disc = int(m.group(1)) s = re.sub(r"\[(Disc\s*\d+|EAC[^\]]*|FLAC|MP3[^\]]*|\d{4}[^\]]*)\]", " ", name, flags=re.I) s = re.sub(r"\((oan|anniv[^)]*|[^)]*)\)", " ", s, flags=re.I) - s = re.sub(r"\b(19|20)\d{2}\b", " ", s) + s = re.sub(r"^\s*\d{1,3}\s*[.)\]]?\s*[-–]?\s*", "", s) # "02. ", "13 - " index prefixes + s = re.sub(r"\b(19|20)\d{2}\s*[-–]?\s*", " ", s) # year, optionally with a dangling dash s = re.sub(r"\b(EAC|FLAC|MP3|320|320Kbps|V0|V2)\b", " ", s, flags=re.I) s = re.sub(r"\(\s*\d{3}\s*[LK]?\s*\)", " ", s) # "(320 L)", "(320)" quality suffixes s = re.sub(r"^\s*(19|20)\d{2}\s+", "", s) # leading release year diff --git a/tools/music-audit/resolve-albums.py b/tools/music-audit/resolve-albums.py index 96e6d2b..15f416d 100755 --- a/tools/music-audit/resolve-albums.py +++ b/tools/music-audit/resolve-albums.py @@ -108,6 +108,27 @@ def parent_artist(d: str) -> str: return re.sub(r"\s+", " ", parent).strip(" -") +DISC_ONLY = re.compile(r"^(disc|cd|disk)\s*\d+$", re.I) + + +def album_identity(folder: str, hint: str) -> tuple[str, str, int | None]: + """(artist, title, disc) for a folder, climbing out of bare "Disc N" folders. + + Compilations keep each disc in its own directory, so the folder itself says + only "Disc 1" — the album name is one level up and the artist two. + """ + artist, title, disc = mbpick.parse_folder(os.path.basename(folder), artist_hint=hint) + climbs = 0 + while (not title or DISC_ONLY.match(title)) and climbs < 2: + folder = os.path.dirname(os.path.abspath(folder)) + climbs += 1 + a2, title, d2 = mbpick.parse_folder(os.path.basename(folder), artist_hint=hint) + disc = disc or d2 + if a2 and a2 != hint: + artist = a2 + return artist, title, disc + + def album_dirs(root: str) -> list[str]: out = [] for dirpath, dirnames, filenames in os.walk(root): @@ -146,7 +167,7 @@ def main() -> int: if args.limit and done >= args.limit: break hint = tag_albumartist(folder) or parent_artist(folder) - artist, title, disc = mbpick.parse_folder(os.path.basename(folder), artist_hint=hint) + artist, title, disc = album_identity(folder, hint) disc = disc or disc_tag print("\n%s (%d files, %d tagged, disc=%s)" % (os.path.basename(folder)[:70], n, have, disc), flush=True) try: