mirror of
https://github.com/beetbox/beets.git
synced 2026-01-05 07:23:33 +01:00
Search for multiple album/track ids
This commit is contained in:
parent
f1204aa81f
commit
9eb14a142b
3 changed files with 23 additions and 30 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue