GitHub - noctuid/mpv-webtorrent-hook: Stream torrents in mpv using webtorrent-cli (original) (raw)

About

This plugin allows mpv to stream magnet links (and any other torrent identifier webtorrent-cli handles) directly. It will automatically remove videos after they are finished playing (by default) and will set the title to be the name of the video.

This script will detect magnet: links, torrent files/urls ending in torrent, and info hashes. You can also explicitly prefix the identifier with webtorrent:// to let this plugin know the path/url is a torrent (e.g. you could do this to play a torrent file that didn’t end in torrent)

Comparison with using webtorrent --mpv

One benefit is consistency of syntax (e.g. if you have a shell command or keybinding to call mpv <clipboard>, you don’t need to handle torrents differently).

This script also provides more functionality and options. For example, it can automatically delete downloaded files, and it can remember and jump to the last video you played in a torrent file with multiple videos. See the settings heading below for more information.

Another reason you might want to use this script is that you can start mpv with a playlist of multiple magnet links or add magnet links to the playlist of an already open mpv window (e.g. using one of the scripts that allow appending a link from the clipboard to the playlist such as SmartCopyPaste-II).

By using this script, you can also see mpv output (which is hidden when calling webtorrent directly). On the other hand, you won’t be able to see both the normal webtorrent output and mpv’s output at the same time. By default, this script will print the download speed while waiting for the video to load (see the information on the webtorrent_verbosity setting below for more options).

Requirements

Webtorrent-cli does not currently provide a way to get a json list of files which is why jq and xidel are required.

Installation Instructions

Clone this repo into the mpv scripts directory (e.g. git clone <url> ~/.config/mpv/scripts/webtorrent-hook). You must put this whole directory in the scripts directory not just the lua file.

Comparison with Peerflix-hook

Peerflix is unmaintained, and webtorrent is supposedly significantly faster.

Peerflix’s output is not parseable, so the peerflix version of this script had to do a bunch of extra work with lsof to figure out the location of video files, the title of video files, and the process id of peerflix (in order to kill it). This script is a lot cleaner by comparison (though it could be better if webtorrent had a way to give more script-friendly output).

This script also has a lot more functionality than the peerflix version (e.g support for torrents containing multiple media files).

Comparison With Btfs-stream

Webtorrent has parseable output but is still not very script friendly. mpv-btfs-stream is cleaner and simpler by comparison and does not rely on parsing output. The advantage of webtorrent over btfs is that webtorrent is much faster. Functionally, I am not aware of any downsides of using webtorrent-hook instead of btfs-stream though. See here for a full comparison.

Comparison with webtorrent-mpv-hook

There is a similarly named plugin webtorrent-mpv-hook which directly uses the webtorrent library instead of webtorrent-cli.

Here are advantages of the other plugin:

Here are missing features of the other plugin:

Configuration

In ~/.config/mpv/script-opts/webtorrent-hook.conf, you can change the following settings:

If you set close_webtorrent to no, you will have to manually kill the WebTorrent processes yourself when you want to stop seeding (pgrep WebTorrent should show all processes).

Here is an example configuration file:

close_webtorrent=yes remove_files=yes

change download directory

download_directory=~/tmp/webtorrent-hook

do not use --out, --keep-streaming, --port or most other flags (should be

obvious; don't use --quiet, --mpv, etc.)

webtorrent_flags=["--blocklist", ""] show_speed=no remember_last_played=yes remember_directory=~/tmp/webtorrent-remember