From 8a64686ff3d504bab3edcc1d558447ac0913b7db Mon Sep 17 00:00:00 2001 From: Lucas Duailibe Date: Mon, 11 Mar 2013 17:56:13 -0300 Subject: [PATCH] store fingerprints --- beetsplug/chroma.py | 19 +++++++++++++++++-- docs/plugins/chroma.rst | 5 +++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/beetsplug/chroma.py b/beetsplug/chroma.py index 2e2ce52b5..7722f2f9d 100644 --- a/beetsplug/chroma.py +++ b/beetsplug/chroma.py @@ -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) diff --git a/docs/plugins/chroma.rst b/docs/plugins/chroma.rst index b24a4816a..1166ada5d 100644 --- a/docs/plugins/chroma.rst +++ b/docs/plugins/chroma.rst @@ -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