-proc getYoutubePage(searchQuery: string): string =
- let queryParam = encodeUrl(searchQuery)
- let client = newHttpClient()
- 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").
- 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)]
-
-proc presentVideoOptions(searchResults: seq[SearchResult]) =
- echo ""
- for index, (title, url) in searchResults:
- styledEcho $index, ". ", styleBright, fgMagenta, title, "\n", resetStyle, fgCyan, url, "\n"
-
-proc play(player: string, args: openArray[string]) =
- discard execProcess(player, args=args, options={poStdErrToStdOut, poUsePath, poEchoCmd})
- quit(0)
-
-proc directPlay(searchQuery: string, player: string) =
- if "watch?" in searchQuery or "videos/watch" in searchQuery:
- play(player, args=[searchQuery])
- elif searchQuery.startswith("magnet:"):
- play("peerflix", args=[searchQuery, &"--{player}"])
-