mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 16:42:42 +01:00
Add --pretend option to lastgenre plugin for previewing genre changes
This commit is contained in:
parent
dc4e4e5020
commit
a57ef2cb3b
3 changed files with 38 additions and 13 deletions
|
|
@ -461,6 +461,12 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
||||||
|
|
||||||
def commands(self):
|
def commands(self):
|
||||||
lastgenre_cmd = ui.Subcommand("lastgenre", help="fetch genres")
|
lastgenre_cmd = ui.Subcommand("lastgenre", help="fetch genres")
|
||||||
|
lastgenre_cmd.parser.add_option(
|
||||||
|
"-p",
|
||||||
|
"--pretend",
|
||||||
|
action="store_true",
|
||||||
|
help="show actions but do nothing",
|
||||||
|
)
|
||||||
lastgenre_cmd.parser.add_option(
|
lastgenre_cmd.parser.add_option(
|
||||||
"-f",
|
"-f",
|
||||||
"--force",
|
"--force",
|
||||||
|
|
@ -521,45 +527,57 @@ class LastGenrePlugin(plugins.BeetsPlugin):
|
||||||
|
|
||||||
def lastgenre_func(lib, opts, args):
|
def lastgenre_func(lib, opts, args):
|
||||||
write = ui.should_write()
|
write = ui.should_write()
|
||||||
|
pretend = getattr(opts, "pretend", False)
|
||||||
self.config.set_args(opts)
|
self.config.set_args(opts)
|
||||||
|
|
||||||
if opts.album:
|
if opts.album:
|
||||||
# Fetch genres for whole albums
|
# Fetch genres for whole albums
|
||||||
for album in lib.albums(args):
|
for album in lib.albums(args):
|
||||||
album.genre, src = self._get_genre(album)
|
album_genre, src = self._get_genre(album)
|
||||||
self._log.info(
|
self._log.info(
|
||||||
'genre for album "{0.album}" ({1}): {0.genre}',
|
'genre for album "{0.album}" ({1}): {}',
|
||||||
album,
|
album,
|
||||||
src,
|
src,
|
||||||
|
album_genre,
|
||||||
)
|
)
|
||||||
if "track" in self.sources:
|
if not pretend:
|
||||||
album.store(inherit=False)
|
album.genre = album_genre
|
||||||
else:
|
if "track" in self.sources:
|
||||||
album.store()
|
album.store(inherit=False)
|
||||||
|
else:
|
||||||
|
album.store()
|
||||||
|
|
||||||
for item in album.items():
|
for item in album.items():
|
||||||
# If we're using track-level sources, also look up each
|
# If we're using track-level sources, also look up each
|
||||||
# track on the album.
|
# track on the album.
|
||||||
if "track" in self.sources:
|
if "track" in self.sources:
|
||||||
item.genre, src = self._get_genre(item)
|
item_genre, src = self._get_genre(item)
|
||||||
item.store()
|
|
||||||
self._log.info(
|
self._log.info(
|
||||||
'genre for track "{0.title}" ({1}): {0.genre}',
|
'genre for track "{0.title}" ({1}): {}',
|
||||||
item,
|
item,
|
||||||
src,
|
src,
|
||||||
|
item_genre,
|
||||||
)
|
)
|
||||||
|
if not pretend:
|
||||||
|
item.genre = item_genre
|
||||||
|
item.store()
|
||||||
|
|
||||||
if write:
|
if write and not pretend:
|
||||||
item.try_write()
|
item.try_write()
|
||||||
else:
|
else:
|
||||||
# Just query singletons, i.e. items that are not part of
|
# Just query singletons, i.e. items that are not part of
|
||||||
# an album
|
# an album
|
||||||
for item in lib.items(args):
|
for item in lib.items(args):
|
||||||
item.genre, src = self._get_genre(item)
|
item_genre, src = self._get_genre(item)
|
||||||
item.store()
|
|
||||||
self._log.info(
|
self._log.info(
|
||||||
"genre for track {0.title} ({1}): {0.genre}", item, src
|
'genre for track "{0.title}" ({1}): {}',
|
||||||
|
item,
|
||||||
|
src,
|
||||||
|
item_genre,
|
||||||
)
|
)
|
||||||
|
if not pretend:
|
||||||
|
item.genre = item_genre
|
||||||
|
item.store()
|
||||||
|
|
||||||
lastgenre_cmd.func = lastgenre_func
|
lastgenre_cmd.func = lastgenre_func
|
||||||
return [lastgenre_cmd]
|
return [lastgenre_cmd]
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,9 @@ Unreleased
|
||||||
|
|
||||||
New features:
|
New features:
|
||||||
|
|
||||||
|
- :doc:`plugins/lastgenre`: Add a ``--pretend`` option to preview genre changes
|
||||||
|
without storing or writing them.
|
||||||
|
|
||||||
Bug fixes:
|
Bug fixes:
|
||||||
|
|
||||||
- :doc:`plugins/spotify` Fixed an issue where track matching and lookups could
|
- :doc:`plugins/spotify` Fixed an issue where track matching and lookups could
|
||||||
|
|
|
||||||
|
|
@ -213,5 +213,9 @@ fetch genres for albums or items matching a certain query.
|
||||||
By default, ``beet lastgenre`` matches albums. To match individual tracks or
|
By default, ``beet lastgenre`` matches albums. To match individual tracks or
|
||||||
singletons, use the ``-A`` switch: ``beet lastgenre -A [QUERY]``.
|
singletons, use the ``-A`` switch: ``beet lastgenre -A [QUERY]``.
|
||||||
|
|
||||||
|
To preview changes without modifying your library, use the ``-p``
|
||||||
|
(``--pretend``) flag. This shows which genres would be set but does not write
|
||||||
|
or store any changes.
|
||||||
|
|
||||||
To disable automatic genre fetching on import, set the ``auto`` config option to
|
To disable automatic genre fetching on import, set the ``auto`` config option to
|
||||||
false.
|
false.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue