Skip to content

Commit 8fd20b9

Browse files
authored
Fix the MusicBrainz search not taking into account the album/recording aliases (#5821)
When searching on MusicBrainz, beets does not add the `alias` field that allows for searching on the entity aliases. As per [the MusicBrainz Indexed Search Syntax](https://musicbrainz.org/doc/Indexed_Search_Syntax#Search_Fields_9): > alias | (part of) any alias attached to the release group (diacritics are ignored) > [...] > release | (part of) the title of any of the releases in the release group By adding the `alias` field assigned with the entity title, the search returns better results for titles that can be aliased. The problem can be reproduced with the following album: https://musicbrainz.org/release-group/b5b4eed2-e871-4268-80bb-7625ee0c6cd0: - Currently, beets searches using the following query: [`release:(rude lose dance \- single) tracks:(1) artist:(minami)`](https://musicbrainz.org/search?query=release%3A%28rude+lose+dance+%5C-+single%29+tracks%3A%281%29+artist%3A%28minami%29&type=release_group&limit=25&method=advanced) - We can see that the correct album cannot be found (even after 5 pages!) - With this PR, beets now searches using the following query: [`release:(rude lose dance \- single) alias:(rude lose dance \- single) tracks:(1) artist:(minami)`](https://musicbrainz.org/search?query=release%3A%28rude+lose+dance+%5C-+single%29+alias%3A%28rude+lose+dance+%5C-+single%29+tracks%3A%281%29+artist%3A%28minami%29&type=release_group&limit=25&method=advanced) - We can see that the correct album is now found in 1st position! Tests had to be updated due to the addition of the `alias` criteria.
2 parents 66864fc + 4893cee commit 8fd20b9

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

beetsplug/musicbrainz.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,7 @@ def get_album_criteria(
771771
) -> dict[str, str]:
772772
criteria = {
773773
"release": album,
774+
"alias": album,
774775
"tracks": str(len(items)),
775776
} | ({"arid": VARIOUS_ARTISTS_ID} if va_likely else {"artist": artist})
776777

@@ -826,7 +827,7 @@ def candidates(
826827
def item_candidates(
827828
self, item: Item, artist: str, title: str
828829
) -> Iterator[beets.autotag.hooks.TrackInfo]:
829-
criteria = {"artist": artist, "recording": title}
830+
criteria = {"artist": artist, "recording": title, "alias": title}
830831

831832
yield from filter(
832833
None, map(self.track_info, self._search_api("recording", criteria))

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Bug fixes:
3737
* Fix ``HiddenFileTest`` by using ``bytestring_path()``.
3838
* tests: Fix tests failing without ``langdetect`` (by making it required).
3939
:bug:`5797`
40+
* :doc:`plugins/musicbrainz`: Fix the MusicBrainz search not taking into
41+
account the album/recording aliases
4042

4143
For packagers:
4244

test/plugins/test_musicbrainz.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,7 @@ def test_get_album_criteria(
10251025

10261026
assert mb.get_album_criteria(items, "Artist ", " Album", va_likely) == {
10271027
"release": " Album",
1028+
"alias": " Album",
10281029
"tracks": str(len(items)),
10291030
**expected_additional_criteria,
10301031
}

0 commit comments

Comments
 (0)