Skip to content

Commit b525d4c

Browse files
committed
Fixed issues where empty strings would break the search api of various
metadata plugins.
1 parent 475f225 commit b525d4c

File tree

5 files changed

+54
-5
lines changed

5 files changed

+54
-5
lines changed

beetsplug/beatport.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,16 @@ def _get_releases(self, query: str) -> Iterator[AlbumInfo]:
457457
# Strip medium information from query, Things like "CD1" and "disk 1"
458458
# can also negate an otherwise positive result.
459459
query = re.sub(r"\b(CD|disc)\s*\d+", "", query, flags=re.I)
460+
461+
# query may be empty strings
462+
# We want to skip the lookup in this case.
463+
if not query.strip():
464+
self._log.debug(
465+
"Empty search query after preprocessing, skipping {.data_source}.",
466+
self,
467+
)
468+
return
469+
460470
for beatport_release in self.client.search(query, "release"):
461471
if beatport_release is None:
462472
continue
@@ -522,8 +532,18 @@ def _get_artist(self, artists):
522532
"""
523533
return self.get_artist(artists=artists, id_key=0, name_key=1)
524534

525-
def _get_tracks(self, query):
535+
def _get_tracks(self, query: str):
526536
"""Returns a list of TrackInfo objects for a Beatport query."""
537+
538+
# query may be empty strings
539+
# We want to skip the lookup in this case.
540+
if not query.strip():
541+
self._log.debug(
542+
"Empty search query after preprocessing, skipping {.data_source}.",
543+
self,
544+
)
545+
return []
546+
527547
bp_tracks = self.client.search(query, release_type="track")
528548
tracks = [self._get_track_info(x) for x in bp_tracks]
529549
return tracks

beetsplug/discogs.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,10 @@ def get_track_from_album(
231231
return track_info
232232

233233
def item_candidates(
234-
self, item: Item, artist: str, title: str
234+
self,
235+
item: Item,
236+
artist: str,
237+
title: str,
235238
) -> Iterable[TrackInfo]:
236239
albums = self.candidates([item], artist, title, False)
237240

@@ -291,6 +294,15 @@ def get_albums(self, query: str) -> Iterable[AlbumInfo]:
291294
# can also negate an otherwise positive result.
292295
query = re.sub(r"(?i)\b(CD|disc|vinyl)\s*\d+", "", query)
293296

297+
# query may be empty strings
298+
# We want to skip the lookup in this case.
299+
if not query.strip():
300+
self._log.debug(
301+
"Empty search query after preprocessing, skipping {.data_source}.",
302+
self,
303+
)
304+
return []
305+
294306
try:
295307
results = self.discogs_client.search(query, type="release")
296308
results.per_page = self.config["search_limit"].get()

beetsplug/musicbrainz.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,11 @@ def _search_api(
807807
self._log.debug(
808808
"Searching for MusicBrainz {}s with: {!r}", query_type, filters
809809
)
810+
811+
if not filters:
812+
self._log.debug("No valid filters provided, skipping search.")
813+
return []
814+
810815
try:
811816
method = getattr(musicbrainzngs, f"search_{query_type}s")
812817
res = method(limit=self.config["search_limit"].get(), **filters)

beetsplug/spotify.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,13 @@ def _search_api(
434434
filters=filters, query_string=query_string
435435
)
436436

437+
if not query.strip():
438+
self._log.debug(
439+
"Empty search query after applying filters, skipping {.data_source}.",
440+
self,
441+
)
442+
return []
443+
437444
self._log.debug("Searching {.data_source} for '{}'", self, query)
438445
try:
439446
response = self._handle_response(

docs/changelog.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@ New features:
1515

1616
Bug fixes:
1717

18+
- :doc:`plugins/discogs`, :doc:`plugins/beatport`, :doc:`plugins/spotify`,
19+
:doc:`plugins/musicbrainz`: Fix an issue where no metadata in a file would
20+
crash the import process :bug:`6060`
21+
1822
For packagers:
1923

2024
Other changes:
2125

22-
- Standardized ``search_*`` parameter handling in autotag matchers. Manual album and
23-
singleton searches now behave consistently: when the prompt does not specify a
24-
search query, the system defaults to using the corresponding metadata value.
26+
- Standardized ``search_*`` parameter handling in autotag matchers. Manual album
27+
and singleton searches now behave consistently: when the prompt does not
28+
specify a search query, the system defaults to using the corresponding
29+
metadata value.
2530

2631
2.5.1 (October 14, 2025)
2732
------------------------

0 commit comments

Comments
 (0)