Bug in chroma plugin when recording was merged
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 2.1k
- Avg merge
- 4d 21h
- Merged PRs (30d)
- 31
Description
### Problem
I've found a bug within the chroma plugin which can cause the recordings returned by an acoustid lookup to be suggested with an incorrect distance when those recording have been merged.
For example, the fingerprint [AQADtJmYJYsSKQry5...](https://github.com/user-attachments/files/18001382/fingerprint.txt) of [this music file](https://github.com/user-attachments/files/18001549/song.zip) results in an acoustid response:
```json
{
"results": [
{
"id": "ad580b8c-ff11-4656-83a5-7e7915ac5c9e",
"recordings": [
{
"id": "a63c1288-7247-4d3b-8ca0-453d8a38e2ed"
},
{
"id": "de8c09f3-0f69-4c39-93dd-e0964b0f8492"
}
],
"score": 0.9669699
},
...
```
Both recordings have been merged into the recording with the id [79d185cc-8453-4020-85f3-0c53d4a2ebd1](https://musicbrainz.org/recording/79d185cc-8453-4020-85f3-0c53d4a2ebd1).
However, when importing the music file using beets, the recording [79d185cc-8453-4020-85f3-0c53d4a2ebd1](https://musicbrainz.org/recording/79d185cc-8453-4020-85f3-0c53d4a2ebd1) might not be the best candidate. This is because of the variable `recording_ids` in the `track_distance` function of the chroma plugin does not contain the id `79d185cc-8453-4020-85f3-0c53d4a2ebd1`.
```python
def track_distance(self, item, info):
dist = hooks.Distance()
if item.path not in _matches or not info.track_id:
# Match failed or no track ID.
return dist
recording_ids, _ = _matches[item.path]
dist.add_expr("track_id", info.track_id not in recording_ids)
return dist
```
### Step to reproduce
The import of [the music file from above](https://github.com/user-attachments/files/18001549/song.zip) with the chroma plugin enabled does not confidently suggest the recording [79d185cc-8453-4020-85f3-0c53d4a2ebd1](https://musicbrainz.org/recording/79d185cc-8453-4020-85f3-0c53d4a2ebd1).
```sh
$ beet import -s song.mp3
/media/.../song.mp3
Finding tags for track "Phantom Planet - California".
Candidates:
1. (58.3%) Phantom Planet - California
≠ id
MusicBrainz, Index None, Track None,
2. (58.3%) Phantom Planet - California
≠ id
MusicBrainz, Index None, Track None,
3. (58.3%) Phantom Planet - California
≠ id
MusicBrainz, Index None, Track None,
4. (54.3%) Phantom Planet - California
≠ id, length
MusicBrainz, Index None, Track None,
5. (54.1%) Phantom Planet - California (Tchad Blake mix)
≠ id, title
MusicBrainz, Index None, Track None,
6. (41.9%) Phantom Planet - California
≠ id, length
MusicBrainz, Index None, Track None,
➜ # selection (default 1), Skip, Use as-is, Enter search, enter Id, aBort?
```
### Proposed solution
[This commit](https://github.com/beetbox/beets/commit/a4e3b14b6f9e0debbcdbdb56f3b475406e015cf1) seems to fix the issue.

```sh
$ beet import -s song.mp3
/media/.../song.mp3
Match (95.8%):
Phantom Planet - California (Tchad Blake mix)
≠ title
MusicBrainz, Index None, Track None,
https://musicbrainz.org/recording/79d185cc-8453-4020-85f3-0c53d4a2ebd1
* Artist: Phantom Planet
≠ Title: California -> California (Tchad Blake mix)
➜ [A]pply, More candidates, Skip, Use as-is, Enter search, enter Id, aBort
```
### Setup
* OS: Ubuntu 24.04.1 LTS
* Python version: 3.12.3
* beets version: 2.2.0
* Turning off other plugins made problem go away (yes/no): no
My configuration (output of `beet config`) is:
```yaml
# --------------- Plugins ---------------
plugins: chroma
directory: /media/markus/DataLinux/Temp/BeetsBug
# --------------- Main ---------------
library: /media/markus/DataLinux/Temp/BeetsBug/library.db
chroma:
auto: yes
```
Contributor guide
Assessment
This issue has not been assessed yet.