diff --git a/beetsplug/musicbrainz.py b/beetsplug/musicbrainz.py index cc0b7adee..d6960300e 100644 --- a/beetsplug/musicbrainz.py +++ b/beetsplug/musicbrainz.py @@ -768,15 +768,14 @@ class MusicBrainzPlugin(BeetsPlugin): def get_album_criteria( self, items: list[Item], artist: str, album: str, va_likely: bool ) -> dict[str, str]: - # Build search criteria. - criteria = {"release": album.lower().strip()} - if artist is not None: - criteria["artist"] = artist.lower().strip() - else: - # Various Artists search. - criteria["arid"] = VARIOUS_ARTISTS_ID - if track_count := len(items): - criteria["tracks"] = str(track_count) + criteria = { + "release": album.lower().strip(), + "tracks": str(len(items)), + } | ( + {"arid": VARIOUS_ARTISTS_ID} + if va_likely + else {"artist": artist.lower().strip()} + ) for tag, mb_field in self.extra_mb_field_by_tag.items(): most_common, _ = util.plurality(i.get(tag) for i in items) @@ -804,9 +803,6 @@ class MusicBrainzPlugin(BeetsPlugin): optionally, a number of tracks on the album and any other extra tags. """ criteria = self.get_album_criteria(items, artist, album, va_likely) - # Abort if we have no search terms. - if not any(criteria.values()): - return try: self._log.debug( @@ -837,9 +833,6 @@ class MusicBrainzPlugin(BeetsPlugin): "recording": title.lower().strip(), } - if not any(criteria.values()): - return - try: res = musicbrainzngs.search_recordings( limit=self.config["searchlimit"].get(int), **criteria diff --git a/test/plugins/test_musicbrainz.py b/test/plugins/test_musicbrainz.py index d74e3ff40..90befff9b 100644 --- a/test/plugins/test_musicbrainz.py +++ b/test/plugins/test_musicbrainz.py @@ -823,23 +823,13 @@ class MBLibraryTest(MusicBrainzTestCase): ai = list(self.mb.candidates([], "hello", "there", False))[0] - sp.assert_called_with(artist="hello", release="there", limit=5) + sp.assert_called_with( + artist="hello", release="there", tracks="0", limit=5 + ) gp.assert_called_with(mbid, mock.ANY) assert ai.tracks[0].title == "foo" assert ai.album == "hi" - def test_match_track_empty(self): - with mock.patch("musicbrainzngs.search_recordings") as p: - til = list(self.mb.item_candidates(None, " ", " ")) - assert not p.called - assert til == [] - - def test_candidates_empty(self): - with mock.patch("musicbrainzngs.search_releases") as p: - ail = list(self.mb.candidates([], " ", " ", False)) - assert not p.called - assert ail == [] - def test_follow_pseudo_releases(self): side_effect = [ {