Skip to content
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

handle playlists appearing in top results (closes #524) #526

Merged
merged 2 commits into from
Jan 21, 2024
Merged
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
7 changes: 7 additions & 0 deletions tests/mixins/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ def test_search_filters(self, yt_auth):
assert len(results) > 10
assert all(item["resultType"] == "episode" for item in results)

def test_search_top_result(self, yt):
results = yt.search("fdsfsfsd") # issue 524
assert results[0]["category"] == "Top result"
assert results[0]["resultType"] == "playlist"
assert results[0]["playlistId"] == "PLK3q5XTYSK60QH3gDypSu3n9OBz6H9HfV"
assert len(results[0]["author"]) > 0

def test_search_uploads(self, config, yt, yt_oauth):
with pytest.raises(Exception, match="No filter can be set when searching uploads"):
yt.search(
Expand Down
5 changes: 5 additions & 0 deletions ytmusicapi/parsers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ def parse_top_result(data, search_result_types):
if result_type in ["album"]:
search_result["browseId"] = nav(data, TITLE + NAVIGATION_BROWSE_ID, True)

if result_type in ["playlist"]:
search_result["playlistId"] = nav(data, MENU_PLAYLIST_ID)
search_result["title"] = nav(data, TITLE_TEXT)
search_result["author"] = parse_song_artists_runs(nav(data, ["subtitle", "runs"])[2:])

search_result["thumbnails"] = nav(data, THUMBNAILS, True)
return search_result

Expand Down
Loading