noctuid / mpv-webtorrent-hook

Stream torrents in mpv using webtorrent-cli
GNU General Public License v3.0
90 stars 3 forks source link

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=)

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 [[https://github.com/Eisa01/mpv-scripts#smartcopypaste-ii-script][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).

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

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 [[https://github.com/webtorrent/webtorrent-cli/issues/132][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).

Here are advantages of the other plugin:

Here are missing features of the other plugin:

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:

+begin_src conf-unix

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

+end_src