From 7a7314ee3f921805fac3d4bc55e59e29d81526a8 Mon Sep 17 00:00:00 2001 From: Zsin Skri Date: Wed, 17 Oct 2018 22:27:02 +0200 Subject: [PATCH] Allow other ReplayGain backends to support R128. Previously using EBU R128 forced the use of the bs1770gain backend. This change adds a whitelist of backends supporting R128. When the configured backend is in that list it will also be used for R128 calculations. Otherwise bs1770gain is still used as a default. This should not change the overall behaviour of the program at all, but allow for further R128-supporting backends to be added. --- beetsplug/replaygain.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/beetsplug/replaygain.py b/beetsplug/replaygain.py index 58a4df83c..084172336 100644 --- a/beetsplug/replaygain.py +++ b/beetsplug/replaygain.py @@ -88,6 +88,10 @@ class Backend(object): # individual tracks which can be used for any backend. raise NotImplementedError() + def use_ebu_r128(self): + """Set this Backend up to use EBU R128.""" + pass + # bsg1770gain backend class Bs1770gainBackend(Backend): @@ -277,6 +281,10 @@ class Bs1770gainBackend(Backend): out.append(album_gain["album"]) return out + def use_ebu_r128(self): + """Set this Backend up to use EBU R128.""" + self.method = '--ebu' + # mpgain/aacgain CLI tool backend. class CommandBackend(Backend): @@ -830,6 +838,8 @@ class ReplayGainPlugin(BeetsPlugin): "bs1770gain": Bs1770gainBackend, } + r128_backend_names = ["bs1770gain"] + def __init__(self): super(ReplayGainPlugin, self).__init__() @@ -1024,7 +1034,9 @@ class ReplayGainPlugin(BeetsPlugin): u"Fatal replay gain error: {0}".format(e)) def init_r128_backend(self): - backend_name = 'bs1770gain' + backend_name = self.config["backend"].as_str() + if backend_name not in self.r128_backend_names: + backend_name = "bs1770gain" try: self.r128_backend_instance = self.backends[backend_name]( @@ -1034,7 +1046,7 @@ class ReplayGainPlugin(BeetsPlugin): raise ui.UserError( u'replaygain initialization failed: {0}'.format(e)) - self.r128_backend_instance.method = '--ebu' + self.r128_backend_instance.use_ebu_r128() def imported(self, session, task): """Add replay gain info to items or albums of ``task``.