Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#2347: First hack of ignoring already tagged items #2349

Merged
merged 7 commits into from
Dec 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions beetsplug/acousticbrainz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -118,7 +119,13 @@ def commands(self):

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might need something like this to make the command-line flag work:

cmd.parser.add_option(
    u'-f', u'--force', dest='force_refetch',
    action='store_true', default=False,
    help=u're-download data if present',
)

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're-download data when already present'
)

cmd.func = func
return [cmd]
Expand Down Expand Up @@ -151,10 +158,17 @@ 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:
if not force:
mood_str = item.get('mood_acoustic', u'')
if mood_str:
self._log.info(u'Already set acoustic\
brainz tags for {} ', item)
continue

if not item.mb_trackid:
continue

Expand Down
10 changes: 9 additions & 1 deletion docs/plugins/acousticbrainz.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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``.