From 1643eea3f569db0b4a4d28e361b80367b2628daa Mon Sep 17 00:00:00 2001 From: Susanna Maria Date: Sun, 23 Jun 2019 13:04:17 +0200 Subject: [PATCH 1/9] Parameter handling --- beetsplug/absubmit.py | 27 ++++++++++++++++++++++++++- docs/plugins/absubmit.rst | 12 ++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/beetsplug/absubmit.py b/beetsplug/absubmit.py index d9525e1d2..e1e327283 100644 --- a/beetsplug/absubmit.py +++ b/beetsplug/absubmit.py @@ -55,7 +55,11 @@ class AcousticBrainzSubmitPlugin(plugins.BeetsPlugin): def __init__(self): super(AcousticBrainzSubmitPlugin, self).__init__() - self.config.add({'extractor': u''}) + self.config.add({ + 'extractor': u'', + 'force': False, + 'dry': False + }) self.extractor = self.config['extractor'].as_str() if self.extractor: @@ -98,12 +102,23 @@ class AcousticBrainzSubmitPlugin(plugins.BeetsPlugin): 'absubmit', help=u'calculate and submit AcousticBrainz analysis' ) + cmd.parser.add_option( + u'-f', u'--force', dest='force_refetch', + action='store_true', default=False, + help=u're-download data when already present' + ) + cmd.parser.add_option( + u'-d', u'--dry', dest='dry_fetch', + action='store_true', default=False, + help=u'dry run, show files which would be processed' + ) cmd.func = self.command return [cmd] def command(self, lib, opts, args): # Get items from arguments items = lib.items(ui.decargs(args)) + self.opts=opts util.par_map(self.analyze_submit, items) def analyze_submit(self, item): @@ -113,12 +128,22 @@ class AcousticBrainzSubmitPlugin(plugins.BeetsPlugin): def _get_analysis(self, item): mbid = item['mb_trackid'] + # If file has no mbid skip it. + if not self.opts.force_refetch and not self.config['force']: + mood_str = item.get('mood_acoustic', u'') + if mood_str: + return None + if not mbid: self._log.info(u'Not analysing {}, missing ' u'musicbrainz track id.', item) return None + if self.opts.dry_fetch or self.config['dry']: + self._log.info(u'dry run - extract item: {}', item) + return None + # Temporary file to save extractor output to, extractor only works # if an output file is given. Here we use a temporary file to copy # the data into a python object and then remove the file from the diff --git a/docs/plugins/absubmit.rst b/docs/plugins/absubmit.rst index 3221a07b3..6caffc27b 100644 --- a/docs/plugins/absubmit.rst +++ b/docs/plugins/absubmit.rst @@ -20,9 +20,12 @@ Submitting Data Type:: - beet absubmit [QUERY] + beet absubmit [-f] [-d] [QUERY] -to run the analysis program and upload its results. +to run the analysis program and upload its results. 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 refetch data even +when it already exists. You can use the ``-d`` or ``--dry``swtich to check which files will be +analyzed, before you start a longer period of processing. The plugin works on music with a MusicBrainz track ID attached. The plugin will also skip music that the analysis tool doesn't support. @@ -40,6 +43,11 @@ To configure the plugin, make a ``absubmit:`` section in your configuration file Default: ``no`` - **extractor**: The absolute path to the `streaming_extractor_music`_ binary. Default: search for the program in your ``$PATH`` +- **force**: Analyse AcousticBrainz data even for tracks that already have + it. + Default: ``no``. +- **dry**: No analyse AcousticBrainz data but print out the files which would be processed + Default: ``no``. .. _streaming_extractor_music: https://acousticbrainz.org/download .. _FAQ: https://acousticbrainz.org/faq From 0242176b408dc990b829088daca482400158c20e Mon Sep 17 00:00:00 2001 From: Susanna Maria Date: Sun, 23 Jun 2019 16:59:33 +0200 Subject: [PATCH 2/9] Why binary import of json? --- beetsplug/absubmit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/absubmit.py b/beetsplug/absubmit.py index e1e327283..fcdd02701 100644 --- a/beetsplug/absubmit.py +++ b/beetsplug/absubmit.py @@ -160,7 +160,7 @@ class AcousticBrainzSubmitPlugin(plugins.BeetsPlugin): item=item, error=e ) return None - with open(filename, 'rb') as tmp_file: + with open(filename, 'r') as tmp_file: analysis = json.load(tmp_file) # Add the hash to the output. analysis['metadata']['version']['essentia_build_sha'] = \ From f99b4841dfcd9d7b75abb685183669ce21d49b6f Mon Sep 17 00:00:00 2001 From: Susanna Maria Date: Sun, 23 Jun 2019 17:04:43 +0200 Subject: [PATCH 3/9] Better documentation --- docs/plugins/absubmit.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/plugins/absubmit.rst b/docs/plugins/absubmit.rst index 6caffc27b..f6e561b35 100644 --- a/docs/plugins/absubmit.rst +++ b/docs/plugins/absubmit.rst @@ -43,10 +43,10 @@ To configure the plugin, make a ``absubmit:`` section in your configuration file Default: ``no`` - **extractor**: The absolute path to the `streaming_extractor_music`_ binary. Default: search for the program in your ``$PATH`` -- **force**: Analyse AcousticBrainz data even for tracks that already have +- **force**: Analyze items and submit of AcousticBrainz data even for tracks that already have it. Default: ``no``. -- **dry**: No analyse AcousticBrainz data but print out the files which would be processed +- **dry**: No analyze and submit of AcousticBrainz data but print out the items which would be processed Default: ``no``. .. _streaming_extractor_music: https://acousticbrainz.org/download From 6e179d86e6fe121f4191b6d3bcc6930fe83bd86c Mon Sep 17 00:00:00 2001 From: Susanna Maria Date: Sun, 23 Jun 2019 17:43:40 +0200 Subject: [PATCH 4/9] Pep8 bugfix --- beetsplug/absubmit.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/beetsplug/absubmit.py b/beetsplug/absubmit.py index fcdd02701..b5f3009ca 100644 --- a/beetsplug/absubmit.py +++ b/beetsplug/absubmit.py @@ -111,14 +111,14 @@ class AcousticBrainzSubmitPlugin(plugins.BeetsPlugin): u'-d', u'--dry', dest='dry_fetch', action='store_true', default=False, help=u'dry run, show files which would be processed' - ) + ) cmd.func = self.command return [cmd] def command(self, lib, opts, args): # Get items from arguments items = lib.items(ui.decargs(args)) - self.opts=opts + self.opts = opts util.par_map(self.analyze_submit, items) def analyze_submit(self, item): @@ -141,7 +141,7 @@ class AcousticBrainzSubmitPlugin(plugins.BeetsPlugin): return None if self.opts.dry_fetch or self.config['dry']: - self._log.info(u'dry run - extract item: {}', item) + self._log.info(u'dry run - extract item: {}', item) return None # Temporary file to save extractor output to, extractor only works From 2bfc7723fa3e8bf6fea57e68f24de5673b0dd633 Mon Sep 17 00:00:00 2001 From: Susanna Maria Date: Sun, 23 Jun 2019 18:01:21 +0200 Subject: [PATCH 5/9] Fix findings from travis-ci --- docs/plugins/absubmit.rst | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/docs/plugins/absubmit.rst b/docs/plugins/absubmit.rst index f6e561b35..a9cf651ce 100644 --- a/docs/plugins/absubmit.rst +++ b/docs/plugins/absubmit.rst @@ -7,13 +7,18 @@ The ``absubmit`` plugin lets you submit acoustic analysis results to the Installation ------------ -The ``absubmit`` plugin requires the `streaming_extractor_music`_ program to run. Its source can be found on `GitHub`_, and while it is possible to compile the extractor from source, AcousticBrainz would prefer if you used their binary (see the AcousticBrainz `FAQ`_). +The ``absubmit`` plugin requires the `streaming_extractor_music`_ program +to run. Its source can be found on `GitHub`_, and while it is possible to +compile the extractor from source, AcousticBrainz would prefer if you used +their binary (see the AcousticBrainz `FAQ`_). -The ``absubmit`` plugin also requires `requests`_, which you can install using `pip`_ by typing:: +The ``absubmit`` plugin also requires `requests`_, which you can install +using `pip`_ by typing:: pip install requests -After installing both the extractor binary and requests you can enable the plugin ``absubmit`` in your configuration (see :ref:`using-plugins`). +After installing both the extractor binary and requests you can enable +the plugin ``absubmit`` in your configuration (see :ref:`using-plugins`). Submitting Data --------------- @@ -22,10 +27,12 @@ Type:: beet absubmit [-f] [-d] [QUERY] -to run the analysis program and upload its results. 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 refetch data even -when it already exists. You can use the ``-d`` or ``--dry``swtich to check which files will be -analyzed, before you start a longer period of processing. +To run the analysis program and upload its results. 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 refetch +data even when it already exists. You can use the ``-d`` or ``--dry`` swtich +to check which files will be analyzed, before you start a longer period +of processing. The plugin works on music with a MusicBrainz track ID attached. The plugin will also skip music that the analysis tool doesn't support. @@ -37,17 +44,20 @@ will also skip music that the analysis tool doesn't support. Configuration ------------- -To configure the plugin, make a ``absubmit:`` section in your configuration file. The available options are: +To configure the plugin, make a ``absubmit:`` section in your configuration +file. The available options are: -- **auto**: Analyze every file on import. Otherwise, you need to use the ``beet absubmit`` command explicitly. +- **auto**: Analyze every file on import. Otherwise, you need to use the + ``beet absubmit`` command explicitly. Default: ``no`` - **extractor**: The absolute path to the `streaming_extractor_music`_ binary. Default: search for the program in your ``$PATH`` -- **force**: Analyze items and submit of AcousticBrainz data even for tracks that already have - it. - Default: ``no``. -- **dry**: No analyze and submit of AcousticBrainz data but print out the items which would be processed - Default: ``no``. +- **force**: Analyze items and submit of AcousticBrainz data even for tracks + that already have it. + Default: ``no``. +- **dry**: No analyze and submit of AcousticBrainz data but print out the + items which would be processed + Default: ``no``. .. _streaming_extractor_music: https://acousticbrainz.org/download .. _FAQ: https://acousticbrainz.org/faq From f254b33c6ede8170c05925ad0e30399814758fec Mon Sep 17 00:00:00 2001 From: Susanna Maria Date: Tue, 25 Jun 2019 20:22:26 +0200 Subject: [PATCH 6/9] Findings from PR --- beetsplug/absubmit.py | 14 ++++++++------ docs/plugins/absubmit.rst | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/beetsplug/absubmit.py b/beetsplug/absubmit.py index b5f3009ca..ececda861 100644 --- a/beetsplug/absubmit.py +++ b/beetsplug/absubmit.py @@ -58,9 +58,11 @@ class AcousticBrainzSubmitPlugin(plugins.BeetsPlugin): self.config.add({ 'extractor': u'', 'force': False, - 'dry': False + 'pretend': False }) + self.PROBE_FIELD = 'mood_acoustic' + self.extractor = self.config['extractor'].as_str() if self.extractor: self.extractor = util.normpath(self.extractor) @@ -108,9 +110,9 @@ class AcousticBrainzSubmitPlugin(plugins.BeetsPlugin): help=u're-download data when already present' ) cmd.parser.add_option( - u'-d', u'--dry', dest='dry_fetch', + u'-p', u'--pretend', dest='pretend_fetch', action='store_true', default=False, - help=u'dry run, show files which would be processed' + help=u'pretend to perform action, but show only files which would be processed' ) cmd.func = self.command return [cmd] @@ -131,7 +133,7 @@ class AcousticBrainzSubmitPlugin(plugins.BeetsPlugin): # If file has no mbid skip it. if not self.opts.force_refetch and not self.config['force']: - mood_str = item.get('mood_acoustic', u'') + mood_str = item.get(self.PROBE_FIELD, u'') if mood_str: return None @@ -140,8 +142,8 @@ class AcousticBrainzSubmitPlugin(plugins.BeetsPlugin): u'musicbrainz track id.', item) return None - if self.opts.dry_fetch or self.config['dry']: - self._log.info(u'dry run - extract item: {}', item) + if self.opts.pretend_fetch or self.config['pretend']: + self._log.info(u'pretend action - extract item: {}', item) return None # Temporary file to save extractor output to, extractor only works diff --git a/docs/plugins/absubmit.rst b/docs/plugins/absubmit.rst index a9cf651ce..64c77e077 100644 --- a/docs/plugins/absubmit.rst +++ b/docs/plugins/absubmit.rst @@ -55,8 +55,8 @@ file. The available options are: - **force**: Analyze items and submit of AcousticBrainz data even for tracks that already have it. Default: ``no``. -- **dry**: No analyze and submit of AcousticBrainz data but print out the - items which would be processed +- **pretend**: Do not analyze and submit of AcousticBrainz data but print out + the items which would be processed. Default: ``no``. .. _streaming_extractor_music: https://acousticbrainz.org/download From 932d18a838925142f7dfa287e9da16e6e7c64fd6 Mon Sep 17 00:00:00 2001 From: Susanna Maria Date: Tue, 25 Jun 2019 20:37:12 +0200 Subject: [PATCH 7/9] Pep8 error ... --- beetsplug/absubmit.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/beetsplug/absubmit.py b/beetsplug/absubmit.py index ececda861..ac3094c9b 100644 --- a/beetsplug/absubmit.py +++ b/beetsplug/absubmit.py @@ -112,7 +112,8 @@ class AcousticBrainzSubmitPlugin(plugins.BeetsPlugin): cmd.parser.add_option( u'-p', u'--pretend', dest='pretend_fetch', action='store_true', default=False, - help=u'pretend to perform action, but show only files which would be processed' + help=u'pretend to perform action, but show ' \ + 'only files which would be processed' ) cmd.func = self.command return [cmd] From cab97c58d4dd420a79860d7f7000397545669fe7 Mon Sep 17 00:00:00 2001 From: Susanna Maria Date: Tue, 25 Jun 2019 20:57:43 +0200 Subject: [PATCH 8/9] Pep8 drives me sometimes crazy --- beetsplug/absubmit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/beetsplug/absubmit.py b/beetsplug/absubmit.py index ac3094c9b..29ed5c3fb 100644 --- a/beetsplug/absubmit.py +++ b/beetsplug/absubmit.py @@ -112,8 +112,8 @@ class AcousticBrainzSubmitPlugin(plugins.BeetsPlugin): cmd.parser.add_option( u'-p', u'--pretend', dest='pretend_fetch', action='store_true', default=False, - help=u'pretend to perform action, but show ' \ - 'only files which would be processed' + help=u'pretend to perform action, but show \ +only files which would be processed' ) cmd.func = self.command return [cmd] From b20516e552fce31ef61c0457ea6af08ab7bff083 Mon Sep 17 00:00:00 2001 From: Susanna Maria Date: Wed, 26 Jun 2019 20:29:17 +0200 Subject: [PATCH 9/9] Small improvement of code doc --- beetsplug/absubmit.py | 1 + 1 file changed, 1 insertion(+) diff --git a/beetsplug/absubmit.py b/beetsplug/absubmit.py index 29ed5c3fb..594d0dc01 100644 --- a/beetsplug/absubmit.py +++ b/beetsplug/absubmit.py @@ -61,6 +61,7 @@ class AcousticBrainzSubmitPlugin(plugins.BeetsPlugin): 'pretend': False }) + # Define a field which shows that acousticbrainz info is present self.PROBE_FIELD = 'mood_acoustic' self.extractor = self.config['extractor'].as_str()