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)]
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()