beetbox / beetbox/beets

chroma: Fingerprint files on import, even in "as-is" cases

Open
#3,320 1 comment 0 reactions 0 assignees View on GitHub
chroma feature
Dominant language
Python
Stars
15.7k
Forks
2.1k
Avg merge
4d 21h
Merged PRs (30d)
31

Description

### Problem

In short: chroma doesn't apply the audio fingerprint when a track is imported with specific options.
Options:
- Use as-is
- eDit (from edit plugin)
- edit Candidates (from edit plugin)
- maybe others

For me is important to have this field for every track to have an additional way to *check for duplicates*.

### Steps to reproduce

1. Run the `beet import` command to import a track
2. After the candidates are shown. select the option `Use as-is` to import the track
3. Use `beet ls` command to check the track just imported (including `acoustid_fingerprint` in the output format). As alternative you can use the `edit` with `-all` option enabled like this
```bash
beet edit --all
```
4. You will see that the fingerprint is not assigned.
5. If you choose one of the candidates instead, the fingerprint gets assigned correctly.

### (Possible) cause of the issue

I had a look at the code of the `importer` and the chroma plugin.
- The chroma plugin assigns his metadata (id and fingerprints) when the event `import_task_apply` is fired.
- The importer trigger the `import_task_apply` events when a candidate is applied but not when is imported as-is or a manual edit (edit plugin) is applied.

### workaround

I tried to update the chroma code but I didn't find any better event to use as hook.
`item_imported` was an option but once imported, an item changes the path property necessary for correctly assign chroma metatags in the item.

```python
#Snippet of code from chroma plugin
for item in task.imported_items():
if item.path in _fingerprints:
item.acoustid_fingerprint = _fingerprints[item.path]
```

For `eDit` and `edit Candidates` options, I solved customizing the edit plugin triggering the event `import_task_apply` manually.
```python
# Save the new data.
if success:
# Return action.RETAG, which makes the importer write the tags
# to the files if needed without re-applying metadata.
plugins.send('import_task_apply', session=session, task=task) # <-------- event triggered
return action.RETAG
```

An obvious possibility is to run `beet fingerprint` after every import to be sure to set the fingerprint to every track.

### Setup

* OS: Windows 10 (using beet in WSL Ubuntu)
* Python version: Python 3.6.7
* beets version: 1.4.9

My configuration (output of `beet config`) is: No relevant configuration

Contributor guide

Open the contributing guide

Research direction

Trace the importer and chroma plugin around the import_task_apply and item_imported events, using the reported as-is and candidate import paths as starting points. Reproduce with beet import and inspect the result with beet ls; done means acoustid_fingerprint is assigned for as-is, candidate, and edit-related imports without breaking existing metadata handling.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.