-
- for video in videos:
- if video.hasKey("videoRenderer"):
- let title = ($video["videoRenderer"]["title"]["runs"][0]["text"]).strip(chars={'"'})
- let videoId = ($video["videoRenderer"]["videoId"]).strip(chars={'"'})
- let videoUrl = &"https://www.youtube.com/watch?v={videoId}"
- searchResults.add((title, videoUrl))
-
- elif video.hasKey("playlistRenderer"):
- let title = ($video["playlistRenderer"]["title"]["simpleText"]).strip(chars={'"'})
- let playlistId = ($video["playlistRenderer"]["playlistId"]).strip(chars={'"'})
- let playlistUrl = &"https://www.youtube.com/playlist?list={playlistId}"
- searchResults.add((title, playlistUrl))
-
+ for item in jsonData:
+ if item["type"].getStr() == "video":
+ searchResults.add((item["title"].getStr(), "https://www.youtube.com/watch?v=" & item["videoId"].getStr()))
+ elif item["type"].getStr() == "playlist":
+ searchResults.add((item["title"].getStr(), "https://www.youtube.com/watch?v=" & item["playlistId"].getStr()))
+ # Not handling type = channel for now