From 30843c18209ae8c6b6d3641668ab6a972e5feb5d Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Thu, 2 Jul 2020 09:31:04 +0530 Subject: [PATCH] Use Invidio.us to retrieve search results Signed-off-by: Joseph Nuthalapati --- src/lib.nim | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.nim b/src/lib.nim index 3033458..a259d18 100644 --- a/src/lib.nim +++ b/src/lib.nim @@ -8,7 +8,6 @@ import sequtils, std/[terminal], strformat, - strformat, strtabs, strutils, sugar, @@ -48,7 +47,7 @@ proc selectMediaPlayer*(): string = proc getYoutubePage*(searchQuery: string): string = let queryParam = encodeUrl(searchQuery) let client = newHttpClient() - let response = get(client, &"https://www.youtube.com/results?hl=en&search_query={queryParam}") + let response = get(client, &"https://invidio.us/search?q={queryParam}") $response.body @@ -65,9 +64,10 @@ proc getPeerTubeMagnetLink(url: string): string = func extractTitlesAndUrls*(html: string): SearchResults = {.noSideEffect.}: + # TODO Pick an invidious instance from config. Using YouTube directly for now. parseHtml(html).findAll("a"). - filter(a => "watch" in a.attrs["href"] and a.attrs.hasKey "title"). - map(a => (a.attrs["title"], "https://www.youtube.com" & a.attrs["href"])) + filter(a => "watch" in a.attrs["href"] and len(a) == 1). + map(a => (innerText(a), "https://www.youtube.com" & a.attrs["href"])) proc presentVideoOptions*(searchResults: SearchResults) = -- 2.43.0