diff --git a/beetsplug/replaygain.py b/beetsplug/replaygain.py index 7e1ca4bd7..a7064451a 100644 --- a/beetsplug/replaygain.py +++ b/beetsplug/replaygain.py @@ -920,7 +920,7 @@ class ReplayGainPlugin(BeetsPlugin): self._log.debug(u'applied album gain {0}', album.r128_album_gain) - def handle_album(self, album, write): + def handle_album(self, album, write, force=False): """Compute album and track replay gain store it in all of the album's items. @@ -928,7 +928,7 @@ class ReplayGainPlugin(BeetsPlugin): item. If replay gain information is already present in all items, nothing is done. """ - if not self.album_requires_gain(album): + if not force and not self.album_requires_gain(album): self._log.info(u'Skipping album {0}', album) return @@ -971,14 +971,14 @@ class ReplayGainPlugin(BeetsPlugin): raise ui.UserError( u"Fatal replay gain error: {0}".format(e)) - def handle_track(self, item, write): + def handle_track(self, item, write, force=False): """Compute track replay gain and store it in the item. If ``write`` is truthy then ``item.write()`` is called to write the data to disk. If replay gain information is already present in the item, nothing is done. """ - if not self.track_requires_gain(item): + if not force and not self.track_requires_gain(item): self._log.info(u'Skipping track {0}', item) return @@ -1034,17 +1034,28 @@ class ReplayGainPlugin(BeetsPlugin): """Return the "replaygain" ui subcommand. """ def func(lib, opts, args): - write = ui.should_write() + write = ui.should_write(opts.write) + force = opts.force if opts.album: for album in lib.albums(ui.decargs(args)): - self.handle_album(album, write) + self.handle_album(album, write, force) else: for item in lib.items(ui.decargs(args)): - self.handle_track(item, write) + self.handle_track(item, write, force) cmd = ui.Subcommand('replaygain', help=u'analyze for ReplayGain') cmd.parser.add_album_option() + cmd.parser.add_option( + "-f", "--force", dest="force", action="store_true", default=False, + help=u"analyze all files, including those that " + "already have ReplayGain metadata") + cmd.parser.add_option( + "-w", "--write", default=None, action="store_true", + help=u"write new metadata to files' tags") + cmd.parser.add_option( + "-W", "--nowrite", dest="write", action="store_false", + help=u"don't write metadata (opposite of -w)") cmd.func = func return [cmd] diff --git a/docs/changelog.rst b/docs/changelog.rst index c7e2d0ff6..b507b67e7 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -6,6 +6,12 @@ Changelog Changelog goes here! +New features: + +* :doc:`/plugins/replaygain`: add ``--force``, ``--write`` and ``--nowrite`` + options to ``beet replaygain``. :bug:`2778` + + Fixes: * Non-audio media (DVD-Video, etc.) are now skipped by the autotagger. :bug:`2688` diff --git a/docs/plugins/replaygain.rst b/docs/plugins/replaygain.rst index 07b585d27..7f520c334 100644 --- a/docs/plugins/replaygain.rst +++ b/docs/plugins/replaygain.rst @@ -140,11 +140,15 @@ By default, the plugin will analyze all items an albums as they are implemented. However, you can also manually analyze files that are already in your library. Use the ``beet replaygain`` command:: - $ beet replaygain [-a] [QUERY] + $ beet replaygain [-Waf] [QUERY] The ``-a`` flag analyzes whole albums instead of individual tracks. Provide a query (see :doc:`/reference/query`) to indicate which items or albums to -analyze. +analyze. Files that already have ReplayGain values are skipped unless ``-f`` is +supplied. Use ``-w`` (write tags) or ``-W`` (don't write tags) to control +whether ReplayGain tags are written into the music files, or stored in the +beets database only (the default is to use :ref:`the importer's configuration +`). ReplayGain analysis is not fast, so you may want to disable it during import. Use the ``auto`` config option to control this::