]> njoseph.me Git - nimcoon.git/blobdiff - src/lib.nim
Support directPlay and directDownload for music
[nimcoon.git] / src / lib.nim
index ffa4a4a3847a8e55cd3145acf2bc9c3f3233b085..1fa21685006241c3e2bd81aea15cab7b0fd64eb8 100644 (file)
@@ -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(\" \")}")