Skip to content

Commit bc9d34e

Browse files
authored
Fix for Spotify Candidate Lookup. Changed query from double to single quotes. (#6049)
I noticed that spotify did not return any candidates for some of my examples, but adding the search id manually would give a very good match. I debugged it a bit and it seems like spotify does not like double quotes we used for the search query. Using single quotes fixed it for me. Note that this does not seem to be documented in the [spotify api documentation](https://developer.spotify.com/documentation/web-api/reference/search) The example I used: ``` # Query with double quotes, which does not return any candidates # Searching Spotify for 'album:"Flamethrower" artist:"Circadian, Cody Frost"' https://api.spotify.com/v1/search?offset=0&limit=50&query=album%3A%22Flamethrower%22%20artist%3A%22Circadian%2C%20Cody%20Frost%22&type=album # New Query # Searching Spotify for 'album:'Flamethrower' artist:'Circadian, Cody Frost'' https://api.spotify.com/v1/search?offset=0&limit=5&query=album%3A%27Flamethrower%27%20artist%3A%27Circadian%2C%20Cody%20Frost%27&type=album ```
2 parents 64c94f6 + cc0024e commit bc9d34e

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

beets/metadata_plugins.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def _construct_search_query(
412412
:return: Query string to be provided to the search API.
413413
"""
414414

415-
components = [query_string, *(f'{k}:"{v}"' for k, v in filters.items())]
415+
components = [query_string, *(f"{k}:'{v}'" for k, v in filters.items())]
416416
query = " ".join(filter(None, components))
417417

418418
if self.config["search_query_ascii"].get():

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Bug fixes:
2727
matching. :bug:`5189`
2828
- :doc:`plugins/discogs` Fixed inconsistency in stripping disambiguation from
2929
artists but not labels. :bug:`5366`
30+
- :doc:`plugins/spotify` Fixed an issue where candidate lookup would not find
31+
matches due to query escaping (single vs double quotes).
3032

3133
For packagers:
3234

test/plugins/test_spotify.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ def test_missing_request(self):
8282
params = _params(responses.calls[0].request.url)
8383
query = params["q"][0]
8484
assert "duifhjslkef" in query
85-
assert 'artist:"ujydfsuihse"' in query
86-
assert 'album:"lkajsdflakjsd"' in query
85+
assert "artist:'ujydfsuihse'" in query
86+
assert "album:'lkajsdflakjsd'" in query
8787
assert params["type"] == ["track"]
8888

8989
@responses.activate
@@ -117,8 +117,8 @@ def test_track_request(self):
117117
params = _params(responses.calls[0].request.url)
118118
query = params["q"][0]
119119
assert "Happy" in query
120-
assert 'artist:"Pharrell Williams"' in query
121-
assert 'album:"Despicable Me 2"' in query
120+
assert "artist:'Pharrell Williams'" in query
121+
assert "album:'Despicable Me 2'" in query
122122
assert params["type"] == ["track"]
123123

124124
@responses.activate
@@ -233,8 +233,8 @@ def test_japanese_track(self):
233233
params = _params(responses.calls[0].request.url)
234234
query = params["q"][0]
235235
assert item.title in query
236-
assert f'artist:"{item.albumartist}"' in query
237-
assert f'album:"{item.album}"' in query
236+
assert f"artist:'{item.albumartist}'" in query
237+
assert f"album:'{item.album}'" in query
238238
assert not query.isascii()
239239

240240
# Is not found in the library if ascii encoding is enabled

0 commit comments

Comments
 (0)