mirror of
https://github.com/beetbox/beets.git
synced 2026-01-08 17:08:12 +01:00
chroma: fingerprint command's write from config
This turns on metadata-writing based on the import.write config option, so those with this option turned off will be spared any surprises. (Affects #217 and #143.)
This commit is contained in:
parent
c72cb5af59
commit
aff3fb106d
2 changed files with 21 additions and 14 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -78,9 +78,11 @@ editing your :doc:`configuration file </reference/config>`. 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:
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue