Introduce a func

Signed-off-by: Joseph Nuthalapati's avatarJoseph Nuthalapati <[email protected]>
parent 46817cb7
Pipeline #108491569 passed with stage
in 1 minute
......@@ -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()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment