]> njoseph.me Git - nimcoon.git/blobdiff - src/lib.nim
Allow http urls to .torrent files to be streamed
[nimcoon.git] / src / lib.nim
index 67095ac9b24ec905f7e79f3e9d1ee90728cece53..24aa9305218c02a599af07e93eeb223589b0e071 100644 (file)
@@ -52,6 +52,7 @@ proc presentVideoOptions*(searchResults: SearchResults) =
     styledEcho $index, ". ", styleBright, fgMagenta, title, "\n", resetStyle, fgCyan, url, "\n"
 
 func isPlaylist(url: string): bool =
+  # Identifies if video is part of a playlist
   # Only YouTube playlists are supported for now
   "www.youtube.com" in url and "&list=" in url
 
@@ -62,7 +63,8 @@ func buildPlayerArgs(url: string, options: Table[string, bool], player: string):
   if options["fullScreen"]: args.add("--fullscreen")
   # Playlists are only supported for MPV player
   if isPlaylist(url) and player == "mpv":
-    args.add("--ytdl-raw-options=\"yes-playlist=\"")
+    let list_arg = url.split('&')[1]
+    args[0] = "https://www.youtube.com/playlist?" & list_arg
   return args
 
 proc play*(player: string, options: Table[string, bool], url: string, title: string = "") =
@@ -104,11 +106,13 @@ func sanitizeURL*(url: string): string =
   urlLongen(stripZshEscaping(url))
 
 proc directPlay*(url: string, player: string, options: Table[string, bool]) =
-  if url.startswith("magnet:"):
+  if url.startswith("magnet:") or url.endswith(".torrent"):
     if options["musicOnly"]:
+      # TODO Replace with WebTorrent once it supports media player options
       discard execShellCmd(&"peerflix '{url}' -a --{player} -- --no-video")
     else:
-      discard execProcess("peerflix", args=[url, &"--{player}"], options=processOptions)
+      # WebTorrent is so much faster!
+      discard execProcess("webtorrent", args=[url, &"--{player}"], options=processOptions)
   else:
     play(player, options, url)