mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 16:42:42 +01:00
Take into account va_likely param and remove redundant checks
- Instead of checking for empty `artist` query, use `va_likely` parameter to determine whether we should query for Various Artists or not. - `album` / `title` is always a truthy string - no need to handle empty criteria case - `tracks` list always has at least one track - no need to check for `len(items)`
This commit is contained in:
parent
6487893315
commit
0102f3ce7d
2 changed files with 11 additions and 28 deletions
|
|
@ -768,15 +768,14 @@ class MusicBrainzPlugin(BeetsPlugin):
|
||||||
def get_album_criteria(
|
def get_album_criteria(
|
||||||
self, items: list[Item], artist: str, album: str, va_likely: bool
|
self, items: list[Item], artist: str, album: str, va_likely: bool
|
||||||
) -> dict[str, str]:
|
) -> dict[str, str]:
|
||||||
# Build search criteria.
|
criteria = {
|
||||||
criteria = {"release": album.lower().strip()}
|
"release": album.lower().strip(),
|
||||||
if artist is not None:
|
"tracks": str(len(items)),
|
||||||
criteria["artist"] = artist.lower().strip()
|
} | (
|
||||||
else:
|
{"arid": VARIOUS_ARTISTS_ID}
|
||||||
# Various Artists search.
|
if va_likely
|
||||||
criteria["arid"] = VARIOUS_ARTISTS_ID
|
else {"artist": artist.lower().strip()}
|
||||||
if track_count := len(items):
|
)
|
||||||
criteria["tracks"] = str(track_count)
|
|
||||||
|
|
||||||
for tag, mb_field in self.extra_mb_field_by_tag.items():
|
for tag, mb_field in self.extra_mb_field_by_tag.items():
|
||||||
most_common, _ = util.plurality(i.get(tag) for i in 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.
|
optionally, a number of tracks on the album and any other extra tags.
|
||||||
"""
|
"""
|
||||||
criteria = self.get_album_criteria(items, artist, album, va_likely)
|
criteria = self.get_album_criteria(items, artist, album, va_likely)
|
||||||
# Abort if we have no search terms.
|
|
||||||
if not any(criteria.values()):
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._log.debug(
|
self._log.debug(
|
||||||
|
|
@ -837,9 +833,6 @@ class MusicBrainzPlugin(BeetsPlugin):
|
||||||
"recording": title.lower().strip(),
|
"recording": title.lower().strip(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if not any(criteria.values()):
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = musicbrainzngs.search_recordings(
|
res = musicbrainzngs.search_recordings(
|
||||||
limit=self.config["searchlimit"].get(int), **criteria
|
limit=self.config["searchlimit"].get(int), **criteria
|
||||||
|
|
|
||||||
|
|
@ -823,23 +823,13 @@ class MBLibraryTest(MusicBrainzTestCase):
|
||||||
|
|
||||||
ai = list(self.mb.candidates([], "hello", "there", False))[0]
|
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)
|
gp.assert_called_with(mbid, mock.ANY)
|
||||||
assert ai.tracks[0].title == "foo"
|
assert ai.tracks[0].title == "foo"
|
||||||
assert ai.album == "hi"
|
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):
|
def test_follow_pseudo_releases(self):
|
||||||
side_effect = [
|
side_effect = [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue