From f93ee3accc6673674cfc98d2a1e09afb119d3eea Mon Sep 17 00:00:00 2001 From: Susanna Maria Hepp Date: Mon, 26 Dec 2016 23:47:10 +0100 Subject: [PATCH 1/7] First hack of ignoring already tagged items --- beetsplug/acousticbrainz.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/beetsplug/acousticbrainz.py b/beetsplug/acousticbrainz.py index 138fd88099..9985ade874 100644 --- a/beetsplug/acousticbrainz.py +++ b/beetsplug/acousticbrainz.py @@ -155,6 +155,12 @@ def _fetch_info(self, items, write): """Fetch additional information from AcousticBrainz for the `item`s. """ for item in items: + + mood_str = item.get('mood_acoustic', u'') + if len(mood_str) != 0: + self._log.info(u'Already set acousticbrainz tag for {} ', item) + continue + if not item.mb_trackid: continue From bbaad2f17dedf3394065f9bea3eb30fc85df2fae Mon Sep 17 00:00:00 2001 From: Susanna Maria Hepp Date: Tue, 27 Dec 2016 13:22:16 +0100 Subject: [PATCH 2/7] Introduce force option in acousticbrainz --- beetsplug/acousticbrainz.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/beetsplug/acousticbrainz.py b/beetsplug/acousticbrainz.py index 9985ade874..9f52329535 100644 --- a/beetsplug/acousticbrainz.py +++ b/beetsplug/acousticbrainz.py @@ -107,7 +107,8 @@ class AcousticPlugin(plugins.BeetsPlugin): def __init__(self): super(AcousticPlugin, self).__init__() - self.config.add({'auto': True}) + self.config.add({'auto': True,'force': False}) + if self.config['auto']: self.register_listener('import_task_files', self.import_task_files) @@ -118,7 +119,13 @@ def commands(self): def func(lib, opts, args): items = lib.items(ui.decargs(args)) - self._fetch_info(items, ui.should_write()) + self._fetch_info(items, ui.should_write(),opts.force_refetch or self.config['force']) + + cmd.parser.add_option( + u'-f', u'--force', dest='force_refetch', + action='store_true', default=False, + help=u'always fetch acousticbrainz data', + ) cmd.func = func return [cmd] @@ -151,15 +158,16 @@ def _get_data(self, mbid): return data - def _fetch_info(self, items, write): + def _fetch_info(self, items, write, force): """Fetch additional information from AcousticBrainz for the `item`s. """ for item in items: - mood_str = item.get('mood_acoustic', u'') - if len(mood_str) != 0: - self._log.info(u'Already set acousticbrainz tag for {} ', item) - continue + if not force: + mood_str = item.get('mood_acoustic', u'') + if len(mood_str) != 0: + self._log.info(u'Already set acousticbrainz tag for {} ', item) + continue if not item.mb_trackid: continue From c632949b648b90b044aa58089a43bfd39f3d6170 Mon Sep 17 00:00:00 2001 From: Susanna Maria Hepp Date: Tue, 27 Dec 2016 21:48:06 +0100 Subject: [PATCH 3/7] Changes suggested by @Kraymer --- beetsplug/acousticbrainz.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/beetsplug/acousticbrainz.py b/beetsplug/acousticbrainz.py index 9f52329535..09078402f0 100644 --- a/beetsplug/acousticbrainz.py +++ b/beetsplug/acousticbrainz.py @@ -119,7 +119,7 @@ def commands(self): def func(lib, opts, args): items = lib.items(ui.decargs(args)) - self._fetch_info(items, ui.should_write(),opts.force_refetch or self.config['force']) + self._fetch_info(items, ui.should_write(), opts.force_refetch or self.config['force']) cmd.parser.add_option( u'-f', u'--force', dest='force_refetch', @@ -165,8 +165,8 @@ def _fetch_info(self, items, write, force): if not force: mood_str = item.get('mood_acoustic', u'') - if len(mood_str) != 0: - self._log.info(u'Already set acousticbrainz tag for {} ', item) + if mood_str: + self._log.info(u'Already set acousticbrainz tags for {} ', item) continue if not item.mb_trackid: From 00371de0bb739cd2f632e57525cbff0db6ea5008 Mon Sep 17 00:00:00 2001 From: Susanna Maria Hepp Date: Tue, 27 Dec 2016 21:56:39 +0100 Subject: [PATCH 4/7] Changes suggested by @sampsyo --- beetsplug/acousticbrainz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/acousticbrainz.py b/beetsplug/acousticbrainz.py index 09078402f0..5fc60634dc 100644 --- a/beetsplug/acousticbrainz.py +++ b/beetsplug/acousticbrainz.py @@ -124,7 +124,7 @@ def func(lib, opts, args): cmd.parser.add_option( u'-f', u'--force', dest='force_refetch', action='store_true', default=False, - help=u'always fetch acousticbrainz data', + help=u're-download data when already present' ) cmd.func = func From 8be0a271b599aa0151f0074d36fb904982735b12 Mon Sep 17 00:00:00 2001 From: Susanna Maria Hepp Date: Tue, 27 Dec 2016 22:11:27 +0100 Subject: [PATCH 5/7] Add documentation for the force-option --- docs/plugins/acousticbrainz.rst | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/docs/plugins/acousticbrainz.rst b/docs/plugins/acousticbrainz.rst index b66bf17def..5d72b8517a 100644 --- a/docs/plugins/acousticbrainz.rst +++ b/docs/plugins/acousticbrainz.rst @@ -8,7 +8,12 @@ The ``acousticbrainz`` plugin gets acoustic-analysis information from the Enable the ``acousticbrainz`` plugin in your configuration (see :ref:`using-plugins`) and run it by typing:: - $ beet acousticbrainz [QUERY] + $ beet acousticbrainz [-f] [QUERY] + +By default, the command will only look for acousticbrainz data when the tracks doesn't +already have it; the ``-f`` or ``--force`` switch makes it fetch acousticbrainz +for the item. If you specify a query, only matching tracks will be processed; +otherwise, the command processes every track in your library. For all tracks with a MusicBrainz recording ID, the plugin currently sets these fields: @@ -52,3 +57,6 @@ configuration file. There is one option: - **auto**: Enable AcousticBrainz during ``beet import``. Default: ``yes``. +- **force**: By default, beets will not override already fetched acousticbrainz data. To instead fetch acousticbrainz and override data, + set the ``force`` option to ``yes``. + Default: ``no``. \ No newline at end of file From 165f2e189ea93c4391b48df710af6ae812e850d4 Mon Sep 17 00:00:00 2001 From: Susanna Maria Hepp Date: Wed, 28 Dec 2016 15:11:03 +0100 Subject: [PATCH 6/7] Repair findings from Travis CI --- beetsplug/acousticbrainz.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/beetsplug/acousticbrainz.py b/beetsplug/acousticbrainz.py index 5fc60634dc..3dea02fd2e 100644 --- a/beetsplug/acousticbrainz.py +++ b/beetsplug/acousticbrainz.py @@ -107,7 +107,7 @@ class AcousticPlugin(plugins.BeetsPlugin): def __init__(self): super(AcousticPlugin, self).__init__() - self.config.add({'auto': True,'force': False}) + self.config.add({'auto': True, 'force': False}) if self.config['auto']: self.register_listener('import_task_files', @@ -119,8 +119,8 @@ def commands(self): def func(lib, opts, args): items = lib.items(ui.decargs(args)) - self._fetch_info(items, ui.should_write(), opts.force_refetch or self.config['force']) - + self._fetch_info(items, ui.should_write(), + opts.force_refetch or self.config['force']) cmd.parser.add_option( u'-f', u'--force', dest='force_refetch', action='store_true', default=False, @@ -162,11 +162,11 @@ def _fetch_info(self, items, write, force): """Fetch additional information from AcousticBrainz for the `item`s. """ for item in items: - if not force: mood_str = item.get('mood_acoustic', u'') if mood_str: - self._log.info(u'Already set acousticbrainz tags for {} ', item) + self._log.info(u'Already set acoustic\ + brainz tags for {} ', item) continue if not item.mb_trackid: From 7e1e31bdddea3d30c3a61c0514298bfb1fdbbe6c Mon Sep 17 00:00:00 2001 From: Susanna Maria Hepp Date: Wed, 28 Dec 2016 15:30:57 +0100 Subject: [PATCH 7/7] E128: continuation line under-indented for visual indent? --- beetsplug/acousticbrainz.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beetsplug/acousticbrainz.py b/beetsplug/acousticbrainz.py index 3dea02fd2e..725c55089d 100644 --- a/beetsplug/acousticbrainz.py +++ b/beetsplug/acousticbrainz.py @@ -119,8 +119,8 @@ def commands(self): def func(lib, opts, args): items = lib.items(ui.decargs(args)) - self._fetch_info(items, ui.should_write(), - opts.force_refetch or self.config['force']) + self._fetch_info(items, ui.should_write(), + opts.force_refetch or self.config['force']) cmd.parser.add_option( u'-f', u'--force', dest='force_refetch', action='store_true', default=False,