Commits

Lucas Duailibe  committed 3f2fef6

store fingerprints

  • Participants
  • Parent commits d04198c

Comments (0)

Files changed (2)

File beetsplug/chroma.py

             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.
     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]
 
 
 # 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.
             ))
             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)

File docs/plugins/chroma.rst

 * 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.
 
 
 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