diff --git a/beets/autotag/match.py b/beets/autotag/match.py index bc6a506f6..d6566c2dd 100644 --- a/beets/autotag/match.py +++ b/beets/autotag/match.py @@ -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 diff --git a/test/test_autotag.py b/test/test_autotag.py index 0b5ccc535..c8fd3dca2 100644 --- a/test/test_autotag.py +++ b/test/test_autotag.py @@ -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):