mirror of
https://github.com/beetbox/beets.git
synced 2026-03-01 18:55:50 +01:00
autotag: Fill the blanks when ordering incomplete album
In the function order_items, instead of automatically reject the canonical candidate if it has more tracks, the function still tries to find matches for the tracks amongst the items, and otherwise uses None to fill the void in order to keep the information about the track numbers
This commit is contained in:
parent
4dc4025b5f
commit
bb964a7c47
2 changed files with 17 additions and 3 deletions
|
|
@ -174,8 +174,9 @@ def order_items(items, trackinfo):
|
|||
information. This always produces a result if the numbers of tracks
|
||||
match.
|
||||
"""
|
||||
# Make sure lengths match.
|
||||
if len(items) != len(trackinfo):
|
||||
# Make sure lengths match: If there is less items, it might just be that
|
||||
# there is some tracks missing.
|
||||
if len(items) > len(trackinfo):
|
||||
return None
|
||||
|
||||
# Construct the cost matrix.
|
||||
|
|
@ -190,7 +191,7 @@ def order_items(items, trackinfo):
|
|||
matching = Munkres().compute(costs)
|
||||
|
||||
# Order items based on the matching.
|
||||
ordered_items = [None]*len(items)
|
||||
ordered_items = [None]*len(trackinfo)
|
||||
for cur_idx, canon_idx in matching:
|
||||
ordered_items[canon_idx] = items[cur_idx]
|
||||
return ordered_items
|
||||
|
|
|
|||
|
|
@ -251,11 +251,24 @@ class OrderingTest(unittest.TestCase):
|
|||
items = []
|
||||
items.append(self.item('one', 1))
|
||||
items.append(self.item('two', 2))
|
||||
items.append(self.item('three', 3))
|
||||
items.append(self.item('four',4))
|
||||
trackinfo = []
|
||||
trackinfo.append(TrackInfo('one', None))
|
||||
ordered = match.order_items(items, trackinfo)
|
||||
self.assertEqual(ordered, None)
|
||||
|
||||
def test_order_works_with_missing_tracks(self)
|
||||
items = []
|
||||
items.append(self.item('one', 1))
|
||||
items.append(self.item('two', 2))
|
||||
trackinfo = []
|
||||
trackinfo.append(TrackInfo('one', None))
|
||||
ordered = match.order_items(items, trackinfo)
|
||||
self.assertEqual(ordered[0].title, 'one')
|
||||
self.assertEqual(ordered[1].title, 'two')
|
||||
self.assertEqual(ordered[2], None)
|
||||
|
||||
def test_order_corrects_when_track_names_are_entirely_wrong(self):
|
||||
# A real-world test case contributed by a user.
|
||||
def item(i, length):
|
||||
|
|
|
|||
Loading…
Reference in a new issue