]> njoseph.me Git - nimcoon.git/commitdiff
Use Invidio.us to retrieve search results
authorJoseph Nuthalapati <njoseph@riseup.net>
Thu, 2 Jul 2020 04:01:04 +0000 (09:31 +0530)
committerJoseph Nuthalapati <njoseph@riseup.net>
Thu, 2 Jul 2020 04:01:04 +0000 (09:31 +0530)
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
src/lib.nim

index 30334588040993ba0a5c1d5fb900048ad855205c..a259d18834adcf060907cf5a307279b0ee2e5329 100644 (file)
@@ -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) =