Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions scripts/filter_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import csv
import logging
import sys
import unicodedata
from pathlib import Path

logging.basicConfig(
Expand All @@ -34,8 +35,13 @@


def normalize_artist(name: str) -> str:
"""Normalize artist name for matching."""
return name.lower().strip()
"""Normalize artist name for matching.

Strips diacritics so that Discogs "Björk" matches library "Bjork".
"""
nfkd = unicodedata.normalize("NFKD", name)
stripped = "".join(c for c in nfkd if not unicodedata.combining(c))
return stripped.lower().strip()


def load_library_artists(path: Path) -> set[str]:
Expand Down
20 changes: 19 additions & 1 deletion tests/unit/test_filter_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,26 @@ class TestNormalizeArtist:
("RADIOHEAD", "radiohead"),
(" Mixed Case ", "mixed case"),
("", ""),
("Björk", "bjork"),
("Sigur Rós", "sigur ros"),
("Motörhead", "motorhead"),
("Hüsker Dü", "husker du"),
("Café Tacvba", "cafe tacvba"),
("Zoé", "zoe"),
],
ids=[
"lowercase",
"strip-spaces",
"all-caps",
"mixed-case-strip",
"empty",
"bjork",
"sigur-ros",
"motorhead",
"husker-du",
"cafe-tacvba",
"zoe",
],
ids=["lowercase", "strip-spaces", "all-caps", "mixed-case-strip", "empty"],
)
def test_normalize(self, raw: str, expected: str) -> None:
assert normalize_artist(raw) == expected
Expand Down