diff --git a/beetsplug/chroma.py b/beetsplug/chroma.py index e8df67497..d249893d8 100644 --- a/beetsplug/chroma.py +++ b/beetsplug/chroma.py @@ -159,11 +159,13 @@ class AcoustidPlugin(plugins.BeetsPlugin): submit_cmd.func = submit_cmd_func fingerprint_cmd = ui.Subcommand('fingerprint', - help='fingerprints files with no fingerprint stored') + help='generate fingerprints for items without them') def fingerprint_cmd_func(lib, opts, args): for item in lib.items(ui.decargs(args)): - fingerprint_item(item, lib=lib, write=True) + fingerprint_item(item, lib=lib, + write=config['import']['write'].get(bool)) fingerprint_cmd.func = fingerprint_cmd_func + return [submit_cmd, fingerprint_cmd] @@ -235,23 +237,27 @@ def submit_items(userkey, items, chunksize=64): def fingerprint_item(item, lib=None, write=False): - """Fingerprints files that don't already have prints stored + """Get the fingerprint for an Item. If the item already has a + fingerprint, it is not regenerated. If fingerprint generation fails, + return None. If `lib` is provided, then new fingerprints are saved + to the database. If `write` is set, then the new fingerprints are + also written to files' metadata. """ # Get a fingerprint and length for this track. if not item.length: log.info(u'{0}: no duration available'.format( util.displayable_path(item.path) )) - return elif item.acoustid_fingerprint: - if not write: + if write: + log.info(u'{0}: fingerprint exists, skipping'.format( + util.displayable_path(item.path) + )) + else: log.info(u'{0}: using existing fingerprint'.format( util.displayable_path(item.path) )) return item.acoustid_fingerprint - log.info(u'{0}: skipping. fingerprint exists'.format( - util.displayable_path(item.path) - )) else: log.info(u'{0}: fingerprinting'.format( util.displayable_path(item.path) @@ -259,16 +265,15 @@ def fingerprint_item(item, lib=None, write=False): try: _, fp = acoustid.fingerprint_file(item.path) item.acoustid_fingerprint = fp - if write and lib is not None: + if write: log.info(u'{0}: writing fingerprint'.format( util.displayable_path(item.path) )) item.write() + if lib: lib.store(item) return item.acoustid_fingerprint except acoustid.FingerprintGenerationError as exc: log.info( 'fingerprint generation failed: {0}'.format(exc) ) - return - diff --git a/docs/plugins/chroma.rst b/docs/plugins/chroma.rst index 0677ca957..9fea8cc96 100644 --- a/docs/plugins/chroma.rst +++ b/docs/plugins/chroma.rst @@ -78,9 +78,11 @@ editing your :doc:`configuration file `. Put ``chroma`` on your ``plugins:`` line. With that, beets will use fingerprinting the next time you run ``beet import``. -You can also use ``beet fingerprint`` to fingerprint the tracks already imported -without fingerprints. (You can provide a query to fingerprint a subset of your -library). +You can also use the ``beet fingerprint`` command to generate fingerprints for +items already in your library. (Provide a query to fingerprint a subset of your +library.) The generated fingerprints will be stored in the library database. +If you have the ``import.write`` config option enabled, they will also be +written to files' metadata. .. _submitfp: