Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
* DONE Pretty colors in terminal
* TODO Preferences should go into a config file
* TODO Terminal color themes?
* DONE Pretty colors in terminal
* TODO Preferences should go into a config file
* TODO Terminal color themes?
-* TODO Get rid of temp file or make one temp file per user
+* DONE Get rid of temp file or make one temp file per user
* TODO Use cligen to create a proper CLI
* TODO Use cligen to create a proper CLI
import xmltree
# Supported video players in order of preference
import xmltree
# Supported video players in order of preference
-let supportedPlayers = @["mpv", "vlc"]
+let supportedPlayers = ["mpv", "vlc"]
# Only show these many results
let limit = 10
# Only show these many results
let limit = 10
proc getYoutubePage(searchQuery: string): string =
let queryParam = encodeUrl(searchQuery)
proc getYoutubePage(searchQuery: string): string =
let queryParam = encodeUrl(searchQuery)
- var client = newHttpClient()
+ let client = newHttpClient()
let response = get(client, "https://www.youtube.com/results?hl=en&search_query=" & queryParam)
let response = get(client, "https://www.youtube.com/results?hl=en&search_query=" & queryParam)
- writeFile("/tmp/clitube-page.html", response.body)
- return "/tmp/clitube-page.html"
proc extractTitlesAndUrls(htmlFile: string): seq[SearchResult] =
proc extractTitlesAndUrls(htmlFile: string): seq[SearchResult] =
- loadHtml(htmlFile).findAll("a").
+ 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)]
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)]
presentVideoOptions(searchResults)
stdout.styledWrite(fgYellow, "Choose video number: ")
presentVideoOptions(searchResults)
stdout.styledWrite(fgYellow, "Choose video number: ")
-var number: int = parseInt(readLine(stdin))
+let number: int = parseInt(readLine(stdin))
styledEcho "\n", fgGreen, "Playing ", styleBright, fgMagenta, searchResults[number].title
styledEcho "\n", fgGreen, "Playing ", styleBright, fgMagenta, searchResults[number].title