def list_items(lib, query, album, fmt, config): """Print out items in lib matching query. If album, then search for albums instead of single items. """ tmpl = Template(fmt) if fmt else Template(ui._pick_format(config, album)) if album: for album in lib.albums(query): ui.print_obj(album, lib, config, tmpl) else: for item in lib.items(query): ui.print_obj(item, lib, config, tmpl)
def list_items(lib, query, album, fmt): """Print out items in lib matching query. If album, then search for albums instead of single items. """ tmpl = Template(ui._pick_format(album, fmt)) if album: for album in lib.albums(query): ui.print_obj(album, lib, tmpl) else: for item in lib.items(query): ui.print_obj(item, lib, tmpl)
def singletons(self, lib, query, move, pretend, write, fmt): """Retrieve and apply info from the autotagger for items matched by query. """ template = Template(ui._pick_format(False, fmt)) for item in lib.items(query + ['singleton:true']): item_formatted = item.evaluate_template(template) if not item.mb_trackid: self._log.info(u'Skipping singleton with no mb_trackid: {0}', item_formatted) continue # Get the MusicBrainz recording info. track_info = hooks.track_for_mbid(item.mb_trackid) if not track_info: self._log.info(u'Recording ID not found: {0} for track {0}', item.mb_trackid, item_formatted) continue # Apply. with lib.transaction(): autotag.apply_item_metadata(item, track_info) apply_item_changes(lib, item, move, pretend, write)
import os.path import imghdr import subprocess import platform from tempfile import NamedTemporaryFile from beets.plugins import BeetsPlugin from beets import mediafile from beets import ui from beets.ui import decargs from beets.util import syspath, normpath, displayable_path from beets.util.artresizer import ArtResizer from beets import config from beets.util.functemplate import Template __item_template = Template(ui._pick_format(False)) fmt_item = lambda item: item.evaluate_template(__item_template) __album_template = Template(ui._pick_format(True)) fmt_album = lambda item: item.evaluate_template(__album_template) class EmbedCoverArtPlugin(BeetsPlugin): """Allows albumart to be embedded into the actual files. """ def __init__(self): super(EmbedCoverArtPlugin, self).__init__() self.config.add({ 'maxwidth': 0, 'auto': True, 'compare_threshold': 0, 'ifempty': False,
def albums(self, lib, query, move, pretend, write, fmt): """Retrieve and apply info from the autotagger for albums matched by query and their items. """ template = Template(ui._pick_format(True, fmt)) # Process matching albums. for a in lib.albums(query): album_formatted = a.evaluate_template(template) if not a.mb_albumid: self._log.info(u'Skipping album with no mb_albumid: {0}', album_formatted) continue items = list(a.items()) # Get the MusicBrainz album information. album_info = hooks.album_for_mbid(a.mb_albumid) if not album_info: self._log.info(u'Release ID {0} not found for album {1}', a.mb_albumid, album_formatted) continue # Map recording MBIDs to their information. Recordings can appear # multiple times on a release, so each MBID maps to a list of # TrackInfo objects. track_index = defaultdict(list) for track_info in album_info.tracks: track_index[track_info.track_id].append(track_info) # Construct a track mapping according to MBIDs. This should work # for albums that have missing or extra tracks. If there are # multiple copies of a recording, they are disambiguated using # their disc and track number. mapping = {} for item in items: candidates = track_index[item.mb_trackid] if len(candidates) == 1: mapping[item] = candidates[0] else: for c in candidates: if (c.medium_index == item.track and c.medium == item.disc): mapping[item] = c break # Apply. with lib.transaction(): autotag.apply_metadata(album_info, mapping) changed = False for item in items: item_changed = ui.show_model_changes(item) changed |= item_changed if item_changed: apply_item_changes(lib, item, move, pretend, write) if not changed: # No change to any item. continue if not pretend: # Update album structure to reflect an item in it. for key in library.Album.item_keys: a[key] = items[0][key] a.store() # Move album art (and any inconsistent items). if move and lib.directory in util.ancestry(items[0].path): self._log.debug(u'moving album {0}', album_formatted) a.move()