mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-10-28 04:44:11 -07:00
refactor and clean up code a bit
This commit is contained in:
parent
266f684817
commit
74d511b982
77
ani-cli
77
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,17 +722,17 @@ stream() {
|
||||
episode_selection
|
||||
}
|
||||
|
||||
# to clear the colors when exited using SIGINT
|
||||
trap "printf '$c_reset'" INT HUP
|
||||
|
||||
# option parsing
|
||||
scrape=query
|
||||
quality=best
|
||||
is_rofi=1
|
||||
is_download=0
|
||||
download_dir="."
|
||||
half_ep=0
|
||||
while getopts 'hd:Hsvq:c-:f:t:T:CQ:D:' OPT; do
|
||||
parse_args() {
|
||||
# to clear the colors when exited using SIGINT
|
||||
trap "printf '$c_reset'" INT HUP
|
||||
scrape=query
|
||||
quality=best
|
||||
is_rofi=1
|
||||
is_download=0
|
||||
download_dir="."
|
||||
half_ep=0
|
||||
while getopts 'hd:Hsvq:c-:f:t:T:CQ:D:' OPT; do
|
||||
case "$OPT" in
|
||||
h)
|
||||
help_text
|
||||
@ -844,18 +837,17 @@ while getopts 'hd:Hsvq:c-:f:t:T:CQ:D:' OPT; do
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND - 1))
|
||||
|
||||
dep_ch "$player_fn" "curl" "sed" "grep" "sqlite3" "rofi" "git" "aria2c" "jq"
|
||||
done
|
||||
shift $((OPTIND - 1))
|
||||
}
|
||||
|
||||
########
|
||||
# main #
|
||||
########
|
||||
|
||||
case $scrape in
|
||||
main() {
|
||||
case $scrape in
|
||||
query)
|
||||
stream "$*"
|
||||
stream
|
||||
;;
|
||||
history)
|
||||
stmt="SELECT DISTINCT anime_name FROM watch_history ORDER BY watch_date DESC"
|
||||
@ -921,24 +913,24 @@ case $scrape in
|
||||
play_file "$video_path"
|
||||
exit $?
|
||||
;;
|
||||
esac
|
||||
esac
|
||||
|
||||
check_input
|
||||
check_input
|
||||
|
||||
# plays selected episode(s)
|
||||
for ep in $episodes; do
|
||||
# plays selected episode(s)
|
||||
for ep in $episodes; do
|
||||
open_episode "$selection_id" "$ep" "$download_dir"
|
||||
done
|
||||
done
|
||||
|
||||
if [[ "$is_download" -eq 1 ]]; then
|
||||
if [[ "$is_download" -eq 1 ]]; then
|
||||
logger "Finished downloading episodes: $episodes for $selection_id... exiting"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
episode=${ep_choice_end:-$ep_choice_start}
|
||||
episode=${ep_choice_end:-$ep_choice_start}
|
||||
|
||||
choice=''
|
||||
while :; do
|
||||
choice=''
|
||||
while :; do
|
||||
printf "\n${c_green}Currently playing %s episode ${c_cyan}%d/%d\n" "$selection_id" $episode $last_ep_number
|
||||
if [ "$episode" -ne "$last_ep_number" ]; then
|
||||
printf "$c_blue[${c_cyan}%s$c_blue] $c_yellow%s$c_reset\n" "n" "next episode"
|
||||
@ -994,4 +986,9 @@ while :; do
|
||||
;;
|
||||
esac
|
||||
open_episode "$selection_id" "$episode" "$download_dir"
|
||||
done
|
||||
done
|
||||
}
|
||||
|
||||
dep_ch "$player_fn" "curl" "sed" "grep" "sqlite3" "rofi" "git" "aria2c" "jq"
|
||||
parse_args "$@"
|
||||
main
|
||||
|
Loading…
Reference in New Issue
Block a user