Support directPlay and directDownload for music
authorJoseph Nuthalapati <njoseph@riseup.net>
Fri, 27 Mar 2020 07:47:02 +0000 (13:17 +0530)
committerJoseph Nuthalapati <njoseph@riseup.net>
Fri, 27 Mar 2020 07:59:28 +0000 (13:29 +0530)
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
src/lib.nim
src/nimcoon.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(\" \")}")
index 31a608894167d04f03b6ada6a388a2bb20cec64b..a0bb93deb2ed9ac8a17dad9c5e440abf24255873 100644 (file)
@@ -50,9 +50,9 @@ proc main() =
 
   if searchQuery.startswith("https:") or searchQuery.startswith("magnet:"):
     if options["download"]:
-      directDownload(sanitizeURL(searchQuery))
+      directDownload(sanitizeURL(searchQuery), options["musicOnly"])
     else:
-      directPlay(sanitizeURL(searchQuery), player)
+      directPlay(sanitizeURL(searchQuery), player, options["musicOnly"])
     quit(0)
 
   let searchResults = extractTitlesAndUrls(getYoutubePage(searchQuery))