mirror of
https://github.com/beetbox/beets.git
synced 2026-01-03 14:32:55 +01:00
commit
5f9b28124d
3 changed files with 39 additions and 16 deletions
|
|
@ -14,6 +14,7 @@
|
|||
# included in all copies or substantial portions of the Software.
|
||||
|
||||
from __future__ import division, absolute_import, print_function
|
||||
|
||||
import six
|
||||
|
||||
"""Gets genres for imported music based on Last.fm tags.
|
||||
|
|
@ -380,28 +381,46 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
|||
u'-s', u'--source', dest='source', type='string',
|
||||
help=u'genre source: artist, album, or track'
|
||||
)
|
||||
lastgenre_cmd.parser.add_option(
|
||||
u'-A', u'--items', action='store_false', dest='album',
|
||||
help=u'match items instead of albums')
|
||||
lastgenre_cmd.parser.add_option(
|
||||
u'-a', u'--albums', action='store_true', dest='album',
|
||||
help=u'match albums instead of items')
|
||||
lastgenre_cmd.parser.set_defaults(album=True)
|
||||
|
||||
def lastgenre_func(lib, opts, args):
|
||||
write = ui.should_write()
|
||||
self.config.set_args(opts)
|
||||
|
||||
for album in lib.albums(ui.decargs(args)):
|
||||
album.genre, src = self._get_genre(album)
|
||||
self._log.info(u'genre for album {0} ({1}): {0.genre}',
|
||||
album, src)
|
||||
album.store()
|
||||
if opts.album:
|
||||
# Fetch genres for whole albums
|
||||
for album in lib.albums(ui.decargs(args)):
|
||||
album.genre, src = self._get_genre(album)
|
||||
self._log.info(u'genre for album {0} ({1}): {0.genre}',
|
||||
album, src)
|
||||
album.store()
|
||||
|
||||
for item in album.items():
|
||||
# If we're using track-level sources, also look up each
|
||||
# track on the album.
|
||||
if 'track' in self.sources:
|
||||
item.genre, src = self._get_genre(item)
|
||||
item.store()
|
||||
self._log.info(u'genre for track {0} ({1}): {0.genre}',
|
||||
item, src)
|
||||
for item in album.items():
|
||||
# If we're using track-level sources, also look up each
|
||||
# track on the album.
|
||||
if 'track' in self.sources:
|
||||
item.genre, src = self._get_genre(item)
|
||||
item.store()
|
||||
self._log.info(
|
||||
u'genre for track {0} ({1}): {0.genre}',
|
||||
item, src)
|
||||
|
||||
if write:
|
||||
item.try_write()
|
||||
if write:
|
||||
item.try_write()
|
||||
else:
|
||||
# Just query singletons, i.e. items that are not part of
|
||||
# an album
|
||||
for item in lib.items(ui.decargs(args)):
|
||||
item.genre, src = self._get_genre(item)
|
||||
self._log.debug(u'added last.fm item genre ({0}): {1}',
|
||||
src, item.genre)
|
||||
item.store()
|
||||
|
||||
lastgenre_cmd.func = lastgenre_func
|
||||
return [lastgenre_cmd]
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ Changelog
|
|||
|
||||
New features:
|
||||
|
||||
* :doc:`/plugins/lastgenre`: Added option ``-A`` to match individual tracks and singletons.
|
||||
* The disambiguation string for identifying albums in the importer now shows
|
||||
the catalog number.
|
||||
Thanks to :user:`8h2a`.
|
||||
|
|
|
|||
|
|
@ -155,7 +155,10 @@ Running Manually
|
|||
|
||||
In addition to running automatically on import, the plugin can also be run manually
|
||||
from the command line. Use the command ``beet lastgenre [QUERY]`` to fetch
|
||||
genres for albums matching a certain query.
|
||||
genres for albums or items matching a certain query.
|
||||
|
||||
By default, ``beet lastgenre`` matches albums. If you would like to match
|
||||
individual tracks or singletons, use the ``-A`` switch: ``beet lastgenre -A [QUERY]``.
|
||||
|
||||
To disable automatic genre fetching on import, set the ``auto`` config option
|
||||
to false.
|
||||
|
|
|
|||
Loading…
Reference in a new issue