Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions beetsplug/deezer.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,20 @@ def get_search_query_with_filters(
name: str,
va_likely: bool,
) -> tuple[str, dict[str, str]]:
query = f'album:"{name}"' if query_type == "album" else name
if query_type == "track" or not va_likely:
query += f' artist:"{artist}"'
if query_type == "album":
query = f'album:"{name}"'
if not va_likely:
query += f' artist:"{artist}"'
else:
# Deezer drops unquoted free text as soon as the query carries any
# field:"value" filter, so `<title> artist:"<artist>"` degenerated
# into "every track by this artist", truncated to `search_limit`.
# The wanted track routinely fell outside that window. Filtering on
# the title instead is no better, because `artist:` is fuzzy enough
# to match unrelated artists ("Pan Da Punk" for "Daft Punk"), so the
# two filters can intersect to nothing even for a well-tagged file.
# Plain free text lets Deezer's own relevance ranking do the work.
query = f"{name} {artist}".strip()
Comment thread
semohr marked this conversation as resolved.

return query, {}

Expand Down
7 changes: 7 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ Bug fixes
- :doc:`plugins/lyrics`: ``beet lyrics`` no longer crashes with an
``AttributeError`` on tracks that have no stored lyrics when ``force`` is
enabled; a missing lyrics body is now treated as empty text. :bug:`6860`
- :doc:`plugins/deezer`: Singleton searches now use plain free text rather than
``<title> artist:"<artist>"``. Deezer discards unquoted free text as soon as a
query contains any ``field:"value"`` filter, so the old query was evaluated as
``artist:"<artist>"`` alone -- every track by the artist, in Deezer's own
relevance order and truncated to ``search_limit``. For artists with more
releases than that window, the track being imported was never among the
candidates offered.

..
For plugin developers
Expand Down
41 changes: 41 additions & 0 deletions test/plugins/test_deezer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import pytest

from beets.library import Item
from beetsplug.deezer import DeezerPlugin


@pytest.fixture
def plugin():
return DeezerPlugin()


class TestSearchQuery:
def test_track_query_is_free_text(self, plugin):
query, filters = plugin.get_search_query_with_filters(
"track", [Item()], "Artist", "Title", False
)

assert query == "Title Artist"
assert filters == {}

def test_track_query_tolerates_missing_artist(self, plugin):
query, _ = plugin.get_search_query_with_filters(
"track", [Item()], "", "Title", False
)

assert query == "Title"

def test_album_query_filters_on_album_and_artist(self, plugin):
query, filters = plugin.get_search_query_with_filters(
"album", [Item()], "Artist", "Album", False
)

assert query == 'album:"Album" artist:"Artist"'
assert filters == {}

def test_album_query_omits_artist_for_various_artists(self, plugin):
query, _ = plugin.get_search_query_with_filters(
"album", [Item()], "Various Artists", "Album", True
)

assert query == 'album:"Album"'
Loading