-
Notifications
You must be signed in to change notification settings - Fork 2k
Empty metadata support for autotagger plugins #6065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
a27cf64
e5d5ce1
a280237
ddca7c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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(): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we define a helper method in ...
def is_query_empty(query: str) -> bool:
if not query.strip():
self._log.debug(
"Empty search query after preprocessing, skipping {.data_source}.",
self,
)
return True
return Falseand then have if self.is_query_empty(query):
return []here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In theory we could add We can although add a helper function to the
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand the concern about interface segregation, but looking at the alternative, I strongly disagree that If we move this validation there, we force every metadata source plugin to import from a module that is currently a "junk drawer" of unrelated concerns. Forcing plugins to depend on that chaotic module just to perform a simple string check is a much stronger violation of separation of concerns than adding a single protected helper method to the base class they already inherit from.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The core issue for me is that not every metadata plugin actually needs this helper. If all metadata sources depended on it, then abstracting it into core would make sense. But that’s not the case thus I’m hesitant to add it to the main interface. Interfaces should define the minimal, common contract, not accumulate convenience helpers that only some implementations need.
At the moment, I completely understand the motivation here, having shared helpers in a common namespace often does feel like the right direction. However, in this case, adding common functions directly to the interface risks muddying the separation between the plugin layer and the core layer. For me that separation has been a conscious design goal with the split into |
||
| 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -231,7 +231,10 @@ def get_track_from_album( | |
| return track_info | ||
|
|
||
| def item_candidates( | ||
| self, item: Item, artist: str, title: str | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing seems to have changed in this line. Re your own comment: #6184 (comment) |
||
| self, | ||
| item: Item, | ||
| artist: str, | ||
| title: str, | ||
| ) -> Iterable[TrackInfo]: | ||
| albums = self.candidates([item], artist, title, False) | ||
|
|
||
|
|
@@ -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(): | ||
snejus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.