remove jq as dependency

This commit is contained in:
ksyasuda 2022-01-28 12:19:24 -08:00
parent 59ea0c99b6
commit b07948cee2

49
ani-cli
View File

@ -65,11 +65,10 @@ get_dpage_link() {
ep_no=$2
# credits to fork: https://github.com/Dink4n/ani-cli for the fix
# dub prefix takes the value "-dub" when dub is needed else is empty
anime_page=$(curl -s "$BASE_URL/$anime_id${dub_prefix}-$ep_no")
anime_page=$(curl -s "$BASE_URL/$anime_id-$ep_no")
if printf '%s' "$anime_page" | grep -q "404"; then
anime_page=$(curl -s "$BASE_URL/$anime_id${dub_prefix}-episode-$ep_no")
anime_page=$(curl -s "$BASE_URL/$anime_id-episode-$ep_no")
fi
printf '%s' "$anime_page" |
@ -82,17 +81,19 @@ decrypt_link() {
ajax_url="https://gogoplay.io/encrypt-ajax.php"
#get the id from the url
video_id=$(printf "$1" | cut -d\? -f2 | cut -d\& -f1 | sed 's/id=//g')
video_id=$(echo "$1" | cut -d\? -f2 | cut -d\& -f1 | sed 's/id=//g')
lg "video_id -> $video_id" > /dev/stderr
#construct ajax parameters
secret_key='3235373436353338353932393338333936373634363632383739383333323838'
iv='34323036393133333738303038313335'
ajax=$(printf "$video_id" | openssl enc -aes256 -K "$secret_key" -iv "$iv" -a)
ajax=$(echo "$video_id" | openssl enc -aes256 -K "$secret_key" -iv "$iv" -a)
lg "ajax -> $ajax" > /dev/stderr
#send the request to the ajax url
curl -s -H 'x-requested-with:XMLHttpRequest' "$ajax_url" -d "id=$ajax" -d "time=69420691337800813569" | jq -r '.source[].file'
curl -s -H 'x-requested-with:XMLHttpRequest' "$ajax_url" -d "id=$ajax" -d "time=69420691337800813569" |
sed -e 's/\].*/\]/' -e 's/\\//g' |
grep -Eo 'https:\/\/[-a-zA-Z0-9@:%._\+~#=][a-zA-Z0-9][-a-zA-Z0-9@:%_\+.~#?&\/\/=]*'
lg "END: decrypt_link()" > /dev/stderr
}
@ -103,11 +104,13 @@ get_video_quality() {
best)
video_link=$(printf '%s' "$video_links" | head -n 4 | tail -n 1)
;;
worst)
video_link=$(printf '%s' "$video_links" | head -n 1)
;;
*)
video_link=$(printf '%s' "$video_links" | grep -iE "${quality}" | head -n 1)
video_link=$(printf '%s' "$video_links" | grep -i "${quality}" | head -n 1)
if [ -z "$video_link" ]; then
err "Current video quality is not available (defaulting to best quality)"
quality=best
@ -664,6 +667,10 @@ open_episode() {
half_ep=0
fi
if [ -z "$video_url" ]; then
die "Video URL not found"
fi
if [ "$is_download" -eq 0 ]; then
kill "$PID" > /dev/null 2>&1
nohup "$player_fn" --http-header-fields="Referer:$dpage_link" "$video_url" > /dev/null 2>&1 &
@ -681,14 +688,17 @@ open_episode() {
{
mkdir -p "$dl_dir" || die "Could not create directory"
if command -v "notify-send" > /dev/null; then
aria2c --referer="$dpage_link" "$video_url" --dir="$dl_dir" -o "$episode.mp4" --download-result=hide &&
notify-send -i "$ANIWRAPPER_ICON_PATH" "Download complete for ${anime_id//-/ } - Episode: $episode" ||
if aria2c --referer="$dpage_link" "$video_url" --dir="$dl_dir" -o "$episode.mp4" --download-result=hide; then
notify-send -i "$ANIWRAPPER_ICON_PATH" "Download complete for ${anime_id//-/ } - Episode: $episode"
else
notify-send -i "$MAISAN_ICON_PATH" "Download failed for ${anime_id//-/ } - Episode: $episode. Please retry or check your internet connection"
fi
else
aria2c --referer="$dpage_link" "$video_url" --dir="$dl_dir" -o "$episode.mp4" --download-result=hide &&
printf "${c_green}Downloaded complete for %s - Episode: %s${c_reset}\n" "${anime_id//-/ }" "$episode" ||
if aria2c --referer="$dpage_link" "$video_url" --dir="$dl_dir" -o "$episode.mp4" --download-result=hide; then
printf "${c_green}Downloaded complete for %s - Episode: %s${c_reset}\n" "${anime_id//-/ }" "$episode"
else
printf "${c_red}Download failed for %s - Episode: %s, please retry or check your internet connection${c_reset}\n" "${anime_id//-/ }" "$episode"
fi
fi
}
fi
@ -733,7 +743,7 @@ parse_args() {
is_download=0
download_dir="."
half_ep=0
while getopts 'hd:Hsvq:c-:f:t:T:CQ:D:' OPT; do
while getopts 'hd:Hsvq:cf:t:T:CQ:D:' OPT; do
case "$OPT" in
h)
help_text
@ -760,17 +770,6 @@ parse_args() {
c)
is_rofi=0
;;
-)
case $OPTARG in
dub)
dub_prefix="-dub"
;;
*)
help_text
exit 1
;;
esac
;;
f)
scrape="file"
play_dir="$OPTARG"
@ -990,6 +989,6 @@ main() {
done
}
dep_ch "$player_fn" "curl" "sed" "grep" "sqlite3" "rofi" "git" "aria2c" "jq"
dep_ch "$player_fn" "curl" "sed" "grep" "sqlite3" "rofi" "git" "aria2c"
parse_args "$@"
main