]> njoseph.me Git - nimcoon.git/commitdiff
Make extractTitlesAndUrls a func
authorJoseph Nuthalapati <njoseph@riseup.net>
Sun, 12 Jan 2020 07:53:05 +0000 (13:23 +0530)
committerJoseph Nuthalapati <njoseph@riseup.net>
Sun, 12 Jan 2020 07:53:05 +0000 (13:23 +0530)
with some convincing of course!

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
lib.nim

diff --git a/lib.nim b/lib.nim
index fc00385307c1f5ac1e177a2a8a6f41a8e3410446..de088b403d679784de4b993e0a828af2917434bc 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 ""