Compare commits

..

3 Commits

Author SHA1 Message Date
ksyasuda
24f3c25142 update quality selection menu 2022-02-03 15:25:15 -08:00
ksyasuda
985a19fcf0 standardize how insert_history function works 2022-02-03 15:18:04 -08:00
ksyasuda
a8a32968da highlight and print out current quality when seleting new quality 2022-02-03 15:10:07 -08:00
2 changed files with 56 additions and 50 deletions

102
ani-cli
View File

@ -156,23 +156,13 @@ run_stmt() {
# Return number of matches for anime/episode in db # Return number of matches for anime/episode in db
check_db() { check_db() {
if [[ "$1" == "directory" ]]; then if [[ "$1" == "directory" ]]; then
stmt="SELECT DISTINCT COUNT(*) \ stmt="SELECT DISTINCT COUNT(*) FROM file_history WHERE directory = '$2';"
FROM file_history \
WHERE directory = '$2';"
elif [[ "$1" == "file" ]]; then elif [[ "$1" == "file" ]]; then
stmt="SELECT DISTINCT COUNT(*) \ stmt="SELECT DISTINCT COUNT(*) FROM file_history WHERE directory = '$2' AND filename = '$3';"
FROM file_history \
WHERE directory = '$2' \
AND filename = '$3';"
elif [[ "$2" == "search" ]]; then elif [[ "$2" == "search" ]]; then
stmt="SELECT DISTINCT COUNT(*) \ stmt="SELECT DISTINCT COUNT(*) FROM search_history WHERE anime_name = '$1';"
FROM search_history \
WHERE anime_name = '$1';"
else else
stmt="SELECT DISTINCT COUNT(*) \ stmt="SELECT DISTINCT COUNT(*) FROM watch_history WHERE anime_name = '$1' AND episode_number = '$2';"
FROM watch_history \
WHERE anime_name = '$1' \
AND episode_number = '$2';"
fi fi
res=$(run_stmt "$stmt") res=$(run_stmt "$stmt")
return $res return $res
@ -195,16 +185,13 @@ update_date() {
stmt="" stmt=""
if [[ "$1" == "directory" ]]; then if [[ "$1" == "directory" ]]; then
lg "UPDATING FILE_HISTORY: directory='$2', filename='DIRECTORY', search_date='$datetime'" lg "UPDATING FILE_HISTORY: directory='$2', filename='DIRECTORY', search_date='$datetime'"
stmt="UPDATE file_history SET watch_date = '$datetime' \ stmt="UPDATE file_history SET watch_date = '$datetime' WHERE directory = '$2' and filename = '$3';"
WHERE directory = '$2' and filename = '$3';"
elif [[ "$1" == "file" ]]; then elif [[ "$1" == "file" ]]; then
lg "UPDATING FILE_HISTORY: directory='$2', filename='$3', search_date='$datetime'" lg "UPDATING FILE_HISTORY: directory='$2', filename='$3', search_date='$datetime'"
stmt="UPDATE file_history SET watch_date = '$datetime' \ stmt="UPDATE file_history SET watch_date = '$datetime' WHERE directory = '$2' and filename = '$3';"
WHERE directory = '$2' and filename = '$3';"
elif [[ "$2" == "search" ]]; then elif [[ "$2" == "search" ]]; then
lg "UPDATING SEARCH_HISTORY: anime_name='$1', search_date='$datetime'" lg "UPDATING SEARCH_HISTORY: anime_name='$1', search_date='$datetime'"
stmt="UPDATE search_history SET search_date = '$datetime' \ stmt="UPDATE search_history SET search_date = '$datetime' WHERE anime_name = '$1';"
WHERE anime_name = '$1';"
elif [[ $# -ge 3 ]]; then elif [[ $# -ge 3 ]]; then
temp_dt="${3// /:}" temp_dt="${3// /:}"
[ -z "$temp_dt" ] && return 1 [ -z "$temp_dt" ] && return 1
@ -216,14 +203,10 @@ update_date() {
return 1 return 1
fi fi
lg "UPDATING watch_history from sync. watch_date -> $temp_dt" lg "UPDATING watch_history from sync. watch_date -> $temp_dt"
stmt="UPDATE watch_history SET watch_date = '$temp_dt' \ stmt="UPDATE watch_history SET watch_date = '$temp_dt' WHERE anime_name = '$1' AND episode_number = $2;"
WHERE anime_name = '$1' \
AND episode_number = $2;"
else else
lg "UPDATING WATCH_HISTORY: anime_name='$1', episode_number='$2' search_date='$datetime'" lg "UPDATING WATCH_HISTORY: anime_name='$1', episode_number='$2' search_date='$datetime'"
stmt="UPDATE watch_history SET watch_date = '$datetime' \ stmt="UPDATE watch_history SET watch_date = '$datetime' WHERE anime_name = '$1' AND episode_number = $2;"
WHERE anime_name = '$1' \
AND episode_number = $2;"
fi fi
wait # in case there's another insert/update still running in background? wait # in case there's another insert/update still running in background?
run_stmt "$stmt" run_stmt "$stmt"
@ -242,20 +225,23 @@ insert_history() {
res=$? res=$?
else else
lg "Row not found in DB... inserting" lg "Row not found in DB... inserting"
if [[ "$1" == "directory" ]]; then case "$1" in
stmt="INSERT INTO file_history(directory, filename, watch_date) \ directory)
VALUES('$2', 'DIRECTORY', '$datetime');" stmt="INSERT INTO file_history(directory, filename, watch_date) VALUES('$2', 'DIRECTORY', '$datetime');"
elif [[ "$1" == "file" ]]; then ;;
stmt="INSERT INTO file_history(directory, filename, watch_date) \ file)
VALUES('$2', '$3', '$datetime');" stmt="INSERT INTO file_history(directory, filename, watch_date) VALUES('$2', '$3', '$datetime');"
elif [[ "$2" == "search" ]]; then ;;
stmt="INSERT INTO search_history(anime_name, search_date) \ search)
VALUES('$1', '$datetime');" stmt="INSERT INTO search_history(anime_name, search_date) VALUES('$2', '$datetime');"
else ;;
stmt="INSERT INTO \ watch)
watch_history(anime_name, episode_number, watch_date) \ stmt="INSERT INTO watch_history(anime_name, episode_number, watch_date) VALUES('$2', '$3', '$datetime');"
VALUES('$1', '$2', '$datetime');" ;;
fi sync)
stmt="INSERT INTO watch_history(anime_name, episode_number, watch_date) VALUES('$2', '$3', '$4');"
;;
esac
lg "INSERT STATEMENT -> $stmt" lg "INSERT STATEMENT -> $stmt"
wait # in case there's another insert/update still running in background wait # in case there's another insert/update still running in background
run_stmt "$stmt" run_stmt "$stmt"
@ -292,7 +278,7 @@ sync_watch_history() {
while read -r ep; do while read -r ep; do
episode_num=$(awk -F '|' '{print $1}' <<< "$ep") episode_num=$(awk -F '|' '{print $1}' <<< "$ep")
watch_date=$(awk -F '|' '{print $NF}' <<< "$ep") watch_date=$(awk -F '|' '{print $NF}' <<< "$ep")
if ! insert_history "$anime_name" "$episode_num" "$watch_date"; then if ! insert_history "sync" "$anime_name" "$episode_num" "$watch_date"; then
((++errs)) ((++errs))
continue continue
fi fi
@ -560,7 +546,7 @@ anime_selection() {
[ -z "$name" ] && name="$anime_id" [ -z "$name" ] && name="$anime_id"
[ -z "$selection_id" ] && die "Invalid number entered" [ -z "$selection_id" ] && die "Invalid number entered"
insert_history "$name" "search" & insert_history "search" "$name" &
read -r last_ep_number <<- EOF read -r last_ep_number <<- EOF
$(search_eps "$selection_id") $(search_eps "$selection_id")
@ -640,7 +626,7 @@ open_episode() {
# Don't update watch history if downloading episode # Don't update watch history if downloading episode
if [ "$is_download" -eq 0 ]; then if [ "$is_download" -eq 0 ]; then
insert_history "$anime_id" "$episode" & insert_history "watch" "$anime_id" "$episode" &
fi fi
dpage_link=$(get_dpage_link "$anime_id" "$episode") dpage_link=$(get_dpage_link "$anime_id" "$episode")
@ -713,7 +699,7 @@ stream() {
# skip search_anime function and assign $query # skip search_anime function and assign $query
anime_id="${query// /}" anime_id="${query// /}"
selection_id="$anime_id" selection_id="$anime_id"
insert_history "$anime_id" "search" & insert_history "search" "$anime_id" &
read -r last_ep_number <<< "$(search_eps "$selection_id")" read -r last_ep_number <<< "$(search_eps "$selection_id")"
fi fi
episode_selection episode_selection
@ -933,7 +919,7 @@ main() {
fi 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_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_yellow%s$c_reset\n" "a" "search for another anime"
printf "$c_blue[${c_cyan}%s$c_blue] $c_magenta%s$c_reset\n" "Q" "change video quality" printf "$c_blue[${c_cyan}%s$c_blue] $c_magenta%s$c_reset\n" "Q" "change video quality (current: $quality)"
printf "$c_blue[${c_cyan}%s$c_blue] $c_red%s$c_reset\n" "q" "exit" printf "$c_blue[${c_cyan}%s$c_blue] $c_red%s$c_reset\n" "q" "exit"
printf "${c_blue}Enter choice:${c_green} " printf "${c_blue}Enter choice:${c_green} "
read -r choice read -r choice
@ -961,13 +947,33 @@ main() {
lg "NEW EPISODE: $selection_id - $episode" lg "NEW EPISODE: $selection_id - $episode"
;; ;;
Q) Q)
qualities="best|1080p|720p|480p|360p|worst"
if ((IS_ROFI == 1)); then if ((IS_ROFI == 1)); then
case "$quality" in
best)
cur_quality=0
;;
1080p)
cur_quality=1
;;
720p)
cur_quality=2
;;
360p)
cur_quality=3
;;
worst)
cur_quality=4
;;
*)
cur_quality=0
;;
esac
choice=$(rofi -dmenu -dpi "$DPI" -config "$ROFI_CFG" \ choice=$(rofi -dmenu -dpi "$DPI" -config "$ROFI_CFG" \
-i -l 5 -only-match -sep '|' \ -i -l 5 -only-match -sep '|' -a "$cur_quality" -mesg "$(generate_span "Current quality: $quality")" \
-p "Choose quality:" <<< "1. best (default)|2. 1080p|3. 720p|4. 360p|5. worst") -p "Choose quality:" <<< "1. best|2. 1080p|3. 720p|4. 360p|5. worst")
quality=$(awk '{ print $2 }' <<< "$choice") quality=$(awk '{ print $2 }' <<< "$choice")
else else
qualities="best|1080p|720p|480p|360p|worst"
printf "${c_blue}Choose quality: [$qualities]:$c_reset " printf "${c_blue}Choose quality: [$qualities]:$c_reset "
read -r quality read -r quality
while [[ ! "$quality" =~ ($qualities) ]]; do while [[ ! "$quality" =~ ($qualities) ]]; do

View File

@ -11,7 +11,7 @@ CFG_FILE="$CFG_DIR/themes/aniwrapper.rasi"
DEFAULT_DOWNLOAD="$HOME/Videos/sauce" DEFAULT_DOWNLOAD="$HOME/Videos/sauce"
ROFI_THEME="aniwrapper.rasi" ROFI_THEME="aniwrapper.rasi"
THEMES="aniwrapper (default)|dracula|doomone|fancy|flamingo|material|nord|onedark" THEMES="aniwrapper (default)|dracula|doomone|fancy|flamingo|material|nord|onedark"
QUALITIES="1. best (default)|2. 1080p|3. 720p|4. 360p|5. worst" QUALITIES="1. best|2. 1080p|3. 720p|4. 360p|5. worst"
QUALITY=best QUALITY=best
DPI=96 DPI=96
GET_QUALITY=0 GET_QUALITY=0
@ -98,7 +98,7 @@ run() {
get_quality() { get_quality() {
if ((IS_ROFI == 1)); then if ((IS_ROFI == 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 -a 0 \
-theme-str 'listview {columns: 1;}' -p "Choose video quality:" \ -theme-str 'listview {columns: 1;}' -p "Choose video quality:" \
-sep '|' -only-match <<< "$QUALITIES") -sep '|' -only-match <<< "$QUALITIES")
QUALITY=$(awk '{print $2}' <<< "$selection") QUALITY=$(awk '{print $2}' <<< "$selection")