-
Notifications
You must be signed in to change notification settings - Fork 2.1k
tidal: respect search_limit config option in candidates() #6781
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
Open
kveni12
wants to merge
6
commits into
beetbox:master
Choose a base branch
from
kveni12:fix/tidal-search-limit
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b9e56fc
tidal: respect search_limit config option in candidates()
kveni12 0e80c5d
docs: add changelog entry for tidal search_limit fix (#6770)
kveni12 7613c3b
tidal: apply search_limit via round-robin early-break in candidates()
kveni12 4c0779d
tidal: fix lint, formatting, and mypy errors
kveni12 a69276f
tidal: simplify search_limit handling with itertools
kveni12 c33a520
tidal: fix mypy errors in interleaved search results
kveni12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,10 @@ def api(self) -> TidalAPI: | |
| token_path=self._tokenfile(), | ||
| ) | ||
|
|
||
| @cached_property | ||
| def search_limit(self) -> int: | ||
| return self.config["search_limit"].get(int) | ||
|
|
||
| def _tokenfile(self) -> str: | ||
| """Return the configured path to the token file in the app directory.""" | ||
| return self.config["tokenfile"].get(confuse.Filename(in_app_dir=True)) | ||
|
|
@@ -114,7 +118,6 @@ def tracks_for_ids(self, ids: Iterable[str]) -> Iterable[TrackInfo | None]: | |
| def candidates( | ||
| self, items: Sequence[Item], artist: str, album: str, va_likely: bool | ||
| ) -> Iterable[AlbumInfo]: | ||
| candidates: list[AlbumInfo] = [] | ||
| # Tidal allows to lookup via isrc and barcode (nice!) | ||
| # We just return early here as a lookup via isrc should | ||
| # return a 100% match | ||
|
|
@@ -128,16 +131,31 @@ def candidates( | |
| ): | ||
| return candidates | ||
|
|
||
| for query in self._album_queries(items): | ||
| candidates += self.search_albums_by_query(query) | ||
| candidates = list( | ||
| itertools.islice( | ||
| ( | ||
| candidate | ||
| for candidate in itertools.chain.from_iterable( | ||
| itertools.zip_longest( | ||
| *( | ||
| self.search_albums_by_query(query) | ||
| for query in self._album_queries(items) | ||
| ), | ||
| fillvalue=None, | ||
| ) | ||
| ) | ||
| if candidate is not None | ||
| ), | ||
| self.search_limit, | ||
| ) | ||
| ) | ||
|
|
||
| log.debug("Found {0} candidates", len(candidates)) | ||
| return candidates | ||
|
|
||
| def item_candidates( | ||
| self, item: Item, artist: str, title: str | ||
| ) -> Iterable[TrackInfo]: | ||
| candidates: list[TrackInfo] = [] | ||
| # Tidal allows to lookup via isrc and barcode (nice!) | ||
| # We just return early here as a lookup via isrc should | ||
| # return a 100% match | ||
|
|
@@ -147,8 +165,24 @@ def item_candidates( | |
| ): | ||
| return candidates | ||
|
|
||
| for query in self._item_queries(item): | ||
| candidates += self.search_tracks_by_query(query) | ||
| candidates = list( | ||
|
Contributor
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. Lets make the round robin logic a helper function. Should make the flow here more readable and should allow to dedupe some code. |
||
| itertools.islice( | ||
| ( | ||
| candidate | ||
| for candidate in itertools.chain.from_iterable( | ||
| itertools.zip_longest( | ||
| *( | ||
| self.search_tracks_by_query(query) | ||
| for query in self._item_queries(item) | ||
| ), | ||
| fillvalue=None, | ||
| ) | ||
| ) | ||
| if candidate is not None | ||
| ), | ||
| self.search_limit, | ||
| ) | ||
| ) | ||
|
|
||
| log.debug("Found {0} candidates", len(candidates)) | ||
| return candidates | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is
zip_longesthere for? Also, you can usefilter(None, ...instead of checking forNonevalues.