diff --git a/beets/autotag/match.py b/beets/autotag/match.py index 65ffc1da9..8453d2c9d 100644 --- a/beets/autotag/match.py +++ b/beets/autotag/match.py @@ -115,7 +115,7 @@ def match_by_id(album_id: str | None, consensus: bool) -> Iterable[AlbumInfo]: log.debug("No album ID consensus.") else: log.debug("Searching for discovered album ID: {}", album_id) - return metadata_plugins.albums_for_ids(album_id) + return metadata_plugins.albums_for_ids([album_id]) return () @@ -203,7 +203,7 @@ def _add_candidate( return # Prevent duplicates. - if info.album_id and info.identifier in results: + if info.identifier in results: log.debug("Duplicate.") return @@ -268,10 +268,9 @@ def tag_album( # Search by explicit ID. if search_ids: - for search_id in search_ids: - log.debug("Searching for album ID: {}", search_id) - for _info in metadata_plugins.albums_for_ids(search_id): - _add_candidate(items, candidates, _info) + log.debug("Searching for album IDs: {}", search_ids) + for _info in metadata_plugins.albums_for_ids(search_ids): + _add_candidate(items, candidates, _info) # Use existing metadata or text search. else: @@ -343,17 +342,16 @@ def tag_item( # First, try matching by the external source ID. trackids = search_ids or [t for t in [item.mb_trackid] if t] if trackids: - for trackid in trackids: - log.debug("Searching for track ID: {}", trackid) - for info in metadata_plugins.tracks_for_ids(trackid): - dist = track_distance(item, info, incl_artist=True) - candidates[info.identifier] = hooks.TrackMatch(dist, info) + log.debug("Searching for track IDs: {}", trackids) + for info in metadata_plugins.tracks_for_ids(trackids): + dist = track_distance(item, info, incl_artist=True) + candidates[info.identifier] = hooks.TrackMatch(dist, info) - # If this is a good match, then don't keep searching. - rec = _recommendation(_sort_candidates(candidates.values())) - if rec == Recommendation.strong and not config["import"]["timid"]: - log.debug("Track ID match.") - return Proposal(_sort_candidates(candidates.values()), rec) + # If this is a good match, then don't keep searching. + rec = _recommendation(_sort_candidates(candidates.values())) + if rec == Recommendation.strong and not config["import"]["timid"]: + log.debug("Track ID match.") + return Proposal(_sort_candidates(candidates.values()), rec) # If we're searching by ID, don't proceed. if search_ids: diff --git a/beets/metadata_plugins.py b/beets/metadata_plugins.py index cf794d120..34f460735 100644 --- a/beets/metadata_plugins.py +++ b/beets/metadata_plugins.py @@ -49,17 +49,17 @@ def item_candidates(*args, **kwargs) -> Iterable[TrackInfo]: @notify_info_yielded("albuminfo_received") -def albums_for_ids(_id: str) -> Iterable[AlbumInfo]: +def albums_for_ids(ids: Sequence[str]) -> Iterable[AlbumInfo]: """Return matching albums from all metadata sources for the given ID.""" for plugin in find_metadata_source_plugins(): - yield from plugin.albums_for_ids([_id]) + yield from plugin.albums_for_ids(ids) @notify_info_yielded("trackinfo_received") -def tracks_for_ids(_id: str) -> Iterable[TrackInfo]: +def tracks_for_ids(ids: Sequence[str]) -> Iterable[TrackInfo]: """Return matching tracks from all metadata sources for the given ID.""" for plugin in find_metadata_source_plugins(): - yield from plugin.tracks_for_ids([_id]) + yield from plugin.tracks_for_ids(ids) @cache diff --git a/test/autotag/test_match.py b/test/autotag/test_match.py index 6538c35d4..995495222 100644 --- a/test/autotag/test_match.py +++ b/test/autotag/test_match.py @@ -1,5 +1,3 @@ -from typing import ClassVar - import pytest from beets import metadata_plugins @@ -107,10 +105,7 @@ class TestTagMultipleDataSources: @pytest.fixture(autouse=True) def _setup_plugins(self, monkeypatch, shared_album_id, shared_track_id): - class StubPlugin: - data_source: ClassVar[str] - data_source_mismatch_penalty = 0 - + class StubPlugin(metadata_plugins.MetadataSourcePlugin): @property def track(self): return TrackInfo( @@ -130,11 +125,11 @@ class TestTagMultipleDataSources: data_source=self.data_source, ) - def albums_for_ids(self, *_): - yield self.album + def album_for_id(self, album_id): + return self.album if album_id == shared_album_id else None - def tracks_for_ids(self, *_): - yield self.track + def track_for_id(self, track_id): + return self.track if track_id == shared_track_id else None def candidates(self, *_, **__): yield self.album