]> njoseph.me Git - nimcoon.git/blobdiff - lib.nim
Continuously keep playing till I press "q"
[nimcoon.git] / lib.nim
diff --git a/lib.nim b/lib.nim
index fc00385307c1f5ac1e177a2a8a6f41a8e3410446..acc4fc12dd33d46cfb13a905a6f54c28f1fd83ed 100644 (file)
--- a/lib.nim
+++ b/lib.nim
@@ -31,10 +31,11 @@ proc getYoutubePage*(searchQuery: string): string =
   let response = get(client, &"https://www.youtube.com/results?hl=en&search_query={queryParam}")
   return $response.body
 
-proc extractTitlesAndUrls*(html: string): seq[SearchResult] =
-  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"]))[..(limit-1)]
+func extractTitlesAndUrls*(html: string): seq[SearchResult] =
+  {.noSideEffect.}:
+    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"]))[..(limit-1)]
 
 proc presentVideoOptions*(searchResults: seq[SearchResult]) =
   echo ""
@@ -44,7 +45,6 @@ proc presentVideoOptions*(searchResults: seq[SearchResult]) =
 proc play*(player: string, args: openArray[string]) =
   # poEchoCmd can be added to options for debugging
   discard execProcess(player, args=args, options={poStdErrToStdOut, poUsePath})
-  quit(0)
 
 func urlLongen(url: string): string =
   url.replace("youtu.be/", "www.youtube.com/watch?v=")