]> njoseph.me Git - nimcoon.git/commitdiff
Get rid of Peerflix. Only use Webtorrent.
authorJoseph Nuthalapati <njoseph@riseup.net>
Fri, 3 Dec 2021 11:51:44 +0000 (17:21 +0530)
committerJoseph Nuthalapati <njoseph@riseup.net>
Fri, 3 Dec 2021 11:52:37 +0000 (17:22 +0530)
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
README.md
src/lib.nim
src/peertube.nim

index fa32d611d3805c6a1610d80ad82d01313bb9735c..6e88ecf972410eef8e0830bee86a7dc794e14432 100644 (file)
--- a/README.md
+++ b/README.md
@@ -73,7 +73,7 @@ I made this just for myself. The development is completely based on my needs and
 Nim Coon depends on the following:
 - yt-dlp
 - mpv (recommended) or vlc
-- peerflix and webtorrent (for magnet links)
+- webtorrent (for magnet links)
 
 Install MPV or VLC using your distribution's package manager.
 
@@ -82,9 +82,9 @@ Install yt-dlp
 pip3 install --user yt-dlp
 ```
 
-Install PeerFlix and WebTorrent
+Install WebTorrent
 ```sh
-npm install --global peerflix webtorrent-cli
+npm install --global webtorrent-cli
 ```
 
 (Optional) If you want your YouTube downloads to be faster, install `aria2` download manager.
index c88c4eda056716504e3b3b104ca4520308a9b8eb..4064ae43cdbdde02acbf5722317597f4a2d11fa1 100644 (file)
@@ -82,14 +82,12 @@ proc play*(player: string, options: Table[string, bool], url: string, title: str
 proc directPlay*(url: string, player: string, options: Table[string, bool]) =
   let url =
     if find(url, PEERTUBE_REGEX) != -1 and "webtorrent".isInstalled:
-      getPeerTubeMagnetLink(url)
+      getPeerTubeMagnetLink(url, options["musicOnly"])
     else: url
   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")
+      discard execShellCmd(&"webtorrent '{url}' --{player} --player-args='--no-video'")
     else:
-      # WebTorrent is so much faster!
       discard execProcess("webtorrent", args=[url, &"--{player}"], options=processOptions)
   else:
     play(player, options, url)
index 946736f163d8110e66b7cc41faed9975ce1a2cf1..16b6d238753cc74cfb2f6ecaca2e5301e3b71fcb 100644 (file)
@@ -7,7 +7,7 @@ import
 
 let PEERTUBE_REGEX = re"w\/[0-9a-zA-z]{22}"
 
-proc getPeerTubeMagnetLink*(url: string): string =
+proc getPeerTubeMagnetLink*(url: string, musicOnly: bool): string =
   ## Gets the magnet link of the best possible resolution from PeerTube
   let uuid = url.substr(find(url, PEERTUBE_REGEX) + "w/".len)
   let domainName = url.substr(8, find(url, '/', start=8) - 1)
@@ -15,4 +15,10 @@ proc getPeerTubeMagnetLink*(url: string): string =
   let client = newHttpClient()
   let response = get(client, apiURL)
   let jsonNode = parseJson($response.body)
-  jsonNode["files"][0]["magnetUri"].getStr()
+  var files = jsonNode["files"]
+  if len(jsonNode["files"]) == 0:
+    files = jsonNode["streamingPlaylists"][0]["files"]
+  if musicOnly:
+    files[len(files)-1]["magnetUri"].getStr()
+  else:
+    files[0]["magnetUri"].getStr()