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
22 changes: 21 additions & 1 deletion beetsplug/beatport.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,16 @@ def _get_releases(self, query: str) -> Iterator[AlbumInfo]:
# Strip medium information from query, Things like "CD1" and "disk 1"
# can also negate an otherwise positive result.
query = re.sub(r"\b(CD|disc)\s*\d+", "", query, flags=re.I)

# query may be empty strings
# We want to skip the lookup in this case.
if not query.strip():
self._log.debug(
"Empty search query after preprocessing, skipping {.data_source}.",
self,
)
return

for beatport_release in self.client.search(query, "release"):
if beatport_release is None:
continue
Expand Down Expand Up @@ -522,8 +532,18 @@ def _get_artist(self, artists):
"""
return self.get_artist(artists=artists, id_key=0, name_key=1)

def _get_tracks(self, query):
def _get_tracks(self, query: str):
"""Returns a list of TrackInfo objects for a Beatport query."""

# query may be empty strings
# We want to skip the lookup in this case.
if not query.strip():
self._log.debug(
"Empty search query after preprocessing, skipping {.data_source}.",
self,
)
return []

bp_tracks = self.client.search(query, release_type="track")
tracks = [self._get_track_info(x) for x in bp_tracks]
return tracks
14 changes: 13 additions & 1 deletion beetsplug/discogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@ def get_track_from_album(
return track_info

def item_candidates(
self, item: Item, artist: str, title: str
self,
item: Item,
artist: str,
title: str,
) -> Iterable[TrackInfo]:
albums = self.candidates([item], artist, title, False)

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

# query may be empty strings
# We want to skip the lookup in this case.
if not query.strip():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this logic being duplicated in every data source. Can we not check this in plugins.item_candidates?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can't move this logic easily. Some metadataplugins do not require artist or title/album at all. We can't move the check one layer up as this would break plugins only depending on item.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this logic is present in all internal plugins. I also don't see a use case in beetcamp where both artist and title / album are missing - I think we can safely handle this one layer up and remove the duplication.

When does fromfilename plugin intercept these parameters and insert data from the filename?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have a look at chroma.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completely forgot about this one 😞

self._log.debug(
"Empty search query after preprocessing, skipping {.data_source}.",
self,
)
return []

try:
results = self.discogs_client.search(query, type="release")
results.per_page = self.config["search_limit"].get()
Expand Down
5 changes: 5 additions & 0 deletions beetsplug/musicbrainz.py
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,11 @@ def _search_api(
self._log.debug(
"Searching for MusicBrainz {}s with: {!r}", query_type, filters
)

if not filters:
self._log.debug("No valid filters provided, skipping search.")
return []

try:
method = getattr(musicbrainzngs, f"search_{query_type}s")
res = method(limit=self.config["search_limit"].get(), **filters)
Expand Down
7 changes: 7 additions & 0 deletions beetsplug/spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,13 @@ def _search_api(
filters=filters, query_string=query_string
)

if not query.strip():
self._log.debug(
"Empty search query after applying filters, skipping {.data_source}.",
self,
)
return []

self._log.debug("Searching {.data_source} for '{}'", self, query)
try:
response = self._handle_response(
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ New features:

Bug fixes:

- :doc:`plugins/discogs`, :doc:`plugins/beatport`, :doc:`plugins/spotify`,
:doc:`plugins/musicbrainz`: Fix an issue where no metadata in a file would
crash the import process :bug:`6060`

For packagers:

Other changes:
Expand Down