From da2baa7cac4202eec70c66ea8edb2e44ec64d5a7 Mon Sep 17 00:00:00 2001 From: localhost_frssoft Date: Tue, 5 Apr 2022 14:05:58 +0300 Subject: [PATCH] upload --- .gitignore | 2 + LICENSE | 7 +++ README.md | 16 ++++++ config.json | 7 +++ peertube-cli.sh | 147 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 179 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 config.json create mode 100755 peertube-cli.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d353c94 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +preload +instance.hist diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..009e47b --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +Copyright (c) 2022 localhost_frssoft + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..3597be1 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# peertube-cli +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. +* All others futures maybe working 50/50 + +Depends: +* [mpv](https://mpv.io) (recommended) +* [jj](http://gitea.phreedom.club/localhost_frssoft/jj) +* [curl](https://curl.se/) +* [fzy](https://github.com/jhawthorn/fzy) + +[1]**Warning:** "Public" list instances in config.json may content _unofficial instance_ + diff --git a/config.json b/config.json new file mode 100644 index 0000000..624c6bc --- /dev/null +++ b/config.json @@ -0,0 +1,7 @@ +{ + "instance": "xxivproduction.video", + "prefer_quality_video": 480 + "public_list_instances": [ + + ] +} diff --git a/peertube-cli.sh b/peertube-cli.sh new file mode 100755 index 0000000..98add97 --- /dev/null +++ b/peertube-cli.sh @@ -0,0 +1,147 @@ +#!/bin/sh + +instance=$(jj -i config.json instance) +pref_video_quality=$(jj -i config.json prefer_quality_video) +instance_hist='instance.hist' +ordering='title' +default_player_command='mpv --network-timeout=30 --profile=low-latency' + +instance_point="https://$instance/api/v1" + +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) + 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") + video_url=$(echo $get_video | jj streamingPlaylists.0.files.#[resolution.id=$pref_video_quality].fileUrl) + if [ -z "$video_url" ]; then + 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) + fi + echo 'Loading may long time for big video' + $default_player_command $video_url ;; + esac + done +} + +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 + "Main menu") sub_menu=0 ;; + + "Default resolution (current: $pref_video_quality)") + 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 ;; + esac + done +} + +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 ;; + + "$Exit") exit 0 ;; + + esac + +done