Compare commits

...

5 Commits

2 changed files with 91 additions and 24 deletions

View File

@ -3,6 +3,7 @@
instance=$(jj -i config.json instance) instance=$(jj -i config.json instance)
pref_video_quality=$(jj -i config.json prefer_quality_video) pref_video_quality=$(jj -i config.json prefer_quality_video)
torrent_enabled=$(jj -i config.json torrent_enabled) torrent_enabled=$(jj -i config.json torrent_enabled)
rpcport=9095
instance_hist='instance.hist' instance_hist='instance.hist'
ordering='title' ordering='title'
default_player_command='mpv --network-timeout=30 --profile=low-latency' default_player_command='mpv --network-timeout=30 --profile=low-latency'
@ -12,7 +13,7 @@ instance_point="https://$instance/api/v1"
torrent_init() torrent_init()
{ {
if [ "$torrent_enabled" = 'true' ]; then if [ "$torrent_enabled" = 'true' ]; then
transmission-daemon -T -g transmission-daemon -w temp --password '' transmission-daemon -T -g transmission-daemon -w temp --password '' -p $rpcport
fi fi
} }
@ -21,9 +22,28 @@ peertube_api_check_ratelimit()
curl -s --head "$instance_point/" | grep rate curl -s --head "$instance_point/" | grep rate
} }
peertube_api_version_server()
{
curl -s --compressed "$instance_point/config" | jj serverVersion | cut -f 1 -d.
}
peertube_api_get_all_videos() peertube_api_get_all_videos()
{ {
curl -s --compressed "$instance_point/videos?count=100&start=$1&isLocal=$2" | jj -p | tee preload >> /dev/null curl -s --compressed "$instance_point/videos?count=100&start=$1" | jj -p | tee preload >> /dev/null
}
peertube_api_get_local_videos()
{
if [ $version -gt 3 ]; then
curl -s --compressed "$instance_point/videos?count=100&start=$1&isLocal=true" | jj -p | tee preload >> /dev/null
else
curl -s --compressed "$instance_point/videos?count=100&start=$1&filter=local" | jj -p | tee preload >> /dev/null
fi
}
peertube_api_get_live_streams()
{
curl -s --compressed "$instance_point/videos?count=100&start=$1&isLive=true&sort=-publishedAt" | jj -p | tee preload >> /dev/null
} }
peertube_api_get_video() peertube_api_get_video()
@ -35,28 +55,48 @@ peertube_menu_videos()
{ {
echo "Avalaible $(jj -i preload total) videos" echo "Avalaible $(jj -i preload total) videos"
sub_menu=1 sub_menu=1
page=0
while [ $sub_menu -eq 1 ]; do while [ $sub_menu -eq 1 ]; do
names=$(jj -i preload -l 'data.#.name') names=$(jj -i preload -l 'data.#.name')
menu_videos_choice=$(echo "Main menu\n$names" | fzy) menu_videos_choice=$(echo "Main menu\n$names\nNext page" | fzy)
case $menu_videos_choice in case $menu_videos_choice in
"Main menu") sub_menu=0 ;; "Main menu") sub_menu=0 ;;
"Next page")
if [ "$1" = 'all' ]; then
page=$(expr $page + 100)
peertube_api_get_all_videos $page
else
page=$(expr $page + 100)
peertube_api_get_local_videos $page
fi ;;
*) *)
video_uuid=$(jj -i preload data.#[name="$menu_videos_choice"].uuid) video_uuid=$(jj -i preload data.#[name="$menu_videos_choice"].uuid)
peertube_menu_video $video_uuid ; if [ "$1" = 'lives' ]; then
peertube_menu_stream $video_uuid
else
peertube_menu_video $video_uuid
fi ;;
esac esac
done done
} }
peertube_menu_video() peertube_menu_video()
{ {
clear
sub2_menu=1 sub2_menu=1
get_video=$(peertube_api_get_video $1) get_video=$(peertube_api_get_video $1)
while [ $sub2_menu -eq 1 ]; do while [ $sub2_menu -eq 1 ]; do
name=$(echo $get_video | jj name) name=$(echo $get_video | jj name)
desc=$(echo $get_video | jj description) desc=$(echo $get_video | jj description)
channel=$(echo $get_video | jj channel.name) channel=$(echo $get_video | jj channel.name)
video_url=$(echo $get_video | jj streamingPlaylists.0.files.#[resolution.id=$pref_video_quality].fileUrl) check_hls_empty=$(echo $get_video | jj streamingPlaylists.0)
torrent_url=$(echo $get_video | jj streamingPlaylists.0.files.#[resolution.id=$pref_video_quality].torrentUrl) if [ -z $check_hls_empty ]; then
hls=''
else
hls='streamingPlaylists.0.'
fi
video_url=$(echo $get_video | jj "$hls"files.#[resolution.id=$pref_video_quality].fileUrl)
torrent_url=$(echo $get_video | jj "$hls"files.#[resolution.id=$pref_video_quality].torrentUrl)
echo "Channel: $channel" echo "Channel: $channel"
echo "Description video:\n$desc" echo "Description video:\n$desc"
menu_video_choice=$(echo "Play\nBack\nMain menu" | fzy) menu_video_choice=$(echo "Play\nBack\nMain menu" | fzy)
@ -67,15 +107,15 @@ peertube_menu_video()
if [ -z "$video_url" ]; then if [ -z "$video_url" ]; then
echo "Resolution $pref_video_quality"'p not avalaible' echo "Resolution $pref_video_quality"'p not avalaible'
echo 'Please choice:' echo 'Please choice:'
resolution=$(echo $get_video | jj -l streamingPlaylists.0.files.#.resolution.label | fzy) resolution=$(echo $get_video | jj -l "$hls"files.#.resolution.label | fzy)
video_url=$(echo $get_video | jj streamingPlaylists.0.files.#[resolution.label=$resolution].fileUrl) video_url=$(echo $get_video | jj "$hls"files.#[resolution.label=$resolution].fileUrl)
torrent_url=$(echo $get_video | jj streamingPlaylists.0.files.#[resolution.label=$resolution].torrentUrl) torrent_url=$(echo $get_video | jj "$hls"files.#[resolution.label=$resolution].torrentUrl)
fi fi
if [ "$torrent_enabled" = 'true' ]; then if [ "$torrent_enabled" = 'true' ]; then
transmission-remote 9095 -a $torrent_url transmission-remote $rpcport -a $torrent_url
curl -s --tcp-fastopen --output - $video_url | $default_player_command - curl -s --tcp-fastopen --output - $video_url | $default_player_command -
transmission-remote 9095 -t 1 -rad transmission-remote $rpcport -t 1 -rad
else else
curl -s --tcp-fastopen --output - $video_url | $default_player_command - curl -s --tcp-fastopen --output - $video_url | $default_player_command -
fi ;; fi ;;
@ -83,6 +123,30 @@ peertube_menu_video()
done done
} }
peertube_menu_stream()
{
clear
sub2_menu=1
get_video=$(peertube_api_get_video $1)
while [ $sub2_menu -eq 1 ]; do
name=$(echo $get_video | jj name)
desc=$(echo $get_video | jj description)
channel=$(echo $get_video | jj channel.name)
playlist_stream=$(echo $get_video | jj streamingPlaylists.0.playlistUrl)
state=$(echo $get_video | jj state.label)
echo "Status: $state"
#torrent_url=$(echo $get_video | jj streamingPlaylists.0.files.#[resolution.id=$pref_video_quality].torrentUrl)
echo "Channel: $channel"
echo "Description video:\n$desc"
menu_video_choice=$(echo "Play\nBack\nMain menu" | fzy)
case $menu_video_choice in
"Main menu") sub2_menu=0 && sub_menu=0 ;;
"Back") sub2_menu=0 ;;
"Play") $default_player_command $playlist_stream ;;
esac
done
}
menu_settings() menu_settings()
{ {
sub_menu=1 sub_menu=1
@ -103,7 +167,7 @@ menu_settings()
'true') 'true')
jj -i config.json torrent_enabled -v 'false' -o config.json jj -i config.json torrent_enabled -v 'false' -o config.json
export torrent_enabled='false' export torrent_enabled='false'
transmission-remote 9095 --exit ;; transmission-remote $rpcport --exit ;;
'false') 'false')
jj -i config.json torrent_enabled -v 'true' -o config.json jj -i config.json torrent_enabled -v 'true' -o config.json
@ -114,30 +178,32 @@ menu_settings()
done done
} }
version=$(peertube_api_version_server)
torrent_init torrent_init
videosmenu='All Videos' videosmenu='All Videos'
videosmenulocal='Local Videos' videosmenulocal='Local Videos'
streamsmenu='Live streams'
changepod='Switch instance' changepod='Switch instance'
settings='Settings' settings='Settings'
checkapilimits='Check API limits (debug)' checkapilimits='Check API limits (debug)'
Exit='Exit' Exit='Exit'
while true; do while true; do
choice=$(echo "$videosmenu\n$videosmenulocal\n$changepod\n$settings\n$checkapilimits\n$Exit" | fzy) choice=$(echo "$videosmenu\n$videosmenulocal\n$streamsmenu\n$changepod\n$settings\n$checkapilimits\n$Exit" | fzy)
case "$choice" in case "$choice" in
"$videosmenu") "$videosmenu")
echo 'Enter page number (per 100 videos)' peertube_api_get_all_videos 0
read page peertube_menu_videos 'all' ;;
peertube_api_get_all_videos $page
peertube_menu_videos ;;
"$videosmenulocal") "$videosmenulocal")
echo 'Enter page number (per 100 videos)' peertube_api_get_local_videos 0
read page peertube_menu_videos 'local' ;;
peertube_api_get_all_videos $page 'true'
peertube_menu_videos ;; "$streamsmenu")
peertube_api_get_live_streams 0
peertube_menu_videos 'lives' ;;
"$changepod") "$changepod")
empty=0 empty=0
@ -159,6 +225,7 @@ while true; do
cat $instance_hist | sort | uniq | tee $instance_hist 1>>/dev/null cat $instance_hist | sort | uniq | tee $instance_hist 1>>/dev/null
export instance export instance
export instance_point="https://$instance/api/v1" export instance_point="https://$instance/api/v1"
export version=$(peertube_api_version_server)
conf_instance_state=$(echo 'Permanent\nTemporaly' | fzy) conf_instance_state=$(echo 'Permanent\nTemporaly' | fzy)
if [ "$conf_instance_state" = 'Permanent' ]; then if [ "$conf_instance_state" = 'Permanent' ]; then
jj -i config.json instance -v $instance -o config.json jj -i config.json instance -v $instance -o config.json
@ -173,7 +240,7 @@ while true; do
"$checkapilimits") peertube_api_check_ratelimit ;; "$checkapilimits") peertube_api_check_ratelimit ;;
"$Exit") "$Exit")
if [ $torrent_enabled = 'true' ]; then transmission-remote 9095 --exit; fi if [ $torrent_enabled = 'true' ]; then transmission-remote $rpcport --exit; fi
exit 0 ;; exit 0 ;;
esac esac

View File

@ -26,7 +26,7 @@
"peer-id-ttl-hours": 6, "peer-id-ttl-hours": 6,
"peer-limit-global": 200, "peer-limit-global": 200,
"peer-limit-per-torrent": 50, "peer-limit-per-torrent": 50,
"peer-port": 49910, "peer-port": 59577,
"peer-port-random-high": 65535, "peer-port-random-high": 65535,
"peer-port-random-low": 49152, "peer-port-random-low": 49152,
"peer-port-random-on-start": true, "peer-port-random-on-start": true,
@ -46,7 +46,7 @@
"rpc-host-whitelist": "", "rpc-host-whitelist": "",
"rpc-host-whitelist-enabled": true, "rpc-host-whitelist-enabled": true,
"rpc-password": "", "rpc-password": "",
"rpc-port": 9091, "rpc-port": 9095,
"rpc-url": "/transmission/", "rpc-url": "/transmission/",
"rpc-username": "", "rpc-username": "",
"rpc-whitelist": "127.0.0.1,::1", "rpc-whitelist": "127.0.0.1,::1",