From: Joseph Nuthalapati Date: Fri, 10 Jan 2020 19:03:00 +0000 (+0530) Subject: Introduce a func X-Git-Tag: 0.1.0~22 X-Git-Url: https://njoseph.me/gitweb/nimcoon.git/commitdiff_plain/c8812b680092eea171bcbd3a0c025467031b74e2?hp=46817cb7cbd9bd6b24e92ed9e292c62ce20d20ac Introduce a func Signed-off-by: Joseph Nuthalapati --- diff --git a/nimcoon.nim b/nimcoon.nim index cea1797..7b69ddb 100644 --- a/nimcoon.nim +++ b/nimcoon.nim @@ -53,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)] @@ -92,15 +92,14 @@ proc main() = styledEcho "\n", fgGreen, "Playing ", styleBright, fgMagenta, searchResults[number].title - var args = @[searchResults[number].url] - - if musicOnly: - args.add("--no-video") - - if fullScreen: - args.add("--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()