From c7ba399dd1057021f6e7344511705ede6955fa28 Mon Sep 17 00:00:00 2001 From: Sebastian Mohr Date: Mon, 15 Sep 2025 23:32:04 +0200 Subject: [PATCH] fix incorrect matches when album is missing or empty closes #5189 --- beets/metadata_plugins.py | 4 +++- beetsplug/spotify.py | 8 +++++++- docs/changelog.rst | 5 +++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/beets/metadata_plugins.py b/beets/metadata_plugins.py index 381881b51..6a75d0f79 100644 --- a/beets/metadata_plugins.py +++ b/beets/metadata_plugins.py @@ -371,7 +371,9 @@ class SearchApiMetadataSourcePlugin( album: str, va_likely: bool, ) -> Iterable[AlbumInfo]: - query_filters: SearchFilter = {"album": album} + query_filters: SearchFilter = {} + if album: + query_filters["album"] = album if not va_likely: query_filters["artist"] = artist diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index a0a5c4358..e97484bc1 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -569,7 +569,13 @@ class SpotifyPlugin( query_string = item[self.config["track_field"].get()] # Query the Web API for each track, look for the items' JSON data - query_filters: SearchFilter = {"artist": artist, "album": album} + + query_filters: SearchFilter = {} + if artist: + query_filters["artist"] = artist + if album: + query_filters["album"] = album + response_data_tracks = self._search_api( query_type="track", query_string=query_string, diff --git a/docs/changelog.rst b/docs/changelog.rst index 67c284a88..f4ac99d27 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -11,6 +11,11 @@ New features: Bug fixes: +- :doc:`plugins/spotify` Fixed an issue where track matching and lookups could + return incorrect or misleading results when using the Spotify plugin. The + problem occurred primarily when no album was provided or when the album field + was an empty string. :bug:`5189` + For packagers: Other changes: