Parameter handling

This commit is contained in:
Susanna Maria 2019-06-23 13:04:17 +02:00
parent b64059b173
commit 1643eea3f5
2 changed files with 36 additions and 3 deletions

View file

@ -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

View file

@ -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