+proc getSearchResults*(searchQuery: string): SearchResults =
+ # Using Invidious API to retrieve the search results but playing the results directly from YouTube.
+ let queryParam = encodeUrl(searchQuery)
+ let client = newHttpClient()
+ let response = get(client, &"{invidiousInstance}/api/v1/search?q={queryParam}")
+ let jsonData = parseJson($response.body)
+ var searchResults: SearchResults = @[]
+ for item in jsonData:
+ if item["type"].getStr() == "video":
+ searchResults.add((item["title"].getStr(), makeUrl(item["videoId"].getStr())))
+ elif item["type"].getStr() == "playlist":
+ searchResults.add((item["title"].getStr(), makeUrl(item["playlistId"].getStr())))
+ # Not handling type = channel for now