From b2ab1e926c5594c699865bcef839a938c470df94 Mon Sep 17 00:00:00 2001 From: Yuuki Chan Date: Thu, 23 Feb 2023 23:39:22 +0900 Subject: [PATCH] Initial commit. --- README.md | 19 +++++++++++++++- ani.sh | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 ani.sh diff --git a/README.md b/README.md index 5d3a3b2..87731e1 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,20 @@ # ani +This is pretty much a clone of my Java version of the .ani command, it will show you the shows that will air soon on Japanese TV. -Script for displaying airing anime. \ No newline at end of file +# Usage +$ git clone https://github.com/Yuuki2012/ani.git +$ cd ani $ chmod +x ani.sh +$ ./ani.sh " " -1 # You can also use -2, -3, -4, -5, depending on what you want +OR +$ ./ani.sh \ -1 # As long as you escape spaces it'll work fine. + +# Output +> Tanaka-kun wa Itsumo Kedaruge Episode 4 airs on Animax in 0d 1h 18m 23s +> Servamp Episode 5 airs on TOKYO MX in 0d 1h 18m 23s +> 文化放送モバイルplus presents 生放送 Episode airs on Ultra! A&G+ in 0d 1h 18m 23s +> 孤独のグルメ(5) Episode ^孤独のグルメスペシャル!真夏の東北・宮城出張編 airs on TV Tokyo in 0d 1h 18m 23s +> 孤独のグルメ(5) Episode ^孤独のグルメスペシャル!真夏の東北・宮城出張編 airs on TV Aichi in 0d 1h 18m 23s + +# Requirements +root user +Everything else required will be installed once you run the tool. diff --git a/ani.sh b/ani.sh new file mode 100644 index 0000000..14249da --- /dev/null +++ b/ani.sh @@ -0,0 +1,66 @@ +#!/bin/bash +ARGS=$1 +API_KEY="15b9666294d951546c3a3b4b1b2a83f55638473c" # Change this, it's not gonna work ;) +JQ_INSTALLED=$(dpkg-query -W -f='${Status}' jq 2>/dev/null | grep -c "ok installed") +CU_INSTALLED=$(dpkg-query -W -f='${Status}' curl 2>/dev/null | grep -c "ok installed") +BC_INSTALLED=$(dpkg-query -W -f='${Status}' bc 2>/dev/null | grep -c "ok installed") +MISSING_PACKAGES=0 + +if [ -z "$1" ]; then + echo "> No arguments, please specify at least one argument: ./ani.sh ARG, escape any spaces." + exit +fi + +function checkpackages { + if [ $JQ_INSTALLED -eq 0 ]; then + let "MISSING_PACKAGES++" + fi + if [ $CU_INSTALLED -eq 0 ]; then + let "MISSING_PACKAGES++" + fi + if [ $BC_INSTALLED -eq 0 ]; then + let "MISSING_PACKAGES++" + fi + + if [ $MISSING_PACKAGES -gt 0 ]; then + echo "One or more required packages are missing, install them? (y/n)" + read REPLY + if [ "$REPLY" = "y" ]; then + sudo apt-get install -y jq curl bc > /dev/null + fi + fi +} + +checkpackages + +R=0 +while true; do + case "$2" in + -1 ) R=0; shift ;; + -2 ) R=1; shift ;; + -3 ) R=2; shift ;; + -4 ) R=3; shift ;; + -5 ) R=4; shift ;; + -- ) R=0; shift ; break ;; + * ) break ;; + esac +done + +URL="http://tv.yuuki-chan.xyz/json.php?key=$API_KEY&controller=search&query=$ARGS" # http://anitv.foolz.us/json.php?controller=search&query=$ARGS +RES=$(curl -s $URL) > /dev/null +for (( index=0; index<=$R; index++ )) +do + ID=$(echo $RES | jq '.results['$index'].id' | tr -d '"') + TI=$(echo $RES | jq '.results['$index'].title' | tr -d '"') + EP=$(echo $RES | jq '.results['$index'].episode' | tr -d '"') + SU=$(echo $RES | jq '.results['$index'].subtitle' | tr -d '"') + ST=$(echo $RES | jq '.results['$index'].station' | tr -d '"') + AT=$(echo $RES | jq '.results['$index'].unixtime' | tr -d '"') + AD=$(echo $RES | jq '.results['$index'].anidb' | tr -d '"') + NOW=$(TZ=":Asia/Tokyo" date +%s) + DIFF=$(echo $AT-$NOW | bc) + TIME=$(printf "%dd %dh %dm %ds" $(( DIFF / (3600 * 24) )) $(((DIFF / 3600) % 24)) $(((DIFF / 60) % 60)) $((DIFF % 60))) + + echo -e "\e[0m>\e[31m $TI\e[0m Episode\e[31m $EP\e[0m airs on\e[31m $ST\e[0m in\e[31m $TIME\e[0m" +done +exit \ No newline at end of file