store fingerprints

This commit is contained in:
Lucas Duailibe 2013-03-11 17:56:13 -03:00
parent 33ff0e8fd2
commit 8a64686ff3
2 changed files with 20 additions and 4 deletions

View file

@ -112,6 +112,11 @@ def _all_releases(items):
yield release_id
class AcoustidPlugin(plugins.BeetsPlugin):
def __init__(self):
super(AcoustidPlugin, self).__init__()
self.config.add({
u'write': False
})
def track_distance(self, item, info):
if item.path not in _matches:
# Match failed.
@ -150,12 +155,15 @@ class AcoustidPlugin(plugins.BeetsPlugin):
def commands(self):
submit_cmd = ui.Subcommand('submit',
help='submit Acoustid fingerprints')
submit_cmd.parser.add_option('-w', '--write', action='store_true',
help='store the calculated fingerprints')
def submit_cmd_func(lib, opts, args):
try:
apikey = config['acoustid']['apikey'].get(unicode)
except confit.NotFoundError:
raise ui.UserError('no Acoustid user API key provided')
submit_items(apikey, lib.items(ui.decargs(args)))
submit_items(lib, apikey, lib.items(ui.decargs(args)),
write=opts.write)
submit_cmd.func = submit_cmd_func
return [submit_cmd]
@ -184,7 +192,7 @@ def apply_acoustid_metadata(task, session):
# UI commands.
def submit_items(userkey, items, chunksize=64):
def submit_items(lib, userkey, items, chunksize=64, write=False):
"""Submit fingerprints for the items to the Acoustid server.
"""
data = [] # The running list of dictionaries to submit.
@ -212,6 +220,13 @@ def submit_items(userkey, items, chunksize=64):
))
try:
_, fp = acoustid.fingerprint_file(item.path)
item.acoustid_fingerprint = fp
if write:
log.info(u'{0}: storing fingerprint'.format(
util.displayable_path(item.path)
))
item.write()
lib.store(item)
except acoustid.FingerprintGenerationError as exc:
log.info(
'fingerprint generation failed: {0}'.format(exc)

View file

@ -45,7 +45,7 @@ Next, you will need a mechanism for decoding audio files supported by the
* On Linux, you can install `GStreamer for Python`_, `FFmpeg`_, or `MAD`_ and
`pymad`_. How you install these will depend on your distribution. For example,
on Ubuntu, run ``apt-get install python-gst0.10-dev``. On Arch Linux, you want
``pacman -S gstreamer0.10-python``.
``pacman -S gstreamer0.10-python``.
* On Windows, try the Gstreamer "WinBuilds" from the `OSSBuild`_ project.
@ -94,6 +94,7 @@ value ``apikey`` in a section called ``acoustid`` like so::
Then, run ``beet submit``. (You can also provide a query to submit a subset of
your library.) The command will use stored fingerprints if they're available;
otherwise it will fingerprint each file before submitting it.
otherwise it will fingerprint each file before submitting it. The ``-w``option
will store the fingerprints in the library.
.. _get an API key: http://acoustid.org/api-key