else:
discard execProcess(player, args=args, options=processOptions)
+func buildMusicDownloadArgs*(url: string): seq[string] =
+ {.noSideEffect.}:
+ var args = @["--ignore-errors", "-f", "bestaudio", "--extract-audio", "--audio-format", "mp3", "--audio-quality", "0", "-o"]
+ let downloadLocation = &"'{expandTilde(musicDownloadDirectory)}/%(title)s.%(ext)s'"
+ args.add(downloadLocation)
+ args.add(url)
+ return args
+
+func buildVideoDownloadArgs*(url: string): seq[string] =
+ {.noSideEffect.}:
+ var args = @["-f", "best", "-o"]
+ let downloadLocation = &"'{expandTilde(videoDownloadDirectory)}/%(title)s.%(ext)s'"
+ args.add(downloadLocation)
+ args.add(url)
+ return args
+
proc download*(args: openArray[string], title: string) =
styledEcho "\n", fgGreen, "Downloading ", styleBright, fgMagenta, title
discard execShellCmd(&"youtube-dl {args.join(\" \")}")
func sanitizeURL*(url: string): string =
urlLongen(stripZshEscaping(url))
-proc directPlay*(searchQuery: string, player: string) =
- let url = sanitizeURL(searchQuery)
- if searchQuery.startswith("magnet:"):
+proc directPlay*(url: string, player: string) =
+ if url.startswith("magnet:"):
discard execProcess("peerflix", args=[url, &"--{player}"], options=processOptions)
else:
discard execProcess(player, args=[url], options=processOptions)
+
+proc directDownload*(url: string) =
+ let args = buildVideoDownloadArgs(url)
+ discard execShellCmd(&"youtube-dl {args.join(\" \")}")