Compare commits

...

6 Commits

2 changed files with 44 additions and 26 deletions

10
install.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
installdir="$HOME/.local/bin"
datadir="$HOME/.local/share/peertube-cli"
mkdir -p $installdir
mkdir -p $datadir
cp -r transmission-daemon config.json $datadir
cp peertube-cli.sh $installdir/peertube-cli
echo "done, make sure $installdir in your PATH"

View File

@ -1,13 +1,20 @@
#!/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' tempvideostor=$(mktemp -d)
default_player_command="mpv --hwdec --network-timeout=30 --profile=low-latency --cache=yes --cache-on-disk=yes --cache-dir=$tempvideostor --cache-unlink-files=immediate"
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,13 +24,14 @@ 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
} }
check_connect() check_connect()
{ {
if [ -n "$(curl --head -s "$instance_point"/config | grep 'HTTP\/. 200')" ]; then if [ -n "$(curl --head -s "$instance_point"/config | grep 'HTTP/. 200')" ]; then
echo 'OK' echo 'OK'
else else
echo echo
@ -42,21 +50,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 +97,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 +115,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
@ -136,8 +144,8 @@ peertube_menu_video()
else else
hls='streamingPlaylists.0.' hls='streamingPlaylists.0.'
fi fi
video_url=$(echo "$get_video" | jj "$hls"files.#[resolution.id="$pref_video_quality"].fileUrl) 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) torrent_url=$(echo "$get_video" | jj "$hls"files.\#[resolution.id="$pref_video_quality"].torrentUrl)
echo "Channel: $channel" echo "Channel: $channel"
fulldescr= fulldescr=
if [ -n "$desc" ]; then if [ -n "$desc" ]; then
@ -153,9 +161,9 @@ 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 "$hls"files.#.resolution.label | fzy) resolution=$(echo "$get_video" | jj -l "$hls"files.\#.resolution.label | fzy)
video_url=$(echo "$get_video" | jj "$hls"files.#[resolution.label="$resolution"].fileUrl) video_url=$(echo "$get_video" | jj "$hls"files.\#[resolution.label="$resolution"].fileUrl)
torrent_url=$(echo "$get_video" | jj "$hls"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
@ -172,8 +180,8 @@ peertube_menu_video()
"Share") "Share")
echo "Link: https://$instance/w/$1" echo "Link: https://$instance/w/$1"
echo "Direct links:" echo "Direct links:"
echo "$(echo "$get_video" | jj -l "$hls"files.#.resolution.label)" echo "$(echo "$get_video" | jj -l "$hls"files.\#.resolution.label)"
echo "$(echo "$get_video" | jj -l "$hls"files.#.fileUrl)" ;; echo "$(echo "$get_video" | jj -l "$hls"files.\#.fileUrl)" ;;
esac esac
done done
} }
@ -250,18 +258,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 +334,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 +352,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