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
```
This commit is contained in:
Šarūnas Nejus 2025-09-27 13:34:20 +01:00 committed by GitHub
commit bc9d34ed98
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 7 deletions

View file

@ -412,7 +412,7 @@ class SearchApiMetadataSourcePlugin(
:return: Query string to be provided to the search API.
"""
components = [query_string, *(f'{k}:"{v}"' for k, v in filters.items())]
components = [query_string, *(f"{k}:'{v}'" for k, v in filters.items())]
query = " ".join(filter(None, components))
if self.config["search_query_ascii"].get():

View file

@ -27,6 +27,8 @@ Bug fixes:
matching. :bug:`5189`
- :doc:`plugins/discogs` Fixed inconsistency in stripping disambiguation from
artists but not labels. :bug:`5366`
- :doc:`plugins/spotify` Fixed an issue where candidate lookup would not find
matches due to query escaping (single vs double quotes).
For packagers:

View file

@ -82,8 +82,8 @@ class SpotifyPluginTest(PluginTestCase):
params = _params(responses.calls[0].request.url)
query = params["q"][0]
assert "duifhjslkef" in query
assert 'artist:"ujydfsuihse"' in query
assert 'album:"lkajsdflakjsd"' in query
assert "artist:'ujydfsuihse'" in query
assert "album:'lkajsdflakjsd'" in query
assert params["type"] == ["track"]
@responses.activate
@ -117,8 +117,8 @@ class SpotifyPluginTest(PluginTestCase):
params = _params(responses.calls[0].request.url)
query = params["q"][0]
assert "Happy" in query
assert 'artist:"Pharrell Williams"' in query
assert 'album:"Despicable Me 2"' in query
assert "artist:'Pharrell Williams'" in query
assert "album:'Despicable Me 2'" in query
assert params["type"] == ["track"]
@responses.activate
@ -233,8 +233,8 @@ class SpotifyPluginTest(PluginTestCase):
params = _params(responses.calls[0].request.url)
query = params["q"][0]
assert item.title in query
assert f'artist:"{item.albumartist}"' in query
assert f'album:"{item.album}"' in query
assert f"artist:'{item.albumartist}'" in query
assert f"album:'{item.album}'" in query
assert not query.isascii()
# Is not found in the library if ascii encoding is enabled