From f114ff9a9ec2477cf9b8fe62283b28794d49fcab Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Fri, 3 Dec 2021 17:21:44 +0530 Subject: [PATCH] Get rid of Peerflix. Only use Webtorrent. Signed-off-by: Joseph Nuthalapati --- README.md | 6 +++--- src/lib.nim | 6 ++---- src/peertube.nim | 10 ++++++++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index fa32d61..6e88ecf 100644 --- 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. diff --git a/src/lib.nim b/src/lib.nim index c88c4ed..4064ae4 100644 --- a/src/lib.nim +++ b/src/lib.nim @@ -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) diff --git a/src/peertube.nim b/src/peertube.nim index 946736f..16b6d23 100644 --- a/src/peertube.nim +++ b/src/peertube.nim @@ -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() -- 2.43.0