From c8812b680092eea171bcbd3a0c025467031b74e2 Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Sat, 11 Jan 2020 00:33:00 +0530 Subject: [PATCH] Introduce a func Signed-off-by: Joseph Nuthalapati --- nimcoon.nim | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) 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() -- 2.43.0