mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-22 23:37:48 +01:00
add pokecli!!
This commit is contained in:
parent
90ca920183
commit
69bcba20b1
1 changed files with 125 additions and 0 deletions
125
poke-cli.sh
Normal file
125
poke-cli.sh
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
function display_help {
|
||||||
|
echo "Usage: $0 <search_query>"
|
||||||
|
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 <https://gnu.org/licenses/gpl.html>.
|
||||||
|
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
|
||||||
|
|
||||||
|
Poke-CLI for GNU/Linux systems
|
||||||
|
|
||||||
|
Copyright (C) Poke 2024-20xx
|
||||||
|
|
||||||
|
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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
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 <search_query> / 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"
|
Loading…
Reference in a new issue