48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
#1/usr/bin/env python3
|
||
|
||
import sys
|
||
import re
|
||
import unicodedata
|
||
from collections import defaultdict
|
||
|
||
def norm(s: str) -> str:
|
||
s = unicodedata.normalize("NFKC", s)
|
||
s = s.replace("’", "'").replace("‘", "'").replace("`", "'").replace("´", "'")
|
||
s = s.replace("‐", "-").replace("-", "-").replace("‒", "-").replace("–", "-").replace("—", "-")
|
||
s = s.replace("“", '"').replace("”", '"')
|
||
s = re.sub(r"\s+", " ", s).strip()
|
||
return s.casefold()
|
||
|
||
groups = defaultdict(list)
|
||
|
||
for line in sys.stdin:
|
||
line = line.rstrip("\n")
|
||
if not line:
|
||
continue
|
||
|
||
parts = line.split("\t")
|
||
if len(parts) != 9:
|
||
print(f"BAD LINE: {line!r}", file=sys.stderr)
|
||
continue
|
||
|
||
album_id, albumartist, album, year, albumtype, albumtotal, mb_albumid, mb_releasegroupid, path = parts
|
||
key = (norm(albumartist), norm(album))
|
||
groups[key].append(parts)
|
||
|
||
for key, rows in sorted(groups.items()):
|
||
if len(rows) <= 1:
|
||
continue
|
||
|
||
print("=" * 100)
|
||
print(f"NORMALIZED DUPLICATE: {key[0]} / {key[1]}")
|
||
for row in rows:
|
||
album_id, albumartist, album, year, albumtype, albumtotal, mb_albumid, mb_releasegroupid, path = row
|
||
print(f"id={album_id}")
|
||
print(f" albumartist: {albumartist}")
|
||
print(f" album: {album}")
|
||
print(f" year/type: {year} / {albumtype}")
|
||
print(f" tracks: {albumtotal}")
|
||
print(f" mb_albumid: {mb_albumid}")
|
||
print(f" rgid: {mb_releasegroupid}")
|
||
print(f" path: {path}")
|