]> njoseph.me Git - nimcoon.git/blobdiff - src/lib.nim
pagination: "n" takes to next page of results
[nimcoon.git] / src / lib.nim
index ffa4a4a3847a8e55cd3145acf2bc9c3f3233b085..54259e2d9f7d08237c3bb73ec51e30fb9751167a 100644 (file)
@@ -20,9 +20,10 @@ type
   Options* = Table[string, bool]
   SearchResult* = tuple[title: string, url: string]
   CommandLineOptions* = tuple[searchQuery: string, options: Options]
+  SelectionRange* = tuple[begin: int, until: int]
 
 # 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 +86,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(\" \")}")