Skip to content

Commit

Permalink
WIP: Consider disambiguation in an album name when calculation distance
Browse files Browse the repository at this point in the history
When calculating distance between the local album name and one from a database
consider the option that the disambiguation text has been included in the
local album's name.
  • Loading branch information
kitizz committed Feb 13, 2025
1 parent 810af1f commit db7a1f5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
12 changes: 11 additions & 1 deletion beets/autotag/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,17 @@ def distance(
dist.add_string("artist", likelies["artist"], album_info.artist)

# Album.
dist.add_string("album", likelies["album"], album_info.album)
compare_album = album_info.album
if album_info.albumdisambig:
# See if "$album ($albumdisambig)" is a closer match, and use that if so.
album_with_disambig = f"{compare_album} ({album_info.albumdisambig})"
album_dist = hooks.string_dist(likelies["album"], compare_album)
album_disambig_dist = hooks.string_dist(
likelies["album"], album_with_disambig
)
if album_disambig_dist < album_dist:
compare_album = album_with_disambig
dist.add_string("album", likelies["album"], compare_album)

# Current or preferred media.
if album_info.media:
Expand Down
22 changes: 20 additions & 2 deletions test/test_autotag.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ def test_current_metadata_likelies(self):
assert likelies[f] == f"{f}_1"


def _make_item(title, track, artist="some artist"):
def _make_item(title, track, artist="some artist", album="some_album"):
return Item(
title=title,
track=track,
artist=artist,
album="some album",
album=album,
length=1,
mb_trackid="",
mb_albumid="",
Expand Down Expand Up @@ -497,6 +497,24 @@ def test_per_medium_track_numbers(self):
dist = self._dist(items, info)
assert dist == 0

def test_album_disambiguation(self):
album = "some album"
disambig = "disambig"
album_disambig = f"{album} ({disambig})"
items = []
items.append(_make_item("one", 1, album=album_disambig))
items.append(_make_item("two", 2, album=album_disambig))
items.append(_make_item("three", 3, album=album_disambig))
info = AlbumInfo(
artist="some artist",
album=album,
albumdisambig=disambig,
tracks=_make_trackinfo(),
va=False,
)

assert self._dist(items, info) == 0


class TestAssignment(ConfigMixin):
A = "one"
Expand Down

0 comments on commit db7a1f5

Please sign in to comment.