From 69bcba20b1638216879eb6a9faf95abef7001c4b Mon Sep 17 00:00:00 2001 From: Ashley //// Date: Wed, 17 Jan 2024 23:59:03 +0000 Subject: [PATCH] add pokecli!! --- poke-cli.sh | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 poke-cli.sh diff --git a/poke-cli.sh b/poke-cli.sh new file mode 100644 index 00000000..dd93f95a --- /dev/null +++ b/poke-cli.sh @@ -0,0 +1,125 @@ +#!/usr/bin/env bash +# +# Copyright (C) 2024-20xx Poke! (https://codeberg.org/ashley/poke) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +function display_help { + echo "Usage: $0 " + echo " --help you are here lol" + echo " --version version information." + echo " --license license stuff" +} + +function display_version { +echo "poke-cli version 1.0 + +Play videos from your terminal! +https://codeberg.org/ashley/poke + +Copyright (C) 2024-202x Poke +License GPLv3+: GNU GPL version 3 or later . +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. +" +} + +# Display license information +function display_license { + cat <. + +EOF +} + +# Check for command-line options +case $1 in + --help) + display_help + exit 0 + ;; + --version) + display_version + exit 0 + ;; + --license) + display_license + exit 0 + ;; +esac + +if [ $# -eq 0 ]; then + echo "Usage: $0 / see --help for more info :D" + exit 1 +fi + +search_query=$1 + +player="mpv" + +if ! command -v $player &> /dev/null; then + player="vlc" +fi + +if ! command -v jq &> /dev/null && ! command -v gojq &> /dev/null; then + echo "Error: jq or gojq not found. Please install them to run the script." + exit 1 +fi + +json_data=$(curl -s "https://invid-api.poketube.fun/api/v1/search?q=${search_query// /+}") + +video_count=$(echo "$json_data" | jq -r '. | length') +if [ $video_count -eq 0 ]; then + echo "Nyo videos found for the given search query ;_;" + exit 1 +fi + +echo "Select a vid to play:" +echo + +for i in $(seq 0 $(($video_count - 1))); do + title=$(echo "$json_data" | jq -r ".[$i].title") + author=$(echo "$json_data" | jq -r ".[$i].author") + echo "[$(($i + 1))] $title by $author" +done + +read -p "Enter the thingy umm number of the video to play (1-$video_count): " selection + +if ! [[ "$selection" =~ ^[1-9][0-9]*$ ]] || [ "$selection" -lt 1 ] || [ "$selection" -gt "$video_count" ]; then + echo "enter a number between 1 and $video_count lol" + exit 1 +fi + +video_url=$(echo "$json_data" | jq -r ".[$(($selection - 1))].videoId") + +echo "Starting $player..." + +$player "https://poketube.fun/watch?v=$video_url"