2022-04-05 11:05:58 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
instance=$(jj -i config.json instance)
|
|
|
|
pref_video_quality=$(jj -i config.json prefer_quality_video)
|
2022-04-05 16:16:13 +00:00
|
|
|
torrent_enabled=$(jj -i config.json torrent_enabled)
|
2022-04-05 11:05:58 +00:00
|
|
|
instance_hist='instance.hist'
|
|
|
|
ordering='title'
|
|
|
|
default_player_command='mpv --network-timeout=30 --profile=low-latency'
|
|
|
|
|
|
|
|
instance_point="https://$instance/api/v1"
|
|
|
|
|
2022-04-05 16:16:13 +00:00
|
|
|
torrent_init()
|
|
|
|
{
|
|
|
|
if [ "$torrent_enabled" = 'true' ]; then
|
|
|
|
transmission-daemon -T -g transmission-daemon -w temp --password ''
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-04-05 11:05:58 +00:00
|
|
|
peertube_api_check_ratelimit()
|
|
|
|
{
|
|
|
|
curl -s --head "$instance_point/" | grep rate
|
|
|
|
}
|
|
|
|
|
|
|
|
peertube_api_get_all_videos()
|
|
|
|
{
|
|
|
|
curl -s --compressed "$instance_point/videos?count=100&start=$1&isLocal=$2" | jj -p | tee preload >> /dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
peertube_api_get_video()
|
|
|
|
{
|
|
|
|
curl -s --compressed "$instance_point/videos/$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
peertube_menu_videos()
|
|
|
|
{
|
|
|
|
echo "Avalaible $(jj -i preload total) videos"
|
|
|
|
sub_menu=1
|
|
|
|
while [ $sub_menu -eq 1 ]; do
|
|
|
|
names=$(jj -i preload -l 'data.#.name')
|
|
|
|
menu_videos_choice=$(echo "Main menu\n$names" | fzy)
|
|
|
|
case $menu_videos_choice in
|
|
|
|
"Main menu") sub_menu=0 ;;
|
|
|
|
*)
|
|
|
|
video_uuid=$(jj -i preload data.#[name="$menu_videos_choice"].uuid)
|
|
|
|
peertube_menu_video $video_uuid ;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
peertube_menu_video()
|
|
|
|
{
|
|
|
|
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)
|
2022-04-05 17:36:11 +00:00
|
|
|
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)
|
2022-04-05 11:05:58 +00:00
|
|
|
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")
|
|
|
|
if [ -z "$video_url" ]; then
|
2022-04-05 17:36:11 +00:00
|
|
|
echo "Resolution $pref_video_quality"'p not avalaible'
|
2022-04-05 11:05:58 +00:00
|
|
|
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)
|
2022-04-05 16:16:13 +00:00
|
|
|
torrent_url=$(echo $get_video | jj streamingPlaylists.0.files.#[resolution.label=$resolution].torrentUrl)
|
2022-04-05 11:05:58 +00:00
|
|
|
fi
|
2022-04-05 17:36:11 +00:00
|
|
|
|
2022-04-05 16:16:13 +00:00
|
|
|
if [ "$torrent_enabled" = 'true' ]; then
|
|
|
|
transmission-remote 9095 -a $torrent_url
|
2022-04-05 17:36:11 +00:00
|
|
|
curl -s --tcp-fastopen --output - $video_url | $default_player_command -
|
2022-04-05 16:16:13 +00:00
|
|
|
transmission-remote 9095 -t 1 -rad
|
|
|
|
else
|
2022-04-05 17:36:11 +00:00
|
|
|
curl -s --tcp-fastopen --output - $video_url | $default_player_command -
|
2022-04-05 16:16:13 +00:00
|
|
|
fi ;;
|
2022-04-05 11:05:58 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
menu_settings()
|
|
|
|
{
|
|
|
|
sub_menu=1
|
|
|
|
while [ $sub_menu -eq 1 ]; do
|
2022-04-05 16:16:13 +00:00
|
|
|
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
|
2022-04-05 11:05:58 +00:00
|
|
|
"Main menu") sub_menu=0 ;;
|
|
|
|
|
2022-04-05 16:16:13 +00:00
|
|
|
"$default_res")
|
2022-04-05 11:05:58 +00:00
|
|
|
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 ;;
|
2022-04-05 16:16:13 +00:00
|
|
|
|
|
|
|
"$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
|
2022-04-05 11:05:58 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2022-04-05 16:16:13 +00:00
|
|
|
torrent_init
|
2022-04-05 11:05:58 +00:00
|
|
|
videosmenu='All Videos'
|
|
|
|
videosmenulocal='Local Videos'
|
|
|
|
changepod='Switch instance'
|
|
|
|
settings='Settings'
|
|
|
|
checkapilimits='Check API limits (debug)'
|
|
|
|
Exit='Exit'
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
choice=$(echo "$videosmenu\n$videosmenulocal\n$changepod\n$settings\n$checkapilimits\n$Exit" | fzy)
|
|
|
|
|
|
|
|
case "$choice" in
|
|
|
|
|
|
|
|
"$videosmenu")
|
|
|
|
echo 'Enter page number (per 100 videos)'
|
|
|
|
read page
|
|
|
|
peertube_api_get_all_videos $page
|
|
|
|
peertube_menu_videos ;;
|
|
|
|
|
|
|
|
"$videosmenulocal")
|
|
|
|
echo 'Enter page number (per 100 videos)'
|
|
|
|
read page
|
|
|
|
peertube_api_get_all_videos $page 'true'
|
|
|
|
peertube_menu_videos ;;
|
|
|
|
|
|
|
|
"$changepod")
|
|
|
|
empty=0
|
|
|
|
case $(echo 'Recently used\nChoice from list\nManual input' | fzy) in
|
|
|
|
"Recently used")
|
|
|
|
if [ -s $instance_hist ]; then
|
|
|
|
touch $instance_hist && instance=$(cat $instance_hist | fzy)
|
|
|
|
else
|
|
|
|
echo 'No recently used instances...'
|
|
|
|
empty=1
|
|
|
|
fi ;;
|
|
|
|
|
|
|
|
"Choice from list") instance=$(jj -l -i config.json public_list_instances | sed 's/"//g' | fzy) ;;
|
|
|
|
|
|
|
|
"Manual input") echo "Type instance (ex. $instance):" && read instance ;;
|
|
|
|
esac
|
|
|
|
if [ $empty -eq 0 ]; then
|
|
|
|
echo $instance >> $instance_hist
|
|
|
|
cat $instance_hist | sort | uniq | tee $instance_hist 1>>/dev/null
|
|
|
|
export instance
|
|
|
|
export instance_point="https://$instance/api/v1"
|
|
|
|
conf_instance_state=$(echo 'Permanent\nTemporaly' | fzy)
|
|
|
|
if [ "$conf_instance_state" = 'Permanent' ]; then
|
|
|
|
jj -i config.json instance -v $instance -o config.json
|
|
|
|
else
|
|
|
|
echo ''
|
|
|
|
fi
|
|
|
|
clear
|
|
|
|
fi ;;
|
|
|
|
|
|
|
|
"$settings") menu_settings ;;
|
|
|
|
|
|
|
|
"$checkapilimits") peertube_api_check_ratelimit ;;
|
|
|
|
|
2022-04-05 16:16:13 +00:00
|
|
|
"$Exit")
|
|
|
|
if [ $torrent_enabled = 'true' ]; then transmission-remote 9095 --exit; fi
|
|
|
|
exit 0 ;;
|
2022-04-05 11:05:58 +00:00
|
|
|
|
|
|
|
esac
|
|
|
|
|
|
|
|
done
|