Skip to content

Commit 89d7c5d

Browse files
author
Thomas Scholtes
committed
Extend the documentation of the ImportTask
1 parent c3f9b08 commit 89d7c5d

File tree

2 files changed

+46
-12
lines changed

2 files changed

+46
-12
lines changed

beets/autotag/match.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,20 @@ def _add_candidate(items, results, info):
368368

369369
def tag_album(items, search_artist=None, search_album=None,
370370
search_id=None):
371-
"""Bundles together the functionality used to infer tags for a
372-
set of items comprised by an album. Returns everything relevant:
373-
- The current artist.
374-
- The current album.
375-
- A list of AlbumMatch objects. The candidates are sorted by
376-
distance (i.e., best match first).
377-
- A :class:`Recommendation`.
378-
If search_artist and search_album or search_id are provided, then
379-
they are used as search terms in place of the current metadata.
371+
"""Return a tuple of a artist name, an album name, a list of
372+
`AlbumMatch` candidates from the metadata backend, and a
373+
`Recommendation`.
374+
375+
The artist and album are the most common values of these fields
376+
among `items`.
377+
378+
The `AlbumMatch` objects are generated by searching the metadata
379+
backends. By default, the metadata of the items is used for the
380+
search. This can be customized by setting the parameters. The
381+
`mapping` field of the album has the matched `items` as keys.
382+
383+
The recommendation is calculated from the match qualitiy of the
384+
candidates.
380385
"""
381386
# Get current metadata.
382387
likelies, consensus = current_metadata(items)

beets/importer.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,30 @@ def ask_resume(self, toppath):
352352
class ImportTask(object):
353353
"""Represents a single set of items to be imported along with its
354354
intermediate state. May represent an album or a single item.
355+
356+
The import session and stages call the following methods in the
357+
given order.
358+
359+
* `lookup_candidates()` Sets the `common_artist`, `common_album`,
360+
`candidates`, and `rec` attributes. `candidates` is a list of
361+
`AlbumMatch` objects.
362+
363+
* `choose_match()` Uses the session to set the `match` attribute
364+
from the `candidates` list.
365+
366+
* `find_duplicates()` Returns a list of albums from `lib` with the
367+
same artist and album name as the task.
368+
369+
* `apply_metadata()` Sets the attributes of the items from the
370+
task's `match` attribute.
371+
372+
* `add()` Add the imported items and album to the database.
373+
374+
* `manipulate_files()` Copy, move, and write files depending on the
375+
session configuration.
376+
377+
* `finalize()` Update the import progress and cleanup the file
378+
system.
355379
"""
356380
def __init__(self, toppath=None, paths=None, items=None):
357381
self.toppath = toppath
@@ -423,12 +447,15 @@ def chosen_ident(self):
423447

424448
def imported_items(self):
425449
"""Return a list of Items that should be added to the library.
426-
If this is an album task, return the list of items in the
427-
selected match or everything if the choice is ASIS. If this is a
428-
singleton task, return a list containing the item.
450+
451+
If the tasks applies an album match the method only returns the
452+
matched items.
429453
"""
430454
if self.choice_flag == action.ASIS:
431455
return list(self.items)
456+
# FIXME this should be a simple attribute. There should be no
457+
# need to retrieve the keys of `match.mapping`. This requires
458+
# that we remove unmatched items from the list.
432459
elif self.choice_flag == action.APPLY:
433460
return self.match.mapping.keys()
434461
else:
@@ -437,6 +464,8 @@ def imported_items(self):
437464
def apply_metadata(self):
438465
"""Copy metadata from match info to the items.
439466
"""
467+
# TODO call should be more descriptive like
468+
# apply_metadata(self.match, self.items)
440469
autotag.apply_metadata(self.match.info, self.match.mapping)
441470

442471
def duplicate_items(self, lib):

0 commit comments

Comments
 (0)