From de651c40ebd05f8001e4c344b36414e2ffaf4e5f Mon Sep 17 00:00:00 2001 From: fischcode <82546407+fischcode@users.noreply.github.com> Date: Sun, 21 Jan 2024 19:06:38 +0100 Subject: [PATCH] handle playlists appearing in top results (closes #524) (#526) * handle playlists appearing in top results #524 parse playlists appearing in top results returning results the same way as for other playlists found be search() * fixup, add test --------- Co-authored-by: sigma67 --- tests/mixins/test_search.py | 7 +++++++ ytmusicapi/parsers/search.py | 5 +++++ 2 files changed, 12 insertions(+) diff --git a/tests/mixins/test_search.py b/tests/mixins/test_search.py index 1d2b7dd..1587399 100644 --- a/tests/mixins/test_search.py +++ b/tests/mixins/test_search.py @@ -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( diff --git a/ytmusicapi/parsers/search.py b/ytmusicapi/parsers/search.py index d831be7..fa1cb00 100644 --- a/ytmusicapi/parsers/search.py +++ b/ytmusicapi/parsers/search.py @@ -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