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: