From: Joseph Nuthalapati Date: Tue, 18 Feb 2020 15:45:57 +0000 (+0530) Subject: Add option to play "all" the search results X-Git-Tag: 0.1.0~12 X-Git-Url: http://njoseph.me/gitweb/nimcoon.git/commitdiff_plain/72720bec46a37176476c4bb6bc0cb83c0488cbed Add option to play "all" the search results Signed-off-by: Joseph Nuthalapati --- diff --git a/lib.nim b/lib.nim index acc4fc1..893422e 100644 --- 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 "" diff --git a/nimcoon.nim b/nimcoon.nim index ae22576..ed3a572 100644 --- a/nimcoon.nim +++ b/nimcoon.nim @@ -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