X-Git-Url: https://njoseph.me/gitweb/nimcoon.git/blobdiff_plain/17955bba9f852c8264f1bfdf8259f19d4aeefd2a..e9f0c7d0facb6a454a204e3b3ce66d521f40d6e8:/src/lib.nim diff --git a/src/lib.nim b/src/lib.nim index c737f02..1b6ed93 100644 --- a/src/lib.nim +++ b/src/lib.nim @@ -1,23 +1,28 @@ import htmlparser, httpClient, + os, osproc, sequtils, sugar, strformat, std/[terminal], + strformat, strtabs, strutils, + tables, uri, xmltree import config type + Options* = Table[string, bool] SearchResult* = tuple[title: string, url: string] - CommandLineOptions* = tuple[searchQuery: string, musicOnly: bool, feelingLucky: bool, fullScreen: bool] + CommandLineOptions* = tuple[searchQuery: string, options: Options] -let processOptions = {poStdErrToStdOut, poUsePath} +# poEchoCmd can be added to options for debugging +let processOptions = {poStdErrToStdOut, poUsePath, poEchoCmd} proc selectMediaPlayer*(): string = let availablePlayers = filterIt(supportedPlayers, execProcess("which " & it).len != 0) @@ -45,10 +50,13 @@ proc presentVideoOptions*(searchResults: seq[SearchResult]) = styledEcho $index, ". ", styleBright, fgMagenta, title, "\n", resetStyle, fgCyan, url, "\n" proc play*(player: string, args: openArray[string], title: string) = - # poEchoCmd can be added to options for debugging styledEcho "\n", fgGreen, "Playing ", styleBright, fgMagenta, title discard execProcess(player, args=args, options=processOptions) +proc download*(args: openArray[string], title: string) = + styledEcho "\n", fgGreen, "Downloading ", styleBright, fgMagenta, title + discard execShellCmd(&"youtube-dl {args.join(\" \")}") + func urlLongen(url: string): string = url.replace("youtu.be/", "www.youtube.com/watch?v=")