X-Git-Url: https://njoseph.me/gitweb/nimcoon.git/blobdiff_plain/9a8ef4ad5f1c6dbee407cbea01224676131060ba..e4a687068729e3042ce742a4058cf7d9297366b8:/src/lib.nim diff --git a/src/lib.nim b/src/lib.nim index ffa4a4a..dd8dcf4 100644 --- a/src/lib.nim +++ b/src/lib.nim @@ -22,7 +22,7 @@ type CommandLineOptions* = tuple[searchQuery: string, options: Options] # poEchoCmd can be added to options for debugging -let processOptions = {poStdErrToStdOut, poUsePath, poEchoCmd} +let processOptions = {poStdErrToStdOut, poUsePath} proc selectMediaPlayer*(): string = let availablePlayers = filterIt(supportedPlayers, execProcess("which " & it).len != 0) @@ -85,12 +85,20 @@ func stripZshEscaping(url: string): string = func sanitizeURL*(url: string): string = urlLongen(stripZshEscaping(url)) -proc directPlay*(url: string, player: string) = +proc directPlay*(url: string, player: string, musicOnly: bool) = if url.startswith("magnet:"): - discard execProcess("peerflix", args=[url, &"--{player}"], options=processOptions) + if musicOnly: + discard execShellCmd(&"peerflix '{url}' -a --{player} -- --no-video") + else: + discard execProcess("peerflix", args=[url, &"--{player}"], options=processOptions) else: - discard execProcess(player, args=[url], options=processOptions) - -proc directDownload*(url: string) = - let args = buildVideoDownloadArgs(url) + if musicOnly: + discard execShellCmd(&"{player} --no-video {url}") + else: + discard execProcess(player, args=[url], options=processOptions) + +proc directDownload*(url: string, musicOnly: bool) = + let args = + if musicOnly: buildMusicDownloadArgs(url) + else: buildVideoDownloadArgs(url) discard execShellCmd(&"youtube-dl {args.join(\" \")}")