From 1f6335581e6871513d1a1a7285df6856d8e4e635 Mon Sep 17 00:00:00 2001 From: Yann Leprince Date: Sun, 31 Dec 2017 12:00:02 +0100 Subject: [PATCH 1/4] Add --force, --write and --nowrite options to replaygain plugin --- beetsplug/replaygain.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/beetsplug/replaygain.py b/beetsplug/replaygain.py index a70f9384b..18fd8db78 100644 --- a/beetsplug/replaygain.py +++ b/beetsplug/replaygain.py @@ -893,7 +893,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. @@ -901,7 +901,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 @@ -944,14 +944,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 @@ -1007,17 +1007,29 @@ 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", dest="write", + action="store_true", + help=u"write new metadata to files' tags (default)") + 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] From 499cd378b7a2e7fc76821096e633e1731e9c5dbc Mon Sep 17 00:00:00 2001 From: Yann Leprince Date: Tue, 2 Jan 2018 12:11:47 +0100 Subject: [PATCH 2/4] fix the default write behaviour to the importer configuration --- beetsplug/replaygain.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/beetsplug/replaygain.py b/beetsplug/replaygain.py index 18fd8db78..19ca8572e 100644 --- a/beetsplug/replaygain.py +++ b/beetsplug/replaygain.py @@ -1025,9 +1025,8 @@ class ReplayGainPlugin(BeetsPlugin): help=u"analyze all files, including those that " "already have ReplayGain metadata") cmd.parser.add_option( - "-w", "--write", dest="write", - action="store_true", - help=u"write new metadata to files' tags (default)") + "-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)") From 1b247dffff8e549d9d2b544fac687fd9b9dadcb2 Mon Sep 17 00:00:00 2001 From: Yann Leprince Date: Tue, 2 Jan 2018 12:34:34 +0100 Subject: [PATCH 3/4] Document new options to the replaygain sub-command --- docs/plugins/replaygain.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/plugins/replaygain.rst b/docs/plugins/replaygain.rst index 838a2ea2b..44246ed50 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:: From e2b920610ff3d55fa9d642335149146d89e4f579 Mon Sep 17 00:00:00 2001 From: Yann Leprince Date: Tue, 2 Jan 2018 14:34:56 +0100 Subject: [PATCH 4/4] Add ChangeLog entry --- docs/changelog.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 4ff54b222..90988785d 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`