preparing for userspace installation

This commit is contained in:
localhost_frssoft 2023-10-11 13:48:57 +03:00
parent 236cbb3023
commit 8fa20fd650
1 changed files with 24 additions and 17 deletions

View File

@ -1,13 +1,19 @@
#!/bin/sh #!/bin/sh
instance=$(jj -i config.json instance) workdir="$HOME/.local/share/peertube-cli"
pref_video_quality=$(jj -i config.json prefer_quality_video) instance=$(jj -i $workdir/config.json instance)
torrent_enabled=$(jj -i config.json torrent_enabled) pref_video_quality=$(jj -i $workdir/config.json prefer_quality_video)
torrent_enabled=$(jj -i $workdir/config.json torrent_enabled)
rpcport=9095 rpcport=9095
instance_hist='instance.hist' instance_hist="$workdir/instance.hist"
ordering='title' ordering='title'
default_player_command='mpv --hwdec --network-timeout=30 --profile=low-latency' default_player_command='mpv --hwdec --network-timeout=30 --profile=low-latency'
mkdir -p $workdir
if [ ! -f "$workdir/config.json" ]; then
cp -r config.json transmission-daemon $workdir
echo 'config created'
fi
instance_point="https://$instance/api/v1" instance_point="https://$instance/api/v1"
default_curl_opt() default_curl_opt()
{ {
@ -17,7 +23,8 @@ default_curl_opt()
torrent_init() torrent_init()
{ {
if [ "$torrent_enabled" = 'true' ]; then if [ "$torrent_enabled" = 'true' ]; then
transmission-daemon -T -g transmission-daemon -w temp --password '' -p $rpcport tmp_dir=$(mktemp -d)
transmission-daemon -T -g $workdir/transmission-daemon -w $tmp_dir --password '' -p $rpcport
fi fi
} }
@ -42,21 +49,21 @@ peertube_api_version_server()
peertube_api_get_all_videos() peertube_api_get_all_videos()
{ {
default_curl_opt "$instance_point/videos?count=100&start=$1" | jj -p | tee preload >> /dev/null default_curl_opt "$instance_point/videos?count=100&start=$1" | jj -p | tee $workdir/preload >> /dev/null
} }
peertube_api_get_local_videos() peertube_api_get_local_videos()
{ {
if [ "$version" -gt 3 ]; then if [ "$version" -gt 3 ]; then
default_curl_opt "$instance_point/videos?count=100&start=$1&isLocal=true" | jj -p | tee preload >> /dev/null default_curl_opt "$instance_point/videos?count=100&start=$1&isLocal=true" | jj -p | tee $workdir/preload >> /dev/null
else else
default_curl_opt "$instance_point/videos?count=100&start=$1&filter=local" | jj -p | tee preload >> /dev/null default_curl_opt "$instance_point/videos?count=100&start=$1&filter=local" | jj -p | tee $workdir/preload >> /dev/null
fi fi
} }
peertube_api_get_live_streams() peertube_api_get_live_streams()
{ {
default_curl_opt "$instance_point/videos?count=100&start=$1&isLive=true&sort=-publishedAt" | jj -p | tee preload >> /dev/null default_curl_opt "$instance_point/videos?count=100&start=$1&isLive=true&sort=-publishedAt" | jj -p | tee $workdir/preload >> /dev/null
} }
peertube_api_get_livechat() peertube_api_get_livechat()
@ -89,11 +96,11 @@ peertube_api_get_fulldescription()
peertube_menu_videos() peertube_menu_videos()
{ {
echo "Avalaible $(jj -i preload total) videos" echo "Avalaible $(jj -i $workdir/preload total) videos"
sub_menu=1 sub_menu=1
page=0 page=0
while [ $sub_menu -eq 1 ]; do while [ $sub_menu -eq 1 ]; do
names=$(jj -i preload -l 'data.#.name' | nl -s: -v0 -w1) names=$(jj -i $workdir/preload -l 'data.#.name' | nl -s: -v0 -w1)
menu_videos_choice=$(echo "Main menu\n$names\nNext page" | 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 ;;
@ -107,7 +114,7 @@ peertube_menu_videos()
fi ;; fi ;;
*) *)
index=$(echo "$menu_videos_choice" | cut -f 1 -d:) index=$(echo "$menu_videos_choice" | cut -f 1 -d:)
video_uuid=$(jj -i preload data."$index".uuid) video_uuid=$(jj -i $workdir/preload data."$index".uuid)
if [ "$1" = 'lives' ]; then if [ "$1" = 'lives' ]; then
peertube_menu_stream "$video_uuid" peertube_menu_stream "$video_uuid"
else else
@ -250,18 +257,18 @@ menu_settings()
"$default_res") "$default_res")
resolution=$(echo '144\n240\n288\n480\n720\n1080' | fzy) resolution=$(echo '144\n240\n288\n480\n720\n1080' | fzy)
jj -i config.json prefer_quality_video -v "$resolution" -o config.json jj -i $workdir/config.json prefer_quality_video -v "$resolution" -o $workdir/config.json
export pref_video_quality="$resolution" ;; export pref_video_quality="$resolution" ;;
"$torrent_set") "$torrent_set")
case $torrent_enabled in case $torrent_enabled in
'true') 'true')
jj -i config.json torrent_enabled -v 'false' -o config.json jj -i $workdir/config.json torrent_enabled -v 'false' -o $workdir/config.json
export torrent_enabled='false' export torrent_enabled='false'
transmission-remote $rpcport --exit ;; transmission-remote $rpcport --exit ;;
'false') 'false')
jj -i config.json torrent_enabled -v 'true' -o config.json jj -i $workdir/config.json torrent_enabled -v 'true' -o $workdir/config.json
export torrent_enabled='true' export torrent_enabled='true'
torrent_init ;; torrent_init ;;
esac esac
@ -326,7 +333,7 @@ while true; do
empty=1 empty=1
fi ;; fi ;;
"Choice from list") instance=$(jj -l -i config.json public_list_instances | sed 's/"//g' | fzy) ;; "Choice from list") instance=$(jj -l -i $workdir/config.json public_list_instances | sed 's/"//g' | fzy) ;;
"Manual input") echo "Type instance (ex. $instance):" && read instance ;; "Manual input") echo "Type instance (ex. $instance):" && read instance ;;
esac esac
@ -344,7 +351,7 @@ while true; do
export version=$(peertube_api_version_server) 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 $workdir/config.json instance -v "$instance" -o $workdir/config.json
else else
echo '' echo ''
fi fi