Compare commits

..

No commits in common. "baeadacae68635b149543a2c7952ea771c307908" and "b07948cee221b05b531c6804cd932334bfd7744d" have entirely different histories.

2 changed files with 78 additions and 101 deletions

131
ani-cli
View File

@ -11,7 +11,6 @@ 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"
@ -37,17 +36,17 @@ help_text() {
} }
die() { die() {
((SILENT != 1)) && printf "$c_red%s$c_reset\n" "$*" >&2 printf "$c_red%s$c_reset\n" "$*" >&2
exit 1 exit 1
} }
err() { err() {
((SILENT != 1)) && printf "$c_red%s$c_reset\n" "$*" >&2 printf "$c_red%s$c_reset\n" "$*" >&2
} }
# prints passed in args to stdout if $VERBOSE is set to 1
lg() { lg() {
((VERBOSE == 1)) && printf "%s\n" "$*" >&2 # prints passed in args to stdout if $VERBOSE is set to 1
[ "$VERBOSE" -eq 1 ] && printf "%s\n" "$*" >&2
} }
check_input() { check_input() {
@ -679,7 +678,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
((SILENT != 1)) && printf "${c_green}\nVideo playing" printf "${c_green}\nVideo playing"
fi fi
else else
lg "Downloading episode $episode ..." lg "Downloading episode $episode ..."
@ -696,9 +695,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
((SILENT != 1)) && printf "${c_green}Downloaded complete for %s - Episode: %s${c_reset}\n" "${anime_id//-/ }" "$episode" printf "${c_green}Downloaded complete for %s - Episode: %s${c_reset}\n" "${anime_id//-/ }" "$episode"
else else
((SILENT != 1)) && printf "${c_red}Download failed for %s - Episode: %s, please retry or check your internet connection${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"
fi fi
fi fi
} }
@ -744,7 +743,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:S' OPT; do while getopts 'hd:Hsvq:cf:t:T:CQ:D:' OPT; do
case "$OPT" in case "$OPT" in
h) h)
help_text help_text
@ -833,9 +832,6 @@ 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
@ -931,67 +927,66 @@ 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=''
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"
fi
if [ "$episode" -ne "1" ]; then
printf "$c_blue[${c_cyan}%s$c_blue] $c_magenta%s$c_reset\n" "p" "previous episode"
fi
if [ "$last_ep_number" -ne "1" ]; then
printf "$c_blue[${c_cyan}%s$c_blue] $c_yellow%s$c_reset\n" "s" "select episode"
fi
printf "$c_blue[${c_cyan}%s$c_blue] $c_magenta%s$c_reset\n" "r" "replay current episode"
printf "$c_blue[${c_cyan}%s$c_blue] $c_yellow%s$c_reset\n" "a" "search for another anime"
# printf "$c_blue[${c_cyan}%s$c_blue] $c_magenta%s$c_reset\n" "h" "search history"
printf "$c_blue[${c_cyan}%s$c_blue] $c_red%s$c_reset\n" "q" "exit"
printf "${c_blue}Enter choice:${c_green} "
read -r choice
printf "$c_reset" choice=''
case $choice in while :; do
n) printf "\n${c_green}Currently playing %s episode ${c_cyan}%d/%d\n" "$selection_id" $episode $last_ep_number
episode=$((episode + 1)) if [ "$episode" -ne "$last_ep_number" ]; then
;; printf "$c_blue[${c_cyan}%s$c_blue] $c_yellow%s$c_reset\n" "n" "next episode"
p) fi
episode=$((episode - 1)) if [ "$episode" -ne "1" ]; then
;; printf "$c_blue[${c_cyan}%s$c_blue] $c_magenta%s$c_reset\n" "p" "previous episode"
fi
if [ "$last_ep_number" -ne "1" ]; then
printf "$c_blue[${c_cyan}%s$c_blue] $c_yellow%s$c_reset\n" "s" "select episode"
fi
printf "$c_blue[${c_cyan}%s$c_blue] $c_magenta%s$c_reset\n" "r" "replay current episode"
printf "$c_blue[${c_cyan}%s$c_blue] $c_yellow%s$c_reset\n" "a" "search for another anime"
# printf "$c_blue[${c_cyan}%s$c_blue] $c_magenta%s$c_reset\n" "h" "search history"
printf "$c_blue[${c_cyan}%s$c_blue] $c_red%s$c_reset\n" "q" "exit"
printf "${c_blue}Enter choice:${c_green} "
read -r choice
s) printf "$c_reset"
printf "${c_blue}Choose episode $c_cyan[1-%d]$c_reset:$c_green " "$last_ep_number" case $choice in
read -r episode n)
if [ "$(echo "$episode" | cut -c1-1)" = "h" ]; then episode=$((episode + 1))
half_ep=1 ;;
episode=$(echo "$episode" | cut -c2-) p)
fi episode=$((episode - 1))
printf "$c_reset" ;;
[ "$episode" -eq "$episode" ] 2> /dev/null || die "Invalid number entered"
;;
r) s)
episode=$((episode)) printf "${c_blue}Choose episode $c_cyan[1-%d]$c_reset:$c_green " "$last_ep_number"
;; read -r episode
a) if [ "$(echo "$episode" | cut -c1-1)" = "h" ]; then
stream half_ep=1
episode=$ep_choice_start episode=$(echo "$episode" | cut -c2-)
lg "NEW EPISODE: $selection_id - $episode" fi
;; printf "$c_reset"
[ "$episode" -eq "$episode" ] 2> /dev/null || die "Invalid number entered"
;;
q) r)
break episode=$((episode))
;; ;;
a)
stream
episode=$ep_choice_start
lg "NEW EPISODE: $selection_id - $episode"
;;
*) q)
die "invalid choice" break
;; ;;
esac
open_episode "$selection_id" "$episode" "$download_dir" *)
done die "invalid choice"
fi ;;
esac
open_episode "$selection_id" "$episode" "$download_dir"
done
} }
dep_ch "$player_fn" "curl" "sed" "grep" "sqlite3" "rofi" "git" "aria2c" dep_ch "$player_fn" "curl" "sed" "grep" "sqlite3" "rofi" "git" "aria2c"

View File

@ -20,7 +20,6 @@ IS_DOWNLOAD=0
IS_PLAY_FROM_FILE=0 IS_PLAY_FROM_FILE=0
IS_ROFI=1 IS_ROFI=1
VERBOSE=0 VERBOSE=0
SILENT=0
quit="6. Quit" quit="6. Quit"
options="1. Stream|2. Download|3. Continue|4. Play from File|5. Sync History|$quit" options="1. Stream|2. Download|3. Continue|4. Play from File|5. Sync History|$quit"
@ -53,7 +52,7 @@ Options:
} }
lg() { lg() {
if ((VERBOSE == 1)); then if [[ "$VERBOSE" -eq 1 ]]; then
printf "%s\n" "$*" printf "%s\n" "$*"
fi fi
} }
@ -69,33 +68,22 @@ quit() {
} }
run() { run() {
if ((IS_PLAY_FROM_FILE == 0 && GET_QUALITY == 1)); then if [[ "$IS_PLAY_FROM_FILE" -eq 0 ]] && [[ "$GET_QUALITY" -eq 1 ]]; then
get_quality get_quality
fi fi
if [[ "$IS_CUSTOM_THEME" -eq 1 ]] && [[ "$VERBOSE" -eq 0 ]]; then
if ((SILENT == 1)); then "$CMD" -D"$DPI" -q "$QUALITY" -T "$CFG_FILE" "$@"
if ((IS_CUSTOM_THEME == 0)); then elif [[ "$IS_CUSTOM_THEME" -eq 1 ]] && [[ "$VERBOSE" -eq 1 ]]; then
"$CMD" -D"$DPI" -Sq "$QUALITY" -t "$theme" "$@" "$CMD" -D"$DPI" -vq "$QUALITY" -T "$CFG_FILE" "$@"
else elif [[ "$VERBOSE" -eq 0 ]]; then
"$CMD" -D"$DPI" -Sq "$QUALITY" -T "$CFG_FILE" "$@" "$CMD" -D"$DPI" -q "$QUALITY" -t "$theme" "$@"
fi
elif ((VERBOSE == 1)); then
if ((IS_CUSTOM_THEME == 0)); then
"$CMD" -D"$DPI" -vq "$QUALITY" -t "$theme" "$@"
else
"$CMD" -D"$DPI" -vq "$QUALITY" -T "$CFG_FILE" "$@"
fi
else else
if ((IS_CUSTOM_THEME == 0)); then "$CMD" -D"$DPI" -vq "$QUALITY" -t "$theme" "$@"
"$CMD" -D"$DPI" -q "$QUALITY" -t "$theme" "$@"
else
"$CMD" -D"$DPI" -q "$QUALITY" -T "$CFG_FILE" "$@"
fi
fi fi
} }
get_quality() { get_quality() {
if ((IS_ROFI == 1)); then if [ "$IS_ROFI" -eq 1 ]; then
selection=$(rofi -dpi "$DPI" -dmenu -config "$CFG_FILE" \ selection=$(rofi -dpi "$DPI" -dmenu -config "$CFG_FILE" \
-l 5 -selected-row 0 \ -l 5 -selected-row 0 \
-theme-str 'listview {columns: 1;}' -p "Choose video quality:" \ -theme-str 'listview {columns: 1;}' -p "Choose video quality:" \
@ -117,7 +105,7 @@ generate_span() {
} }
parse_args() { parse_args() {
while getopts 'vhqcdf:-:t:T:CQ:D:S' OPT; do while getopts 'vhqcdf:-:t:T:CQ:D:' OPT; do
case "$OPT" in case "$OPT" in
h) h)
help_text help_text
@ -198,9 +186,6 @@ parse_args() {
D) D)
DPI="$OPTARG" DPI="$OPTARG"
;; ;;
S)
SILENT=1
;;
*) *)
help_text help_text
exit 1 exit 1
@ -212,13 +197,10 @@ parse_args() {
check_flags() { check_flags() {
# Check if command-line flag is set # Check if command-line flag is set
if ((VERBOSE == 1 && SILENT == 1)); then if [[ "$IS_ROFI" -eq 0 ]] && [[ "$IS_DOWNLOAD" -eq 0 ]]; then
seppuku "verbose and silent options cannot be used together"
fi
if ((IS_ROFI == 0 && IS_DOWNLOAD == 0)); then
run -c run -c
exit $? exit $?
elif ((IS_ROFI == 0 && IS_DOWNLOAD == 1)); then elif [[ "$IS_ROFI" -eq 0 ]] && [[ "$IS_DOWNLOAD" -eq 1 ]]; then
printf "%s" "Enter download dir: " printf "%s" "Enter download dir: "
read -r dl_dir read -r dl_dir
lg "Download dir: $dl_dir" lg "Download dir: $dl_dir"
@ -227,10 +209,10 @@ check_flags() {
fi fi
run "-cd $dl_dir" run "-cd $dl_dir"
exit $? exit $?
elif ((IS_ROFI == 1 && IS_PLAY_FROM_FILE == 1 && IS_CUSTOM_THEME == 1)); then elif [[ "$IS_ROFI" -eq 1 ]] && [[ "$IS_PLAY_FROM_FILE" -eq 1 ]] && [[ "$IS_CUSTOM_THEME" -eq 1 ]]; then
run "-f$play_path" -T "$CFG_FILE" run "-f$play_path" -T "$CFG_FILE"
exit $? exit $?
elif ((IS_ROFI == 1 && IS_PLAY_FROM_FILE == 1 && IS_CUSTOM_THEME == 0)); then elif [[ "$IS_ROFI" -eq 1 ]] && [[ "$IS_PLAY_FROM_FILE" -eq 1 ]] && [[ "$IS_CUSTOM_THEME" -eq 0 ]]; then
run "-f$play_path" -t "$theme" run "-f$play_path" -t "$theme"
exit $? exit $?
fi fi