add silent mode option

This commit is contained in:
ksyasuda 2022-01-29 01:01:37 -08:00
parent 2d9c070374
commit baeadacae6

23
ani-cli
View File

@ -11,6 +11,7 @@ ANIWRAPPER_ICON_PATH="$CFG_DIR/icons/icon-64.png"
MAISAN_ICON_PATH="$CFG_DIR/icons/MYsan.png" MAISAN_ICON_PATH="$CFG_DIR/icons/MYsan.png"
DPI=96 DPI=96
VERBOSE=0 VERBOSE=0
SILENT=0
player_fn="mpv" player_fn="mpv"
playable="\.mp4|\.mkv|\.ts|\.mp3|\.webm" playable="\.mp4|\.mkv|\.ts|\.mp3|\.webm"
@ -36,17 +37,17 @@ help_text() {
} }
die() { die() {
printf "$c_red%s$c_reset\n" "$*" >&2 ((SILENT != 1)) && printf "$c_red%s$c_reset\n" "$*" >&2
exit 1 exit 1
} }
err() { err() {
printf "$c_red%s$c_reset\n" "$*" >&2 ((SILENT != 1)) && printf "$c_red%s$c_reset\n" "$*" >&2
} }
lg() {
# prints passed in args to stdout if $VERBOSE is set to 1 # prints passed in args to stdout if $VERBOSE is set to 1
[ "$VERBOSE" -eq 1 ] && printf "%s\n" "$*" >&2 lg() {
((VERBOSE == 1)) && printf "%s\n" "$*" >&2
} }
check_input() { check_input() {
@ -678,7 +679,7 @@ open_episode() {
if command -v "notify-send" > /dev/null; then if command -v "notify-send" > /dev/null; then
notify-send -i "$ANIWRAPPER_ICON_PATH" "Playing $anime_id - Episode $episode" notify-send -i "$ANIWRAPPER_ICON_PATH" "Playing $anime_id - Episode $episode"
else else
printf "${c_green}\nVideo playing" ((SILENT != 1)) && printf "${c_green}\nVideo playing"
fi fi
else else
lg "Downloading episode $episode ..." lg "Downloading episode $episode ..."
@ -695,9 +696,9 @@ open_episode() {
fi fi
else else
if aria2c --referer="$dpage_link" "$video_url" --dir="$dl_dir" -o "$episode.mp4" --download-result=hide; then 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" ((SILENT != 1)) && printf "${c_green}Downloaded complete for %s - Episode: %s${c_reset}\n" "${anime_id//-/ }" "$episode"
else else
printf "${c_red}Download failed for %s - Episode: %s, please retry or check your internet connection${c_reset}\n" "${anime_id//-/ }" "$episode" ((SILENT != 1)) && 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 fi
} }
@ -743,7 +744,7 @@ parse_args() {
is_download=0 is_download=0
download_dir="." download_dir="."
half_ep=0 half_ep=0
while getopts 'hd:Hsvq:cf:t:T:CQ:D:' OPT; do while getopts 'hd:Hsvq:cf:t:T:CQ:D:S' OPT; do
case "$OPT" in case "$OPT" in
h) h)
help_text help_text
@ -832,6 +833,9 @@ parse_args() {
D) D)
DPI="$OPTARG" DPI="$OPTARG"
;; ;;
S)
SILENT=1
;;
*) *)
printf "%s\n" "Invalid option" printf "%s\n" "Invalid option"
exit 1 exit 1
@ -927,8 +931,8 @@ main() {
exit 0 exit 0
fi fi
if ((SILENT != 1)); then
episode=${ep_choice_end:-$ep_choice_start} episode=${ep_choice_end:-$ep_choice_start}
choice='' choice=''
while :; do while :; do
printf "\n${c_green}Currently playing %s episode ${c_cyan}%d/%d\n" "$selection_id" $episode $last_ep_number printf "\n${c_green}Currently playing %s episode ${c_cyan}%d/%d\n" "$selection_id" $episode $last_ep_number
@ -987,6 +991,7 @@ main() {
esac esac
open_episode "$selection_id" "$episode" "$download_dir" open_episode "$selection_id" "$episode" "$download_dir"
done done
fi
} }
dep_ch "$player_fn" "curl" "sed" "grep" "sqlite3" "rofi" "git" "aria2c" dep_ch "$player_fn" "curl" "sed" "grep" "sqlite3" "rofi" "git" "aria2c"