mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-11-22 03:19:53 -08:00
Compare commits
3 Commits
2e9e28883e
...
24f3c25142
Author | SHA1 | Date | |
---|---|---|---|
|
24f3c25142 | ||
|
985a19fcf0 | ||
|
a8a32968da |
102
ani-cli
102
ani-cli
@ -156,23 +156,13 @@ run_stmt() {
|
||||
# Return number of matches for anime/episode in db
|
||||
check_db() {
|
||||
if [[ "$1" == "directory" ]]; then
|
||||
stmt="SELECT DISTINCT COUNT(*) \
|
||||
FROM file_history \
|
||||
WHERE directory = '$2';"
|
||||
stmt="SELECT DISTINCT COUNT(*) FROM file_history WHERE directory = '$2';"
|
||||
elif [[ "$1" == "file" ]]; then
|
||||
stmt="SELECT DISTINCT COUNT(*) \
|
||||
FROM file_history \
|
||||
WHERE directory = '$2' \
|
||||
AND filename = '$3';"
|
||||
stmt="SELECT DISTINCT COUNT(*) FROM file_history WHERE directory = '$2' AND filename = '$3';"
|
||||
elif [[ "$2" == "search" ]]; then
|
||||
stmt="SELECT DISTINCT COUNT(*) \
|
||||
FROM search_history \
|
||||
WHERE anime_name = '$1';"
|
||||
stmt="SELECT DISTINCT COUNT(*) FROM search_history WHERE anime_name = '$1';"
|
||||
else
|
||||
stmt="SELECT DISTINCT COUNT(*) \
|
||||
FROM watch_history \
|
||||
WHERE anime_name = '$1' \
|
||||
AND episode_number = '$2';"
|
||||
stmt="SELECT DISTINCT COUNT(*) FROM watch_history WHERE anime_name = '$1' AND episode_number = '$2';"
|
||||
fi
|
||||
res=$(run_stmt "$stmt")
|
||||
return $res
|
||||
@ -195,16 +185,13 @@ update_date() {
|
||||
stmt=""
|
||||
if [[ "$1" == "directory" ]]; then
|
||||
lg "UPDATING FILE_HISTORY: directory='$2', filename='DIRECTORY', search_date='$datetime'"
|
||||
stmt="UPDATE file_history SET watch_date = '$datetime' \
|
||||
WHERE directory = '$2' and filename = '$3';"
|
||||
stmt="UPDATE file_history SET watch_date = '$datetime' WHERE directory = '$2' and filename = '$3';"
|
||||
elif [[ "$1" == "file" ]]; then
|
||||
lg "UPDATING FILE_HISTORY: directory='$2', filename='$3', search_date='$datetime'"
|
||||
stmt="UPDATE file_history SET watch_date = '$datetime' \
|
||||
WHERE directory = '$2' and filename = '$3';"
|
||||
stmt="UPDATE file_history SET watch_date = '$datetime' WHERE directory = '$2' and filename = '$3';"
|
||||
elif [[ "$2" == "search" ]]; then
|
||||
lg "UPDATING SEARCH_HISTORY: anime_name='$1', search_date='$datetime'"
|
||||
stmt="UPDATE search_history SET search_date = '$datetime' \
|
||||
WHERE anime_name = '$1';"
|
||||
stmt="UPDATE search_history SET search_date = '$datetime' WHERE anime_name = '$1';"
|
||||
elif [[ $# -ge 3 ]]; then
|
||||
temp_dt="${3// /:}"
|
||||
[ -z "$temp_dt" ] && return 1
|
||||
@ -216,14 +203,10 @@ update_date() {
|
||||
return 1
|
||||
fi
|
||||
lg "UPDATING watch_history from sync. watch_date -> $temp_dt"
|
||||
stmt="UPDATE watch_history SET watch_date = '$temp_dt' \
|
||||
WHERE anime_name = '$1' \
|
||||
AND episode_number = $2;"
|
||||
stmt="UPDATE watch_history SET watch_date = '$temp_dt' WHERE anime_name = '$1' AND episode_number = $2;"
|
||||
else
|
||||
lg "UPDATING WATCH_HISTORY: anime_name='$1', episode_number='$2' search_date='$datetime'"
|
||||
stmt="UPDATE watch_history SET watch_date = '$datetime' \
|
||||
WHERE anime_name = '$1' \
|
||||
AND episode_number = $2;"
|
||||
stmt="UPDATE watch_history SET watch_date = '$datetime' WHERE anime_name = '$1' AND episode_number = $2;"
|
||||
fi
|
||||
wait # in case there's another insert/update still running in background?
|
||||
run_stmt "$stmt"
|
||||
@ -242,20 +225,23 @@ insert_history() {
|
||||
res=$?
|
||||
else
|
||||
lg "Row not found in DB... inserting"
|
||||
if [[ "$1" == "directory" ]]; then
|
||||
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) \
|
||||
VALUES('$2', '$3', '$datetime');"
|
||||
elif [[ "$2" == "search" ]]; then
|
||||
stmt="INSERT INTO search_history(anime_name, search_date) \
|
||||
VALUES('$1', '$datetime');"
|
||||
else
|
||||
stmt="INSERT INTO \
|
||||
watch_history(anime_name, episode_number, watch_date) \
|
||||
VALUES('$1', '$2', '$datetime');"
|
||||
fi
|
||||
case "$1" in
|
||||
directory)
|
||||
stmt="INSERT INTO file_history(directory, filename, watch_date) VALUES('$2', 'DIRECTORY', '$datetime');"
|
||||
;;
|
||||
file)
|
||||
stmt="INSERT INTO file_history(directory, filename, watch_date) VALUES('$2', '$3', '$datetime');"
|
||||
;;
|
||||
search)
|
||||
stmt="INSERT INTO search_history(anime_name, search_date) VALUES('$2', '$datetime');"
|
||||
;;
|
||||
watch)
|
||||
stmt="INSERT INTO watch_history(anime_name, episode_number, watch_date) VALUES('$2', '$3', '$datetime');"
|
||||
;;
|
||||
sync)
|
||||
stmt="INSERT INTO watch_history(anime_name, episode_number, watch_date) VALUES('$2', '$3', '$4');"
|
||||
;;
|
||||
esac
|
||||
lg "INSERT STATEMENT -> $stmt"
|
||||
wait # in case there's another insert/update still running in background
|
||||
run_stmt "$stmt"
|
||||
@ -292,7 +278,7 @@ sync_watch_history() {
|
||||
while read -r ep; do
|
||||
episode_num=$(awk -F '|' '{print $1}' <<< "$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))
|
||||
continue
|
||||
fi
|
||||
@ -560,7 +546,7 @@ anime_selection() {
|
||||
[ -z "$name" ] && name="$anime_id"
|
||||
[ -z "$selection_id" ] && die "Invalid number entered"
|
||||
|
||||
insert_history "$name" "search" &
|
||||
insert_history "search" "$name" &
|
||||
|
||||
read -r last_ep_number <<- EOF
|
||||
$(search_eps "$selection_id")
|
||||
@ -640,7 +626,7 @@ open_episode() {
|
||||
|
||||
# Don't update watch history if downloading episode
|
||||
if [ "$is_download" -eq 0 ]; then
|
||||
insert_history "$anime_id" "$episode" &
|
||||
insert_history "watch" "$anime_id" "$episode" &
|
||||
fi
|
||||
|
||||
dpage_link=$(get_dpage_link "$anime_id" "$episode")
|
||||
@ -713,7 +699,7 @@ stream() {
|
||||
# skip search_anime function and assign $query
|
||||
anime_id="${query// /}"
|
||||
selection_id="$anime_id"
|
||||
insert_history "$anime_id" "search" &
|
||||
insert_history "search" "$anime_id" &
|
||||
read -r last_ep_number <<< "$(search_eps "$selection_id")"
|
||||
fi
|
||||
episode_selection
|
||||
@ -933,7 +919,7 @@ main() {
|
||||
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" "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}Enter choice:${c_green} "
|
||||
read -r choice
|
||||
@ -961,13 +947,33 @@ main() {
|
||||
lg "NEW EPISODE: $selection_id - $episode"
|
||||
;;
|
||||
Q)
|
||||
qualities="best|1080p|720p|480p|360p|worst"
|
||||
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" \
|
||||
-i -l 5 -only-match -sep '|' \
|
||||
-p "Choose quality:" <<< "1. best (default)|2. 1080p|3. 720p|4. 360p|5. worst")
|
||||
-i -l 5 -only-match -sep '|' -a "$cur_quality" -mesg "$(generate_span "Current quality: $quality")" \
|
||||
-p "Choose quality:" <<< "1. best|2. 1080p|3. 720p|4. 360p|5. worst")
|
||||
quality=$(awk '{ print $2 }' <<< "$choice")
|
||||
else
|
||||
qualities="best|1080p|720p|480p|360p|worst"
|
||||
printf "${c_blue}Choose quality: [$qualities]:$c_reset "
|
||||
read -r quality
|
||||
while [[ ! "$quality" =~ ($qualities) ]]; do
|
||||
|
@ -11,7 +11,7 @@ CFG_FILE="$CFG_DIR/themes/aniwrapper.rasi"
|
||||
DEFAULT_DOWNLOAD="$HOME/Videos/sauce"
|
||||
ROFI_THEME="aniwrapper.rasi"
|
||||
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
|
||||
DPI=96
|
||||
GET_QUALITY=0
|
||||
@ -98,7 +98,7 @@ run() {
|
||||
get_quality() {
|
||||
if ((IS_ROFI == 1)); then
|
||||
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:" \
|
||||
-sep '|' -only-match <<< "$QUALITIES")
|
||||
QUALITY=$(awk '{print $2}' <<< "$selection")
|
||||
|
Loading…
Reference in New Issue
Block a user