mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-10-28 04:44:11 -07:00
fix colorscheme for active items
update history function to use database instead of history file
This commit is contained in:
parent
e42629d406
commit
2912950366
85
ani-cli
85
ani-cli
@ -117,6 +117,10 @@ check_anime_name() {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run_stmt() {
|
||||||
|
printf "%s\n" "$1" | sqlite3 -noheader "$history_db"
|
||||||
|
}
|
||||||
|
|
||||||
check_db() {
|
check_db() {
|
||||||
# Return number of matches for anime/episode in db
|
# Return number of matches for anime/episode in db
|
||||||
# echo "$1 $2"
|
# echo "$1 $2"
|
||||||
@ -124,7 +128,7 @@ check_db() {
|
|||||||
stmt="SELECT DISTINCT COUNT(*) \
|
stmt="SELECT DISTINCT COUNT(*) \
|
||||||
FROM search_history \
|
FROM search_history \
|
||||||
WHERE anime_name = '$1';"
|
WHERE anime_name = '$1';"
|
||||||
res="$(printf '%s\n' $stmt | sqlite3 -noheader $history_db | tail -1)"
|
res=$(run_stmt "$stmt")
|
||||||
# echo "QUERY RESULT $res"
|
# echo "QUERY RESULT $res"
|
||||||
return "$res"
|
return "$res"
|
||||||
else
|
else
|
||||||
@ -132,7 +136,7 @@ check_db() {
|
|||||||
FROM watch_history \
|
FROM watch_history \
|
||||||
WHERE anime_name = '$1' \
|
WHERE anime_name = '$1' \
|
||||||
AND episode_number = $2;"
|
AND episode_number = $2;"
|
||||||
res="$(printf '%s\n' $stmt | sqlite3 -noheader $history_db | tail -1)"
|
res=$(run_stmt "$stmt")
|
||||||
# echo "QUERY RESULT $res"
|
# echo "QUERY RESULT $res"
|
||||||
return "$res"
|
return "$res"
|
||||||
fi
|
fi
|
||||||
@ -141,16 +145,16 @@ check_db() {
|
|||||||
update_date() {
|
update_date() {
|
||||||
# updates search/watch date for passed in anime
|
# updates search/watch date for passed in anime
|
||||||
datetime=$(date +'%Y-%m-%d %H:%M:%S')
|
datetime=$(date +'%Y-%m-%d %H:%M:%S')
|
||||||
|
stmt=""
|
||||||
if [[ "$2" == "search" ]]; then
|
if [[ "$2" == "search" ]]; then
|
||||||
stmt="UPDATE search_history SET search_date = '$datetime' \
|
stmt="UPDATE search_history SET search_date = '$datetime' \
|
||||||
WHERE anime_name = '$1';" &&
|
WHERE anime_name = '$1';"
|
||||||
return 0 || return 1
|
|
||||||
else
|
else
|
||||||
stmt="UPDATE watch_history SET watch_date = '$datetime' \
|
stmt="UPDATE watch_history SET watch_date = '$datetime' \
|
||||||
WHERE anime_name = '$1' \
|
WHERE anime_name = '$1' \
|
||||||
AND episode_number = $2;" &&
|
AND episode_number = $2;"
|
||||||
return 0 || return 1
|
|
||||||
fi
|
fi
|
||||||
|
run_stmt "$stmt"
|
||||||
}
|
}
|
||||||
|
|
||||||
insert_history() {
|
insert_history() {
|
||||||
@ -162,9 +166,8 @@ insert_history() {
|
|||||||
fi
|
fi
|
||||||
datetime=$(date +'%Y-%m-%d %H:%M:%S')
|
datetime=$(date +'%Y-%m-%d %H:%M:%S')
|
||||||
check_db "$@"
|
check_db "$@"
|
||||||
num=$?
|
|
||||||
# echo "CHECKDB RETURNED: $num"
|
# echo "CHECKDB RETURNED: $num"
|
||||||
if [[ "$num" -gt 0 ]]; then
|
if [[ "$?" -gt 0 ]]; then
|
||||||
if [[ "$2" == "search" ]]; then
|
if [[ "$2" == "search" ]]; then
|
||||||
printf "%s\n" "Already in search db... Updating search_date"
|
printf "%s\n" "Already in search db... Updating search_date"
|
||||||
else
|
else
|
||||||
@ -175,12 +178,12 @@ insert_history() {
|
|||||||
if [[ "$2" == "search" ]]; then
|
if [[ "$2" == "search" ]]; then
|
||||||
stmt="INSERT INTO search_history(anime_name, search_date) \
|
stmt="INSERT INTO search_history(anime_name, search_date) \
|
||||||
VALUES('$1', '$datetime');"
|
VALUES('$1', '$datetime');"
|
||||||
printf "%s\n" "$stmt" | sqlite3 -noheader "$history_db"
|
run_stmt "$stmt"
|
||||||
else
|
else
|
||||||
stmt="INSERT INTO \
|
stmt="INSERT INTO \
|
||||||
watch_history(anime_name, episode_number, watch_date) \
|
watch_history(anime_name, episode_number, watch_date) \
|
||||||
VALUES('$1', '$2', '$datetime');"
|
VALUES('$1', '$2', '$datetime');"
|
||||||
printf "%s\n" "$stmt" | sqlite3 -noheader "$history_db"
|
run_stmt "$stmt"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -193,16 +196,9 @@ get_search_query() {
|
|||||||
stmt="SELECT DISTINCT anime_name \
|
stmt="SELECT DISTINCT anime_name \
|
||||||
FROM search_history \
|
FROM search_history \
|
||||||
ORDER BY search_date DESC;"
|
ORDER BY search_date DESC;"
|
||||||
# cnt_stmt="SELECT DISTINCT COUNT(*) FROM search_history"
|
# hist=$(echo "$stmt" | sqlite3 -noheader "$history_db")
|
||||||
hist=$(echo "$stmt" | sqlite3 -noheader "$history_db")
|
hist=$(run_stmt "$stmt")
|
||||||
# hist=$(echo "$stmt" | sqlite3 -noheader "$history_db" | awk '{ if ( NR > 2 ) { print } }')
|
|
||||||
|
|
||||||
# cnt=$(printf "%s\n" "$cnt_stmt" | sqlite3 -noheader "$history_db" | tail -1)
|
|
||||||
if [[ "$VERBOSE" -eq 1 ]]; then
|
|
||||||
echo "HISTORY:" "${hist[@]}"
|
|
||||||
fi
|
|
||||||
# echo "HISTORY: $hist"
|
|
||||||
# echo "COUNT: $cnt"
|
|
||||||
if [ -z "$*" ]; then
|
if [ -z "$*" ]; then
|
||||||
query=$(printf "%s\n" "${hist[@]}" |
|
query=$(printf "%s\n" "${hist[@]}" |
|
||||||
rofi -dmenu -l 12 -p "Search Anime:" \
|
rofi -dmenu -l 12 -p "Search Anime:" \
|
||||||
@ -246,19 +242,23 @@ anime_selection() {
|
|||||||
$search_results
|
$search_results
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
searched=()
|
searched=""
|
||||||
cnt=0
|
cnt=0
|
||||||
# Get the comma separated list of indexes of anime that has been searched before
|
# Get the comma separated list of indexes of anime that has been searched before
|
||||||
for anime in "${res[@]}"; do
|
for anime in "${res[@]}"; do
|
||||||
# printf "ANIME: $anime"
|
[ "$VERBOSE" -eq 1 ] && printf "%s\n" "ANIME: $anime"
|
||||||
check_db "$anime" "search"
|
check_db "$anime" "search"
|
||||||
if [[ $? -gt 0 ]]; then
|
if [[ $? -gt 0 ]]; then
|
||||||
# printf "%s\n" "SEARCHED BEFORE"
|
[ "$VERBOSE" -eq 1 ] && printf "%s\n" "SEARCHED BEFORE"
|
||||||
searched+=("$((cnt++)), ")
|
if [[ "$searched" == "" ]]; then
|
||||||
|
searched="$((cnt++))"
|
||||||
|
else
|
||||||
|
searched="$searched, $((cnt++))"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# printf "%s\n" "SEARCHED: $searched"
|
printf "%s\n" "SEARCHED: $searched"
|
||||||
|
|
||||||
# get the anime from indexed list
|
# get the anime from indexed list
|
||||||
user_input=$(printf "${menu[@]}" |
|
user_input=$(printf "${menu[@]}" |
|
||||||
@ -312,10 +312,9 @@ episode_selection() {
|
|||||||
stmt="SELECT DISTINCT episode_number \
|
stmt="SELECT DISTINCT episode_number \
|
||||||
FROM watch_history \
|
FROM watch_history \
|
||||||
WHERE anime_name = '$anime_id';"
|
WHERE anime_name = '$anime_id';"
|
||||||
hist=$(echo "$stmt" | sqlite3 -noheader "$history_db")
|
hist=$(run_stmt "$stmt")
|
||||||
# hist=$(echo "$stmt" | sqlite3 "$history_db" | awk '{ if ( NR > 2 ) { print } }')
|
|
||||||
if [[ "$VERBOSE" -eq 1 ]]; then
|
if [[ "$VERBOSE" -eq 1 ]]; then
|
||||||
echo "HISTORY: ${hist[@]}"
|
printf "%s\n" "HISTORY: ${hist[*]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Get Watch History for $anime_id as comma separated list
|
# Get Watch History for $anime_id as comma separated list
|
||||||
@ -329,19 +328,25 @@ episode_selection() {
|
|||||||
done
|
done
|
||||||
|
|
||||||
[ "$VERBOSE" -eq 1 ] && printf "WATCH HISTORY: %s\n" "$watch_history"
|
[ "$VERBOSE" -eq 1 ] && printf "WATCH HISTORY: %s\n" "$watch_history"
|
||||||
# cnt=$(printf "%s\n" "$cnt_stmt" | sqlite3 "$history_db" | tail -1)
|
|
||||||
# printf "NUM EPISODES: $last_ep_number"
|
# printf "NUM EPISODES: $last_ep_number"
|
||||||
# get user choice and set the start and end
|
# get user choice and set the start and end
|
||||||
|
msg='<span foreground="peachpuff" style="italic" size="small" weight="light">Range of episodes can be provided as: START_EPISODE - END_EPISODE</span>'
|
||||||
choice=$(
|
choice=$(
|
||||||
seq 1 "$last_ep_number" |
|
seq 1 "$last_ep_number" |
|
||||||
rofi -dmenu -l 12 \
|
rofi -dmenu -l 12 \
|
||||||
-a "$watch_history" \
|
-a "$watch_history" \
|
||||||
-p "Select Episode (1, $last_ep_number):" \
|
-p "Select Episode [1, $last_ep_number]:" \
|
||||||
|
-mesg "$msg" \
|
||||||
-config "$config_dir"/meh.rasi
|
-config "$config_dir"/meh.rasi
|
||||||
)
|
)
|
||||||
ep_choice_start=$(printf '%s\n' "$choice" | awk '{print $1}')
|
ep_choice_start=$(printf '%s\n' "${choice}" | awk '{print $1}')
|
||||||
ep_choice_end=$(printf '%s\n' "$choice" | awk '{print $2}')
|
ep_choice_end=$(printf '%s\n' "${choice}" | awk '{print $NF}')
|
||||||
# echo "$ep_choice_start $ep_choice_end"
|
|
||||||
|
# if only one episode was entered, set ep_choice_end to empty string so only selected episode plays
|
||||||
|
# otherwise plays from ep 1 - ep_choice_start
|
||||||
|
[ "$ep_choice_start" -eq "$ep_choice_end" ] && ep_choice_end=""
|
||||||
|
|
||||||
|
[ "$VERBOSE" -eq 1 ] && printf "%s\n" "START: $ep_choice_start | END: $ep_choice_end"
|
||||||
# read ep_choice_start ep_choice_end
|
# read ep_choice_start ep_choice_end
|
||||||
printf "$c_reset"
|
printf "$c_reset"
|
||||||
|
|
||||||
@ -360,9 +365,9 @@ open_episode() {
|
|||||||
FROM watch_history \
|
FROM watch_history \
|
||||||
WHERE anime_name = '$anime_id';"
|
WHERE anime_name = '$anime_id';"
|
||||||
# hist=$(echo "$stmt" | sqlite3 "$history_db" | awk '{ if ( NR > 2 ) { print } }')
|
# hist=$(echo "$stmt" | sqlite3 "$history_db" | awk '{ if ( NR > 2 ) { print } }')
|
||||||
hist=$(echo "$stmt" | sqlite3 -noheader "$history_db")
|
hist=$(run_stmt "$stmt")
|
||||||
if [[ "$VERBOSE" -eq 1 ]]; then
|
if [[ "$VERBOSE" -eq 1 ]]; then
|
||||||
echo "HISTORY: ${hist[@]}"
|
echo "HISTORY: ${hist[*]}"
|
||||||
fi
|
fi
|
||||||
episode=$(printf "%s\n" "${hist[@]}" |
|
episode=$(printf "%s\n" "${hist[@]}" |
|
||||||
rofi -dmenu -l 12 -p "Choose Episode:" \
|
rofi -dmenu -l 12 -p "Choose Episode:" \
|
||||||
@ -464,11 +469,7 @@ if [[ "$list_history" -eq 1 ]]; then
|
|||||||
stmt="SELECT DISTINCT anime_name \
|
stmt="SELECT DISTINCT anime_name \
|
||||||
FROM search_history \
|
FROM search_history \
|
||||||
ORDER BY search_date DESC"
|
ORDER BY search_date DESC"
|
||||||
# cnt_stmt="SELECT DISTINCT COUNT(*) FROM search_history"
|
hist=$(run_stmt "$stmt")
|
||||||
# hist=$(echo "$stmt" | sqlite3 "$history_db")
|
|
||||||
# hist=$(echo "$stmt" | sqlite3 -noheader "$history_db" | awk '{ if ( NR > 2 ) { print } }')
|
|
||||||
hist=$(echo "$stmt" | sqlite3 -noheader "$history_db")
|
|
||||||
# cnt=$(printf "%s\n" "$cnt_stmt" | sqlite3 -noheader "$history_db")
|
|
||||||
printf "%s\n" "${hist[@]}" |
|
printf "%s\n" "${hist[@]}" |
|
||||||
rofi -config "$config_dir"/meh.rasi \
|
rofi -config "$config_dir"/meh.rasi \
|
||||||
-dmenu -l 12 -i -p "Search History"
|
-dmenu -l 12 -i -p "Search History"
|
||||||
@ -485,9 +486,11 @@ query)
|
|||||||
episode_selection
|
episode_selection
|
||||||
;;
|
;;
|
||||||
history)
|
history)
|
||||||
search_results=$(sed -n -E 's/\t[0-9]*//p' "$logfile")
|
# search_results=$(sed -n -E 's/\t[0-9]*//p' "$logfile")
|
||||||
|
stmt="SELECT DISTINCT anime_name FROM watch_history ORDER BY watch_date DESC"
|
||||||
|
search_results=$(printf "%s\n" "$stmt" | sqlite3 -noheader "$history_db")
|
||||||
[ -z "$search_results" ] && die "History is empty"
|
[ -z "$search_results" ] && die "History is empty"
|
||||||
anime_selection "$search_results"
|
anime_selection "${search_results[@]}"
|
||||||
ep_choice_start=$(sed -n -E "s/${selection_id}\t//p" "$logfile")
|
ep_choice_start=$(sed -n -E "s/${selection_id}\t//p" "$logfile")
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -31,6 +31,7 @@ message {
|
|||||||
border: 2px 0px 0px ;
|
border: 2px 0px 0px ;
|
||||||
border-color: @separatorcolor;
|
border-color: @separatorcolor;
|
||||||
padding: 1px ;
|
padding: 1px ;
|
||||||
|
text-color: @active-foreground;
|
||||||
}
|
}
|
||||||
textbox {
|
textbox {
|
||||||
text-color: @foreground;
|
text-color: @foreground;
|
||||||
|
Loading…
Reference in New Issue
Block a user