mirror of
https://github.com/beetbox/beets.git
synced 2025-12-15 21:14:19 +01:00
Merge pull request #3318 from SusannaMaria/absubmit-improvements
Absubmit improvements
This commit is contained in:
commit
cca6c49784
2 changed files with 56 additions and 9 deletions
|
|
@ -55,7 +55,14 @@ class AcousticBrainzSubmitPlugin(plugins.BeetsPlugin):
|
|||
def __init__(self):
|
||||
super(AcousticBrainzSubmitPlugin, self).__init__()
|
||||
|
||||
self.config.add({'extractor': u''})
|
||||
self.config.add({
|
||||
'extractor': u'',
|
||||
'force': False,
|
||||
'pretend': False
|
||||
})
|
||||
|
||||
# Define a field which shows that acousticbrainz info is present
|
||||
self.PROBE_FIELD = 'mood_acoustic'
|
||||
|
||||
self.extractor = self.config['extractor'].as_str()
|
||||
if self.extractor:
|
||||
|
|
@ -98,12 +105,24 @@ 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'-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'
|
||||
)
|
||||
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 +132,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(self.PROBE_FIELD, 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.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
|
||||
# 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
|
||||
|
|
@ -135,7 +164,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'] = \
|
||||
|
|
|
|||
|
|
@ -7,22 +7,32 @@ 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
|
||||
---------------
|
||||
|
||||
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.
|
||||
|
|
@ -34,12 +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``.
|
||||
- **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
|
||||
.. _FAQ: https://acousticbrainz.org/faq
|
||||
|
|
|
|||
Loading…
Reference in a new issue