sequtils,
std/[terminal],
strformat,
- strformat,
strtabs,
strutils,
sugar,
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}")
+ let response = get(client, &"https://invidio.us/search?q={queryParam}")
$response.body
func extractTitlesAndUrls*(html: string): SearchResults =
{.noSideEffect.}:
+ # TODO Pick an invidious instance from config. Using YouTube directly for now.
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"]))
+ filter(a => "watch" in a.attrs["href"] and len(a) == 1).
+ map(a => (innerText(a), "https://www.youtube.com" & a.attrs["href"]))
proc presentVideoOptions*(searchResults: SearchResults) =