From 9dc65252a5863bef63683a4e61ed813960cb65b8 Mon Sep 17 00:00:00 2001 From: Tom Bulled <26026015+tombulled@users.noreply.github.com> Date: Mon, 13 Nov 2023 20:21:09 +0000 Subject: [PATCH] :sparkles: [#47] Add example for filtering a search using params (#62) --- examples/filter-search.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 examples/filter-search.py diff --git a/examples/filter-search.py b/examples/filter-search.py new file mode 100644 index 0000000..5e4eaf7 --- /dev/null +++ b/examples/filter-search.py @@ -0,0 +1,23 @@ +from innertube import InnerTube + +PARAMS_TYPE_VIDEO = "EgIQAQ%3D%3D" +PARAMS_TYPE_CHANNEL = "EgIQAg%3D%3D" +PARAMS_TYPE_PLAYLIST = "EgIQAw%3D%3D" +PARAMS_TYPE_FILM = "EgIQBA%3D%3D" + +client = InnerTube("WEB", "2.20230920.00.00") + +data = client.search("arctic monkeys", params=PARAMS_TYPE_PLAYLIST) + +items = data["contents"]["twoColumnSearchResultsRenderer"]["primaryContents"][ + "sectionListRenderer" +]["contents"][0]["itemSectionRenderer"]["contents"] + +for item in items: + playlist = item["playlistRenderer"] + + playlist_id = playlist["playlistId"] + playlist_title = playlist["title"]["simpleText"] + playlist_video_count = playlist["videoCount"] + + print(f"[{playlist_id}] {playlist_title} ({playlist_video_count} videos)")