From 79da2a4a0a45f48a9efc7ba59b16b3f18c1d4b9b Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Tue, 5 Apr 2022 19:16:13 +0300 Subject: [PATCH] added feature: seeding videos --- .gitignore | 6 +++ README.md | 8 +++- config.json | 1 + peertube-cli.sh | 46 ++++++++++++++++++--- transmission-daemon/settings.json | 68 +++++++++++++++++++++++++++++++ 5 files changed, 121 insertions(+), 8 deletions(-) create mode 100644 transmission-daemon/settings.json diff --git a/.gitignore b/.gitignore index d353c94..2717df5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,8 @@ +temp +transmission-daemon/resume +transmission-daemon/torrents +transmission-daemon/blocklists +transmission-daemon/dht.dat +transmission-daemon/stats.json preload instance.hist diff --git a/README.md b/README.md index 3597be1..b38899b 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,8 @@ Just for fun. Simple "player" API script for PeerTube instances. Features: * Select videos and play -* Switch instance from public list in config.json[1] or manual input. Also recent used instance list. +* Seeding videos[1] +* Switch instance from public list in config.json[2] or manual input. Also recent used instance list. * All others futures maybe working 50/50 Depends: @@ -12,5 +13,8 @@ Depends: * [curl](https://curl.se/) * [fzy](https://github.com/jhawthorn/fzy) -[1]**Warning:** "Public" list instances in config.json may content _unofficial instance_ +Opt. depends: +* [1]transmisson-daemon - for seeding videos when playing (but video still load from server). + +[2]**Warning:** "Public" list instances in config.json may content _unofficial instance_ diff --git a/config.json b/config.json index 624c6bc..faca318 100644 --- a/config.json +++ b/config.json @@ -1,6 +1,7 @@ { "instance": "xxivproduction.video", "prefer_quality_video": 480 + "torrent_enabled": false "public_list_instances": [ ] diff --git a/peertube-cli.sh b/peertube-cli.sh index 98add97..7818d8d 100755 --- a/peertube-cli.sh +++ b/peertube-cli.sh @@ -2,12 +2,20 @@ instance=$(jj -i config.json instance) pref_video_quality=$(jj -i config.json prefer_quality_video) +torrent_enabled=$(jj -i config.json torrent_enabled) instance_hist='instance.hist' ordering='title' default_player_command='mpv --network-timeout=30 --profile=low-latency' instance_point="https://$instance/api/v1" +torrent_init() +{ + if [ "$torrent_enabled" = 'true' ]; then + transmission-daemon -T -g transmission-daemon -w temp --password '' + fi +} + peertube_api_check_ratelimit() { curl -s --head "$instance_point/" | grep rate @@ -55,14 +63,22 @@ peertube_menu_video() "Back") sub2_menu=0 ;; "Play") video_url=$(echo $get_video | jj streamingPlaylists.0.files.#[resolution.id=$pref_video_quality].fileUrl) + torrent_url=$(echo $get_video | jj streamingPlaylists.0.files.#[resolution.id=$pref_video_quality].torrentUrl) if [ -z "$video_url" ]; then - echo "Resolution $pref_video_quality\\p not avalaible" + echo "Resolution $pref_video_quality\p not avalaible" echo 'Please choice:' resolution=$(echo $get_video | jj -l streamingPlaylists.0.files.#.resolution.label | fzy) video_url=$(echo $get_video | jj streamingPlaylists.0.files.#[resolution.label=$resolution].fileUrl) + torrent_url=$(echo $get_video | jj streamingPlaylists.0.files.#[resolution.label=$resolution].torrentUrl) fi echo 'Loading may long time for big video' - $default_player_command $video_url ;; + if [ "$torrent_enabled" = 'true' ]; then + transmission-remote 9095 -a $torrent_url + $default_player_command $video_url + transmission-remote 9095 -t 1 -rad + else + $default_player_command $video_url + fi ;; esac done } @@ -71,18 +87,34 @@ menu_settings() { sub_menu=1 while [ $sub_menu -eq 1 ]; do - set_nane=$(echo "Main menu\nDefault resolution (current: $pref_video_quality)" | fzy) - case $set_nane in + default_res="Default resolution (current: $pref_video_quality)" + torrent_set="Torrent (current: $torrent_enabled)" + set_name=$(echo "Main menu\n$default_res\n$torrent_set" | fzy) + case $set_name in "Main menu") sub_menu=0 ;; - "Default resolution (current: $pref_video_quality)") + "$default_res") resolution=$(echo '144\n240\n288\n480\n720\n1080' | fzy) jj -i config.json prefer_quality_video -v $resolution -o config.json export pref_video_quality=$resolution ;; + + "$torrent_set") + case $torrent_enabled in + 'true') + jj -i config.json torrent_enabled -v 'false' -o config.json + export torrent_enabled='false' + transmission-remote 9095 --exit ;; + + 'false') + jj -i config.json torrent_enabled -v 'true' -o config.json + export torrent_enabled='true' + torrent_init ;; + esac esac done } +torrent_init videosmenu='All Videos' videosmenulocal='Local Videos' changepod='Switch instance' @@ -140,7 +172,9 @@ while true; do "$checkapilimits") peertube_api_check_ratelimit ;; - "$Exit") exit 0 ;; + "$Exit") + if [ $torrent_enabled = 'true' ]; then transmission-remote 9095 --exit; fi + exit 0 ;; esac diff --git a/transmission-daemon/settings.json b/transmission-daemon/settings.json new file mode 100644 index 0000000..e8fdf2f --- /dev/null +++ b/transmission-daemon/settings.json @@ -0,0 +1,68 @@ +{ + "alt-speed-down": 50, + "alt-speed-enabled": false, + "alt-speed-time-begin": 540, + "alt-speed-time-day": 127, + "alt-speed-time-enabled": false, + "alt-speed-time-end": 1020, + "alt-speed-up": 50, + "bind-address-ipv4": "0.0.0.0", + "bind-address-ipv6": "::", + "blocklist-enabled": false, + "blocklist-url": "http://www.example.com/blocklist", + "cache-size-mb": 4, + "dht-enabled": true, + "download-dir": "temp", + "download-queue-enabled": true, + "download-queue-size": 5, + "encryption": 1, + "idle-seeding-limit": 30, + "idle-seeding-limit-enabled": false, + "incomplete-dir": "temp", + "incomplete-dir-enabled": true, + "lpd-enabled": true, + "message-level": 2, + "peer-congestion-algorithm": "", + "peer-id-ttl-hours": 6, + "peer-limit-global": 200, + "peer-limit-per-torrent": 50, + "peer-port": 49910, + "peer-port-random-high": 65535, + "peer-port-random-low": 49152, + "peer-port-random-on-start": true, + "peer-socket-tos": "default", + "pex-enabled": true, + "port-forwarding-enabled": true, + "preallocation": 0, + "prefetch-enabled": true, + "queue-stalled-enabled": true, + "queue-stalled-minutes": 30, + "ratio-limit": 2, + "ratio-limit-enabled": false, + "rename-partial-files": true, + "rpc-authentication-required": false, + "rpc-bind-address": "127.0.0.1", + "rpc-enabled": true, + "rpc-host-whitelist": "", + "rpc-host-whitelist-enabled": true, + "rpc-password": "", + "rpc-port": 9091, + "rpc-url": "/transmission/", + "rpc-username": "", + "rpc-whitelist": "127.0.0.1,::1", + "rpc-whitelist-enabled": true, + "scrape-paused-torrents-enabled": true, + "script-torrent-done-enabled": false, + "script-torrent-done-filename": "", + "seed-queue-enabled": false, + "seed-queue-size": 10, + "speed-limit-down": 100, + "speed-limit-down-enabled": false, + "speed-limit-up": 100, + "speed-limit-up-enabled": false, + "start-added-torrents": true, + "trash-original-torrent-files": false, + "umask": 18, + "upload-slots-per-torrent": 14, + "utp-enabled": true +}