]> njoseph.me Git - nimcoon.git/commitdiff
Add option to play "all" the search results
authorJoseph Nuthalapati <njoseph@riseup.net>
Tue, 18 Feb 2020 15:45:57 +0000 (21:15 +0530)
committerJoseph Nuthalapati <njoseph@riseup.net>
Tue, 18 Feb 2020 15:45:57 +0000 (21:15 +0530)
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
lib.nim
nimcoon.nim

diff --git a/lib.nim b/lib.nim
index acc4fc12dd33d46cfb13a905a6f54c28f1fd83ed..893422ecec8138285d2ea1051f28b8ed6f468a30 100644 (file)
--- a/lib.nim
+++ b/lib.nim
@@ -35,7 +35,7 @@ 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)]
+      map(a => (a.attrs["title"], "https://www.youtube.com" & a.attrs["href"]))
 
 proc presentVideoOptions*(searchResults: seq[SearchResult]) =
   echo ""
index ae22576213d2131ac10982ef17158c24a54e7346..ed3a572d2d596ced7b0fde6b524db3bf9783029b 100644 (file)
@@ -3,6 +3,7 @@ import
   std/[terminal],
   strutils
 
+import config
 import lib
 
 proc parseOptions(): CommandLineOptions =
@@ -40,7 +41,7 @@ proc main() =
   proc getUserInput(): string =
     if feelingLucky: "0"
     else:
-      presentVideoOptions(searchResults)
+      presentVideoOptions(searchResults[..(limit-1)])
       stdout.styledWrite(fgYellow, "Choose video number: ")
       readLine(stdin)
 
@@ -53,6 +54,11 @@ proc main() =
 
   while(true):
     let userInput = getUserInput()
+
+    if userInput == "all":
+      for number in 0..(len(searchResults)):
+        play(player, buildArgs(number))
+
     if userInput == "q":
       break