mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-11-22 03:19:53 -08:00
refactor and clean up code a bit
This commit is contained in:
parent
266f684817
commit
74d511b982
33
ani-cli
33
ani-cli
@ -422,7 +422,7 @@ get_search_query() {
|
||||
|
||||
msg="Choose from list of searched anime below, or enter a unique name of an anime to search for"
|
||||
span="$(generate_span "$msg")"
|
||||
if [ -z "$*" ] && [ "$is_rofi" -eq 1 ]; then
|
||||
if [ "$is_rofi" -eq 1 ]; then
|
||||
query=$(rofi -dpi "$DPI" -dmenu -l 15 -p "Search Anime:" \
|
||||
-mesg "$span" \
|
||||
-config "$ROFI_CFG" < <(run_stmt "$stmt"))
|
||||
@ -432,8 +432,6 @@ get_search_query() {
|
||||
elif [ "$is_rofi" -eq 0 ]; then
|
||||
printf "Search Anime: "
|
||||
read -r query
|
||||
else
|
||||
query=$*
|
||||
fi
|
||||
}
|
||||
|
||||
@ -449,7 +447,6 @@ search_anime() {
|
||||
search="${1// /}"
|
||||
fi
|
||||
logger "Search Query: $search"
|
||||
titlepattern='<a href="/category/'
|
||||
curl -s "$BASE_URL//search.html" \
|
||||
-G \
|
||||
-d "keyword=$search" |
|
||||
@ -515,7 +512,7 @@ anime_selection() {
|
||||
-async-pre-read 33 \
|
||||
-mesg "$msg" -only-match)
|
||||
[ -z "$user_input" ] && return 1
|
||||
if [ $(awk '{ print $NF }' <<< "$user_input") = "Quit" ]; then
|
||||
if [ "$(awk '{ print $NF }' <<< "$user_input")" = "Quit" ]; then
|
||||
logger "QUITTING"
|
||||
return 1
|
||||
fi
|
||||
@ -588,7 +585,6 @@ episode_selection() {
|
||||
FROM watch_history \
|
||||
WHERE anime_name = '$anime_id';"
|
||||
hist=$(run_stmt "$stmt")
|
||||
# logger "HISTORY: ${hist[*]}"
|
||||
|
||||
# Get Watch History for $anime_id as comma separated list
|
||||
watch_history=""
|
||||
@ -684,11 +680,11 @@ open_episode() {
|
||||
{
|
||||
mkdir -p "$dl_dir" || die "Could not create directory"
|
||||
if command -v "notify-send" > /dev/null; then
|
||||
aria2c -x 16 -s 16 --referer="$dpage_link" "$video_url" --dir="$dl_dir" -o "$episode.mp4" --download-result=hide &&
|
||||
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" ||
|
||||
notify-send -i "$MAISAN_ICON_PATH" "Download failed for ${anime_id//-/ } - Episode: $episode. Please retry or check your internet connection"
|
||||
else
|
||||
aria2c -x 16 -s 16 --referer="$dpage_link" "$video_url" --dir="$dl_dir" -o "$episode.mp4" --download-result=hide &&
|
||||
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" ||
|
||||
printf "${c_red}Download failed for %s - Episode: %s, please retry or check your internet connection${c_reset}\n" "${anime_id//-/ }" "$episode"
|
||||
|
||||
@ -699,10 +695,8 @@ open_episode() {
|
||||
|
||||
stream() {
|
||||
logger "Running stream()"
|
||||
logger "args: $*"
|
||||
get_search_query "$*"
|
||||
get_search_query
|
||||
searched=0
|
||||
if [ $# -le 1 ]; then
|
||||
# check if anime has been searched before
|
||||
anime_id="${query// /}"
|
||||
[ -z "$anime_id" ] && die "No anime selected or queried"
|
||||
@ -710,7 +704,6 @@ stream() {
|
||||
check_db "$anime_id" "search"
|
||||
searched="$?"
|
||||
logger "Searched before: $searched"
|
||||
fi
|
||||
if [ "$searched" -eq 0 ]; then
|
||||
search_results=$(search_anime "$query")
|
||||
[ -z "$search_results" ] && die "No search results found"
|
||||
@ -729,10 +722,10 @@ stream() {
|
||||
episode_selection
|
||||
}
|
||||
|
||||
# option parsing
|
||||
parse_args() {
|
||||
# to clear the colors when exited using SIGINT
|
||||
trap "printf '$c_reset'" INT HUP
|
||||
|
||||
# option parsing
|
||||
scrape=query
|
||||
quality=best
|
||||
is_rofi=1
|
||||
@ -846,16 +839,15 @@ while getopts 'hd:Hsvq:c-:f:t:T:CQ:D:' OPT; do
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
dep_ch "$player_fn" "curl" "sed" "grep" "sqlite3" "rofi" "git" "aria2c" "jq"
|
||||
}
|
||||
|
||||
########
|
||||
# main #
|
||||
########
|
||||
|
||||
main() {
|
||||
case $scrape in
|
||||
query)
|
||||
stream "$*"
|
||||
stream
|
||||
;;
|
||||
history)
|
||||
stmt="SELECT DISTINCT anime_name FROM watch_history ORDER BY watch_date DESC"
|
||||
@ -995,3 +987,8 @@ while :; do
|
||||
esac
|
||||
open_episode "$selection_id" "$episode" "$download_dir"
|
||||
done
|
||||
}
|
||||
|
||||
dep_ch "$player_fn" "curl" "sed" "grep" "sqlite3" "rofi" "git" "aria2c" "jq"
|
||||
parse_args "$@"
|
||||
main
|
||||
|
Loading…
Reference in New Issue
Block a user