mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
importer: provides search_ids into lookup_candidates explicitly
This commit is contained in:
parent
5677f9beee
commit
21459c70ee
3 changed files with 19 additions and 23 deletions
|
|
@ -143,9 +143,7 @@ def lookup_candidates(session: ImportSession, task: ImportTask):
|
|||
|
||||
# Restrict the initial lookup to IDs specified by the user via the -m
|
||||
# option. Currently all the IDs are passed onto the tasks directly.
|
||||
task.search_ids = session.config["search_ids"].as_str_seq()
|
||||
|
||||
task.lookup_candidates()
|
||||
task.lookup_candidates(session.config["search_ids"].as_str_seq())
|
||||
|
||||
|
||||
@pipeline.stage
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ from beets.dbcore.query import PathQuery
|
|||
from .state import ImportState
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from beets.autotag.match import Recommendation
|
||||
|
||||
from .session import ImportSession
|
||||
|
||||
# Global logger.
|
||||
|
|
@ -159,6 +161,7 @@ class ImportTask(BaseImportTask):
|
|||
cur_album: str | None = None
|
||||
cur_artist: str | None = None
|
||||
candidates: Sequence[autotag.AlbumMatch | autotag.TrackMatch] = []
|
||||
rec: Recommendation | None = None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
|
@ -167,11 +170,9 @@ class ImportTask(BaseImportTask):
|
|||
items: Iterable[library.Item] | None,
|
||||
):
|
||||
super().__init__(toppath, paths, items)
|
||||
self.rec = None
|
||||
self.should_remove_duplicates = False
|
||||
self.should_merge_duplicates = False
|
||||
self.is_album = True
|
||||
self.search_ids = [] # user-supplied candidate IDs.
|
||||
|
||||
def set_choice(
|
||||
self, choice: Action | autotag.AlbumMatch | autotag.TrackMatch
|
||||
|
|
@ -356,18 +357,15 @@ class ImportTask(BaseImportTask):
|
|||
tasks = [t for inner in tasks for t in inner]
|
||||
return tasks
|
||||
|
||||
def lookup_candidates(self):
|
||||
"""Retrieve and store candidates for this album. User-specified
|
||||
candidate IDs are stored in self.search_ids: if present, the
|
||||
initial lookup is restricted to only those IDs.
|
||||
def lookup_candidates(self, search_ids: list[str]) -> None:
|
||||
"""Retrieve and store candidates for this album.
|
||||
|
||||
If User-specified ``search_ids`` list is not empty, the lookup is
|
||||
restricted to only those IDs.
|
||||
"""
|
||||
artist, album, prop = autotag.tag_album(
|
||||
self.items, search_ids=self.search_ids
|
||||
self.cur_artist, self.cur_album, (self.candidates, self.rec) = (
|
||||
autotag.tag_album(self.items, search_ids=search_ids)
|
||||
)
|
||||
self.cur_artist = artist
|
||||
self.cur_album = album
|
||||
self.candidates = prop.candidates
|
||||
self.rec = prop.recommendation
|
||||
|
||||
def find_duplicates(self, lib: library.Library):
|
||||
"""Return a list of albums from `lib` with the same artist and
|
||||
|
|
@ -695,10 +693,10 @@ class SingletonImportTask(ImportTask):
|
|||
for item in self.imported_items():
|
||||
plugins.send("item_imported", lib=lib, item=item)
|
||||
|
||||
def lookup_candidates(self):
|
||||
prop = autotag.tag_item(self.item, search_ids=self.search_ids)
|
||||
self.candidates = prop.candidates
|
||||
self.rec = prop.recommendation
|
||||
def lookup_candidates(self, search_ids: list[str]) -> None:
|
||||
self.candidates, self.rec = autotag.tag_item(
|
||||
self.item, search_ids=search_ids
|
||||
)
|
||||
|
||||
def find_duplicates(self, lib):
|
||||
"""Return a list of items from `lib` that have the same artist
|
||||
|
|
|
|||
|
|
@ -1627,9 +1627,9 @@ class ImportIdTest(ImportTestCase):
|
|||
task = importer.ImportTask(
|
||||
paths=self.import_dir, toppath="top path", items=[_common.item()]
|
||||
)
|
||||
task.search_ids = [self.ID_RELEASE_0, self.ID_RELEASE_1]
|
||||
|
||||
task.lookup_candidates()
|
||||
task.lookup_candidates([self.ID_RELEASE_0, self.ID_RELEASE_1])
|
||||
|
||||
assert {"VALID_RELEASE_0", "VALID_RELEASE_1"} == {
|
||||
c.info.album for c in task.candidates
|
||||
}
|
||||
|
|
@ -1639,9 +1639,9 @@ class ImportIdTest(ImportTestCase):
|
|||
task = importer.SingletonImportTask(
|
||||
toppath="top path", item=_common.item()
|
||||
)
|
||||
task.search_ids = [self.ID_RECORDING_0, self.ID_RECORDING_1]
|
||||
|
||||
task.lookup_candidates()
|
||||
task.lookup_candidates([self.ID_RECORDING_0, self.ID_RECORDING_1])
|
||||
|
||||
assert {"VALID_RECORDING_0", "VALID_RECORDING_1"} == {
|
||||
c.info.title for c in task.candidates
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue