diff --git a/Makefile b/Makefile
index 90b09e5..8165214 100644
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,4 @@ ifneq ("$(wildcard $(DESTDIR)$(PREFIX)/bin/aniwrapper)","")
$(RM) $(DESTDIR)$(PREFIX)/bin/aniwrapper
endif
-reinstall: uninstall install
-
-.PHONY: all install uninstall dev reinstall
-
+.PHONY: all install uninstall dev
diff --git a/README.md b/README.md
index 8a67ecb..a993d5d 100644
--- a/README.md
+++ b/README.md
@@ -146,7 +146,7 @@ In this program, rofi is configured to search with case insensitivity and select
Once your history starts filling up, it becomes progressively more difficult to form unique search queries
![selection with dash](https://imgur.com/vSyaoG6.png)
-The workaround for this is to prepend a dash ` -` to the search query
+The workaround for this is to append a dash ` -` to the end of the search query
The above output was produced by searching: `isekai -`
@@ -189,6 +189,9 @@ aniwrapper -v
# Connect to history database
aniwrapper -C
+# Enable silent mode (suppress output to stdout) [cannot be used with -v]
+aniwrapper -S
+
# Query the history database
aniwrapper -Q
diff --git a/ani-cli b/ani-cli
index 290d588..b046a20 100755
--- a/ani-cli
+++ b/ani-cli
@@ -10,6 +10,7 @@ ANIWRAPPER_ICON_PATH="$CFG_DIR/icons/icon-64.png"
MAISAN_ICON_PATH="$CFG_DIR/icons/MYsan.png"
DPI=96
VERBOSE=0
+SILENT=0
player_fn="mpv"
playable="\.mp4|\.mkv|\.ts|\.mp3|\.webm"
@@ -34,17 +35,17 @@ help_text() {
}
die() {
- printf "$c_red%s$c_reset\n" "$*" >&2
+ ((SILENT != 1)) && printf "$c_red%s$c_reset\n" "$*" >&2
exit 1
}
err() {
- printf "$c_red%s$c_reset\n" "$*" >&2
+ ((SILENT != 1)) && printf "$c_red%s$c_reset\n" "$*" >&2
}
+# prints passed in args to stdout if $VERBOSE is set to 1
lg() {
- # prints passed in args to stdout if $VERBOSE is set to 1
- [ "$VERBOSE" -eq 1 ] && printf "%s\n" "$*" >&2
+ ((VERBOSE == 1)) && printf "%s\n" "$*" >&2
}
check_input() {
@@ -679,7 +680,7 @@ open_episode() {
if command -v "notify-send" > /dev/null; then
notify-send -i "$ANIWRAPPER_ICON_PATH" "Playing $anime_id - Episode $episode"
else
- printf "${c_green}\nVideo playing"
+ ((SILENT != 1)) && printf "${c_green}\nVideo playing"
fi
else
lg "Downloading episode $episode ..."
@@ -696,9 +697,9 @@ open_episode() {
fi
else
if aria2c -x 16 -s 16 --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
- 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
}
@@ -744,7 +745,7 @@ parse_args() {
is_download=0
download_dir="."
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
h)
help_text
@@ -833,6 +834,9 @@ parse_args() {
D)
DPI="$OPTARG"
;;
+ S)
+ SILENT=1
+ ;;
*)
printf "%s\n" "Invalid option"
exit 1
@@ -930,66 +934,67 @@ main() {
exit 0
fi
- episode=${ep_choice_end:-$ep_choice_start}
+ if ((SILENT != 1)); then
+ 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
- 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"
+ case $choice in
+ n)
+ episode=$((episode + 1))
+ ;;
+ p)
+ episode=$((episode - 1))
+ ;;
- printf "$c_reset"
- case $choice in
- n)
- episode=$((episode + 1))
- ;;
- p)
- episode=$((episode - 1))
- ;;
+ s)
+ printf "${c_blue}Choose episode $c_cyan[1-%d]$c_reset:$c_green " "$last_ep_number"
+ read -r episode
+ if [ "$(echo "$episode" | cut -c1-1)" = "h" ]; then
+ half_ep=1
+ episode=$(echo "$episode" | cut -c2-)
+ fi
+ printf "$c_reset"
+ [ "$episode" -eq "$episode" ] 2> /dev/null || die "Invalid number entered"
+ ;;
- s)
- printf "${c_blue}Choose episode $c_cyan[1-%d]$c_reset:$c_green " "$last_ep_number"
- read -r episode
- if [ "$(echo "$episode" | cut -c1-1)" = "h" ]; then
- half_ep=1
- episode=$(echo "$episode" | cut -c2-)
- fi
- printf "$c_reset"
- [ "$episode" -eq "$episode" ] 2> /dev/null || die "Invalid number entered"
- ;;
+ r)
+ episode=$((episode))
+ ;;
+ a)
+ stream
+ episode=$ep_choice_start
+ lg "NEW EPISODE: $selection_id - $episode"
+ ;;
- r)
- episode=$((episode))
- ;;
- a)
- stream
- episode=$ep_choice_start
- lg "NEW EPISODE: $selection_id - $episode"
- ;;
+ q)
+ break
+ ;;
- q)
- break
- ;;
-
- *)
- die "invalid choice"
- ;;
- esac
- open_episode "$selection_id" "$episode" "$download_dir"
- done
+ *)
+ die "invalid choice"
+ ;;
+ esac
+ open_episode "$selection_id" "$episode" "$download_dir"
+ done
+ fi
}
dep_ch "$player_fn" "curl" "sed" "grep" "sqlite3" "rofi" "git" "aria2c"
diff --git a/aniwrapper b/aniwrapper
index 021ee09..ed5ae3c 100755
--- a/aniwrapper
+++ b/aniwrapper
@@ -20,6 +20,7 @@ IS_DOWNLOAD=0
IS_PLAY_FROM_FILE=0
IS_ROFI=1
VERBOSE=0
+SILENT=0
quit="6. Quit"
options="1. Stream|2. Download|3. Continue|4. Play from File|5. Sync History|$quit"
@@ -33,8 +34,8 @@ help_text() {
printf "%s\n" "$line"
done <<< "
Usage:
- aniwrapper [-cdhvq] [-t or -T ]
- aniwrapper [-cv] [-t or -T ] -f
+ aniwrapper [-cdhvqS] [-t or -T ]
+ aniwrapper [-cvS] [-t or -T ] -f
aniwrapper -Q
aniwrapper -C
Options:
@@ -43,6 +44,7 @@ Options:
-c enable command-line mode (rofi disabled)
-d download episode in command-line mode
-C connect to history database
+ -S silent mode (suppress output to stdout) [cannot be used with -v]
-t change rofi theme
-T specify custom rofi theme
@@ -52,7 +54,7 @@ Options:
}
lg() {
- if [[ "$VERBOSE" -eq 1 ]]; then
+ if ((VERBOSE == 1)); then
printf "%s\n" "$*"
fi
}
@@ -68,22 +70,33 @@ quit() {
}
run() {
- if [[ "$IS_PLAY_FROM_FILE" -eq 0 ]] && [[ "$GET_QUALITY" -eq 1 ]]; then
+ if ((IS_PLAY_FROM_FILE == 0 && GET_QUALITY == 1)); then
get_quality
fi
- if [[ "$IS_CUSTOM_THEME" -eq 1 ]] && [[ "$VERBOSE" -eq 0 ]]; then
- "$CMD" -D"$DPI" -q "$QUALITY" -T "$CFG_FILE" "$@"
- elif [[ "$IS_CUSTOM_THEME" -eq 1 ]] && [[ "$VERBOSE" -eq 1 ]]; then
- "$CMD" -D"$DPI" -vq "$QUALITY" -T "$CFG_FILE" "$@"
- elif [[ "$VERBOSE" -eq 0 ]]; then
- "$CMD" -D"$DPI" -q "$QUALITY" -t "$theme" "$@"
+
+ if ((SILENT == 1)); then
+ if ((IS_CUSTOM_THEME == 0)); then
+ "$CMD" -D"$DPI" -Sq "$QUALITY" -t "$theme" "$@"
+ else
+ "$CMD" -D"$DPI" -Sq "$QUALITY" -T "$CFG_FILE" "$@"
+ 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
- "$CMD" -D"$DPI" -vq "$QUALITY" -t "$theme" "$@"
+ if ((IS_CUSTOM_THEME == 0)); then
+ "$CMD" -D"$DPI" -q "$QUALITY" -t "$theme" "$@"
+ else
+ "$CMD" -D"$DPI" -q "$QUALITY" -T "$CFG_FILE" "$@"
+ fi
fi
}
get_quality() {
- if [ "$IS_ROFI" -eq 1 ]; then
+ if ((IS_ROFI == 1)); then
selection=$(rofi -dpi "$DPI" -dmenu -config "$CFG_FILE" \
-l 5 -selected-row 0 \
-theme-str 'listview {columns: 1;}' -p "Choose video quality:" \
@@ -105,7 +118,7 @@ generate_span() {
}
parse_args() {
- while getopts 'vhqcdf:-:t:T:CQ:D:' OPT; do
+ while getopts 'vhqcdf:-:t:T:CQ:D:S' OPT; do
case "$OPT" in
h)
help_text
@@ -186,6 +199,9 @@ parse_args() {
D)
DPI="$OPTARG"
;;
+ S)
+ SILENT=1
+ ;;
*)
help_text
exit 1
@@ -197,10 +213,13 @@ parse_args() {
check_flags() {
# Check if command-line flag is set
- if [[ "$IS_ROFI" -eq 0 ]] && [[ "$IS_DOWNLOAD" -eq 0 ]]; then
+ if ((VERBOSE == 1 && SILENT == 1)); then
+ seppuku "verbose and silent options cannot be used together"
+ fi
+ if ((IS_ROFI == 0 && IS_DOWNLOAD == 0)); then
run -c
exit $?
- elif [[ "$IS_ROFI" -eq 0 ]] && [[ "$IS_DOWNLOAD" -eq 1 ]]; then
+ elif ((IS_ROFI == 0 && IS_DOWNLOAD == 1)); then
printf "%s" "Enter download dir: "
read -r dl_dir
lg "Download dir: $dl_dir"
@@ -209,10 +228,10 @@ check_flags() {
fi
run "-cd $dl_dir"
exit $?
- elif [[ "$IS_ROFI" -eq 1 ]] && [[ "$IS_PLAY_FROM_FILE" -eq 1 ]] && [[ "$IS_CUSTOM_THEME" -eq 1 ]]; then
+ elif ((IS_ROFI == 1 && IS_PLAY_FROM_FILE == 1 && IS_CUSTOM_THEME == 1)); then
run "-f$play_path" -T "$CFG_FILE"
exit $?
- elif [[ "$IS_ROFI" -eq 1 ]] && [[ "$IS_PLAY_FROM_FILE" -eq 1 ]] && [[ "$IS_CUSTOM_THEME" -eq 0 ]]; then
+ elif ((IS_ROFI == 1 && IS_PLAY_FROM_FILE == 1 && IS_CUSTOM_THEME == 0)); then
run "-f$play_path" -t "$theme"
exit $?
fi