Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Ignore diacritic characters when matching on name #449

Merged
Merged
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
21 changes: 6 additions & 15 deletions music_assistant/helpers/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def compare_strings(str1: str, str2: str, strict: bool = True) -> bool:
"""Compare strings and return True if we have an (almost) perfect match."""
if str1 is None or str2 is None:
return False
# return early if total length mismatch
if abs(len(str1) - len(str2)) > 2:
return False
if not strict:
return create_safe_string(str1) == create_safe_string(str2)
return create_sort_name(str1) == create_sort_name(str2)
Expand Down Expand Up @@ -83,11 +86,7 @@ def compare_artist(
return left_artist.musicbrainz_id == right_artist.musicbrainz_id

# fallback to comparing
if not left_artist.sort_name:
left_artist.sort_name = create_sort_name(left_artist.name)
if not right_artist.sort_name:
right_artist.sort_name = create_sort_name(right_artist.name)
return left_artist.sort_name == right_artist.sort_name
return compare_strings(left_artist.name, right_artist.name, False)


def compare_artists(
Expand Down Expand Up @@ -180,11 +179,7 @@ def compare_album(
return left_album.musicbrainz_id == right_album.musicbrainz_id

# fallback to comparing
if not left_album.sort_name:
left_album.sort_name = create_sort_name(left_album.name)
if not right_album.sort_name:
right_album.sort_name = create_sort_name(right_album.name)
if left_album.sort_name != right_album.sort_name:
if not compare_strings(left_album.name, right_album.name, False):
return False
if not compare_version(left_album.version, right_album.version):
return False
Expand Down Expand Up @@ -216,11 +211,7 @@ def compare_track(left_track: Track, right_track: Track):
if left_track.album is None or right_track.album is None:
return False
# track name must match
if not left_track.sort_name:
left_track.sort_name = create_sort_name(left_track.name)
if not right_track.sort_name:
right_track.sort_name = create_sort_name(right_track.name)
if left_track.sort_name != right_track.sort_name:
if not compare_strings(left_track.name, right_track.name, False):
return False
# exact albumtrack match = 100% match
if (
Expand Down