X-Git-Url: https://njoseph.me/gitweb/nimcoon.git/blobdiff_plain/aaeaf00b0276e4eee8355c223ca668be7dfe2ee0..c8812b680092eea171bcbd3a0c025467031b74e2:/nimcoon.nim diff --git a/nimcoon.nim b/nimcoon.nim index f47b249..7b69ddb 100644 --- a/nimcoon.nim +++ b/nimcoon.nim @@ -9,7 +9,6 @@ import std/[terminal], strtabs, strutils, - tables, uri, xmltree @@ -54,8 +53,8 @@ proc getYoutubePage(searchQuery: string): string = let response = get(client, &"https://www.youtube.com/results?hl=en&search_query={queryParam}") return $response.body -proc extractTitlesAndUrls(htmlFile: string): seq[SearchResult] = - parseHtml(htmlFile).findAll("a"). +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)] @@ -93,15 +92,14 @@ proc main() = styledEcho "\n", fgGreen, "Playing ", styleBright, fgMagenta, searchResults[number].title - var args = @[searchResults[number].url] - - if musicOnly: - args.add(playerOptions[player]["musicOnly"]) - - if fullScreen: - args.add(playerOptions[player]["fullScreen"]) + # This is a pure function with no side effects + func buildArgs(): seq[string] = + var args = @[searchResults[number].url] + if musicOnly: args.add("--no-video") + if fullScreen: args.add("--fullscreen") + return args # Play the video using the preferred/available media player - play(player, args) + play(player, buildArgs()) main()