`mb_track_extract`'s changes overwritten by `album_info`
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 2.1k
- Avg merge
- 4d 21h
- Merged PRs (30d)
- 31
Description
### Background
I've been working on a beets plugin to adjust tags and paths of imported music to my preferences. I wasn't particularly happy with how "ftintitle" works, given that beets itself renders the structured data down into a string, and the string is then post-processed by that plugin. I had a go at implementing an alternative, using the `mb_track_extract` and `mb_album_extract` hooks, which render _from the source data_ the desired output for multiple artist credits.
### Problem
While the hooks work mostly as expected...
(at the end of processing a track, calls a hook and merges the return value into the TrackInfo object)
https://github.com/beetbox/beets/blob/cfb32d9bc5450982a9a9a513cedf5ea553ecc8d2/beets/autotag/mb.py#L279-L281
(at the end of processing an album, calls a hook and merges the return value into the AlbumInfo object)
https://github.com/beetbox/beets/blob/cfb32d9bc5450982a9a9a513cedf5ea553ecc8d2/beets/autotag/mb.py#L478-L480
...There is an additional case where the album_info function overwrites the track_info data with "reprocessed" information based on the album's `tracks` results:
https://github.com/beetbox/beets/blob/cfb32d9bc5450982a9a9a513cedf5ea553ecc8d2/beets/autotag/mb.py#L354-L390
The result is that, if an `mb_track_extract` hook updates a track's title or artist info, that info is dicarded when importing in album mode because the `album_info` call explicitly overwrites it.
I intended to send a PR with a fix (the solution here could take multiple forms, but the simplest is to call the hook again before `track_infos.append`), but I was a little surprised that I couldn't find any existing tests around the hook behavior of the musicbrainz import hooks. I don't have a good enough understanding of the codebase to write some from scratch, so I'm hoping that somebody can guide me:
How can I mock out the appropriate data and processes so that I can write tests around correct behavior of hooks being called when importing albums and/or tracks? Which file is most appropriate, and what mechanisms must I mock or satisfy to accomplish this task?
Contributor guide
Assessment
This issue has not been assessed yet.