youtube: Use a different Invidious instance
authorJoseph Nuthalapati <njoseph@riseup.net>
Sun, 14 Mar 2021 11:19:42 +0000 (16:49 +0530)
committerJoseph Nuthalapati <njoseph@riseup.net>
Sun, 14 Mar 2021 11:19:42 +0000 (16:49 +0530)
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
src/config.nim
src/youtube.nim

index 06ebd63e86218b5ae5d012e505de8b76bec35daf..aa6afd9981182191a7f5c6a65f818555d5c63997 100644 (file)
@@ -20,7 +20,7 @@ let rewriteInvidiousURLs* = true
 # Invidious instance for querying
 # This instance should have a valid public API
 # Check like this: curl https://invidious.xyz/api/v1/search\?q\=cats
-let invidiousInstance* = "https://invidious.kavin.rocks"
+let invidiousInstance* = "https://invidious.tube"
 
 discard """"
 Configuration goes through three levels of overrides:
index a83e23372fb21b6e66822648812bf60ef062aacf..a07a629f36cb04a39b67121d7c3ee31bd82f4115 100644 (file)
@@ -1,6 +1,7 @@
 import
   httpClient,
   json,
+  std/[terminal],
   strformat,
   strutils,
   uri
@@ -26,6 +27,12 @@ proc getSearchResults*(searchQuery: string): SearchResults =
   let client = newHttpClient()
   let response = get(client, &"{invidiousInstance}/api/v1/search?q={queryParam}")
   let jsonData = parseJson($response.body)
+  if jsonData.kind == JObject: # Could be a 403 error
+    stdout.styledWrite(fgRed, $response.body)
+    quit(1)
+  if len(jsonData) == 0:
+    stdout.styledWrite(fgRed, "Got empty response from Invidious instance")
+    quit(2)
   var searchResults: SearchResults = @[]
   for item in jsonData:
     if item["type"].getStr() == "video":