@@ -103,28 +103,21 @@ def assign_items(
103103 return list (mapping .items ()), extra_items , extra_tracks
104104
105105
106- def match_by_id (items : Iterable [Item ]) -> Iterable [AlbumInfo ]:
107- """If the items are tagged with an external source ID, return an
108- AlbumInfo object for the corresponding album. Otherwise, returns
109- None.
110- """
111- albumids = (item .mb_albumid for item in items if item .mb_albumid )
106+ def match_by_id (album_id : str | None , consensus : bool ) -> Iterable [AlbumInfo ]:
107+ """Return album candidates for the given album id.
112108
113- # Did any of the items have an MB album ID?
114- try :
115- first = next ( albumids )
116- except StopIteration :
109+ Make sure that the ID is present and that there is consensus on it among
110+ the items being tagged.
111+ """
112+ if not album_id :
117113 log .debug ("No album ID found." )
118- return ()
114+ elif not consensus :
115+ log .debug ("No album ID consensus." )
116+ else :
117+ log .debug ("Searching for discovered album ID: {}" , album_id )
118+ return metadata_plugins .albums_for_ids (album_id )
119119
120- # Is there a consensus on the MB album ID?
121- for other in albumids :
122- if other != first :
123- log .debug ("No album ID consensus." )
124- return ()
125- # If all album IDs are equal, look up the album.
126- log .debug ("Searching for discovered album ID: {}" , first )
127- return metadata_plugins .albums_for_ids (first )
120+ return ()
128121
129122
130123def _recommendation (
@@ -287,7 +280,9 @@ def tag_album(
287280 # Use existing metadata or text search.
288281 else :
289282 # Try search based on current ID.
290- for info in match_by_id (items ):
283+ for info in match_by_id (
284+ likelies ["mb_albumid" ], consensus ["mb_albumid" ]
285+ ):
291286 _add_candidate (items , candidates , info )
292287 for candidate in candidates .values ():
293288 plugins .send ("album_matched" , match = candidate )
0 commit comments