Compare commits

..

3 Commits

Author SHA1 Message Date
ksyasuda
4af41db0bf add openssl to dep_ch function 2022-02-22 08:30:57 -08:00
ksyasuda
8882405c0e add option to download current episode 2022-02-22 08:18:14 -08:00
ksyasuda
4d704d4b32 make queries not distinct since uniqueness is enforced at table level 2022-02-21 19:41:50 -08:00

123
ani-cli
View File

@ -138,6 +138,54 @@ get_video_quality() {
printf '%s' "$video_link" printf '%s' "$video_link"
} }
set_video_quality() {
if ((IS_ROFI == 1)); then
qualities="1. best|2. 1080p|3. 720p|4. 480p|5. 360p|6. worst"
while IFS='|' read -ra quals; do
for q in "${quals[@]}"; do
if [[ "$(awk '{ print $NF }' <<< "$q")" == "$quality" ]]; then
cur_quality="$((${q:0:1} - 1))"
break
fi
done
done <<< "$qualities"
choice=$(rofi -dmenu -dpi "$DPI" -config "$ROFI_CFG" \
-theme-str 'listview {columns: 1;} window {width: 25%;}' \
-i -l 6 -no-custom -sep '|' -a "$cur_quality" -mesg "$(generate_span "Current quality: $quality")" \
-p "Choose quality:" -window-title 'aniwrapper' -selected-row "$cur_quality" <<< "$qualities")
quality=$(awk '{ print $2 }' <<< "$choice")
else
qualities="best|1080p|720p|480p|360p|worst"
prompt "Choose quality [$qualities]"
read -r quality
while [[ ! "$quality" =~ ($qualities) ]]; do
lg "$quality not a valid quality"
prompt "Choose quality [$qualities]"
read -r quality
done
fi
[ -z "$quality" ] && die "No quality selected"
}
get_dl_dir() {
if ((IS_ROFI == 1)); then
download_dir=$(
rofi -dpi "$DPI" -dmenu -config "$ROFI_CFG" \
-theme-str 'listview {columns: 1;} window {width: 45%;}' \
-mesg "$(generate_span "Enter the path to the download directory, or leave blank to go with the default: $HOME/Videos/sauce/")" \
-l 1 -p "Enter download dir:" -window-title 'aniwrapper'
)
else
prompt "Enter download directory"
read -r download_dir
fi
lg "Download dir: $download_dir"
[ -z "$download_dir" ] && download_dir="$HOME/Videos/sauce/"
if [ ! -d "$download_dir" ]; then
mkdir -p "$download_dir" || die "Error creating directory: $download_dir"
fi
}
dep_ch() { dep_ch() {
for dep; do for dep; do
if ! command -v "$dep" > /dev/null; then if ! command -v "$dep" > /dev/null; then
@ -174,19 +222,19 @@ run_stmt() {
check_db() { check_db() {
case "$1" in case "$1" in
directory) directory)
stmt="SELECT DISTINCT COUNT(*) FROM file_history WHERE directory = '$2';" stmt="SELECT COUNT(*) FROM file_history WHERE directory = '$2';"
;; ;;
file) file)
stmt="SELECT DISTINCT COUNT(*) FROM file_history WHERE directory = '$2' AND filename = '$3';" stmt="SELECT COUNT(*) FROM file_history WHERE directory = '$2' AND filename = '$3';"
;; ;;
search) search)
stmt="SELECT DISTINCT COUNT(*) FROM search_history WHERE anime_name = '$2';" stmt="SELECT COUNT(*) FROM search_history WHERE anime_name = '$2';"
;; ;;
watch | sync) watch | sync)
stmt="SELECT DISTINCT COUNT(*) FROM watch_history WHERE anime_name = '$2' AND episode_number = '$3';" stmt="SELECT COUNT(*) FROM watch_history WHERE anime_name = '$2' AND episode_number = '$3';"
;; ;;
anime) anime)
stmt="SELECT DISTINCT COUNT(*) FROM anime WHERE anime_name = '$2';" stmt="SELECT COUNT(*) FROM anime WHERE anime_name = '$2';"
;; ;;
esac esac
res=$(run_stmt "$stmt") res=$(run_stmt "$stmt")
@ -291,7 +339,7 @@ sync_search_history() {
fi fi
((++cnt)) ((++cnt))
fi fi
done < <(sqlite3 -list -noheader "$temp_db" "SELECT DISTINCT * FROM search_history") done < <(sqlite3 -list -noheader "$temp_db" "SELECT * FROM search_history")
lg "$cnt rows inserted into search_history table" lg "$cnt rows inserted into search_history table"
lg "$errs errors on insert" lg "$errs errors on insert"
} }
@ -310,7 +358,7 @@ sync_watch_history() {
fi fi
((++cnt)) ((++cnt))
done < <(sqlite3 -list -noheader "$temp_db" "SELECT episode_number, watch_date FROM watch_history WHERE anime_name = '$anime_name'") done < <(sqlite3 -list -noheader "$temp_db" "SELECT episode_number, watch_date FROM watch_history WHERE anime_name = '$anime_name'")
done < <(sqlite3 -list -noheader "$temp_db" "SELECT DISTINCT anime_name FROM watch_history") done < <(sqlite3 -list -noheader "$temp_db" "SELECT anime_name FROM watch_history")
lg "$cnt rows inserted into watch_history table" lg "$cnt rows inserted into watch_history table"
lg "$errs rows skipped on insert" lg "$errs rows skipped on insert"
} }
@ -436,7 +484,7 @@ get_search_query() {
if [ $# -gt 0 ]; then if [ $# -gt 0 ]; then
query="${*// /-}" query="${*// /-}"
elif [ "$IS_ROFI" -eq 1 ]; then elif [ "$IS_ROFI" -eq 1 ]; then
stmt="SELECT DISTINCT id || '. ' || anime_name FROM search_history ORDER BY search_date DESC;" stmt="SELECT id || '. ' || anime_name FROM search_history ORDER BY search_date DESC;"
msg="Choose from list of searched anime below, or enter a unique name of an anime to search for" msg="Choose from list of searched anime below, or enter a unique name of an anime to search for"
query=$(rofi -dpi "$DPI" -dmenu -l 15 -p "Search Anime:" \ query=$(rofi -dpi "$DPI" -dmenu -l 15 -p "Search Anime:" \
-mesg "$(generate_span "$msg")" \ -mesg "$(generate_span "$msg")" \
@ -549,7 +597,7 @@ episode_selection() {
ep_choice_start=1 ep_choice_start=1
if ((IS_ROFI == 1)); then if ((IS_ROFI == 1)); then
lg "Anime ID: $anime_id" lg "Anime ID: $anime_id"
stmt="SELECT DISTINCT episode_number FROM watch_history WHERE anime_name = '$anime_id';" stmt="SELECT episode_number FROM watch_history WHERE anime_name = '$anime_id';"
# Get Watch History for $anime_id as comma separated list # Get Watch History for $anime_id as comma separated list
watch_history="" watch_history=""
@ -793,7 +841,7 @@ main() {
;; ;;
history) history)
BASE_URL="$(curl -s -L -o /dev/null -w "%{url_effective}\n" https://gogoanime.fi)" BASE_URL="$(curl -s -L -o /dev/null -w "%{url_effective}\n" https://gogoanime.fi)"
stmt="SELECT DISTINCT anime_name FROM search_history ORDER BY search_date DESC" stmt="SELECT anime_name FROM search_history ORDER BY search_date DESC"
search_results="$(run_stmt "$stmt")" search_results="$(run_stmt "$stmt")"
[ -z "$search_results" ] && die "History is empty" [ -z "$search_results" ] && die "History is empty"
if ! anime_selection "${search_results[@]}"; then if ! anime_selection "${search_results[@]}"; then
@ -867,18 +915,14 @@ main() {
choice='' choice=''
while :; do while :; do
inf "Currently playing $selection_id episode" "${episode// /}/$LAST_EP_NUMBER" inf "Currently playing $selection_id episode" "${episode// /}/$LAST_EP_NUMBER"
if ((episode != LAST_EP_NUMBER)); then ((episode != LAST_EP_NUMBER)) && menu_line_alternate "next episode" "n"
menu_line_alternate "next episode" "n" ((episode != FIRST_EP_NUMBER)) && menu_line_alternate "previous episode" "p"
fi ((FIRST_EP_NUMBER != LAST_EP_NUMBER)) && menu_line_alternate "select episode" "s"
if ((episode != FIRST_EP_NUMBER)); then
menu_line_alternate "previous episode" "p"
fi
if ((FIRST_EP_NUMBER != LAST_EP_NUMBER)); then
menu_line_alternate "select episode" "s"
fi
menu_line_alternate "replay current episode" "r" menu_line_alternate "replay current episode" "r"
menu_line_alternate "search for another anime" "a" menu_line_alternate "search for another anime" "a"
menu_line_alternate "select quality (current: $quality)" "Q" menu_line_alternate "download current episode" "d"
menu_line_alternate "download current episode (with quality selection)" "D"
menu_line_alternate "select video quality (current: $quality)" "Q"
menu_line_strong "exit" "q" menu_line_strong "exit" "q"
prompt "Enter choice" prompt "Enter choice"
read -r choice read -r choice
@ -904,34 +948,21 @@ main() {
lg "NEW EPISODE: $selection_id - $episode" lg "NEW EPISODE: $selection_id - $episode"
;; ;;
Q) Q)
if ((IS_ROFI == 1)); then set_video_quality
qualities="1. best|2. 1080p|3. 720p|4. 480p|5. 360p|6. worst"
while IFS='|' read -ra quals; do
for q in "${quals[@]}"; do
if [[ "$(awk '{ print $NF }' <<< "$q")" == "$quality" ]]; then
cur_quality="$((${q:0:1} - 1))"
break
fi
done
done <<< "$qualities"
choice=$(rofi -dmenu -dpi "$DPI" -config "$ROFI_CFG" \
-theme-str 'listview {columns: 1;} window {width: 25%;}' \
-i -l 6 -no-custom -sep '|' -a "$cur_quality" -mesg "$(generate_span "Current quality: $quality")" \
-p "Choose quality:" -window-title 'aniwrapper' -selected-row "$cur_quality" <<< "$qualities")
quality=$(awk '{ print $2 }' <<< "$choice")
else
qualities="best|1080p|720p|480p|360p|worst"
prompt "Choose quality [$qualities]"
read -r quality
while [[ ! "$quality" =~ ($qualities) ]]; do
lg "$quality not a valid quality"
prompt "Choose quality [$qualities]"
read -r quality
done
fi
episode=$((episode)) episode=$((episode))
;; ;;
d)
get_dl_dir
is_download=1
break
;;
D)
get_dl_dir
set_video_quality
is_download=1
break
;;
q) q)
break break
;; ;;
@ -945,7 +976,7 @@ main() {
fi fi
} }
dep_ch "$PLAYER_FN" "curl" "sed" "grep" "sqlite3" "rofi" "git" "aria2c" dep_ch "$PLAYER_FN" "curl" "sed" "grep" "sqlite3" "rofi" "git" "aria2c" "openssl"
parse_args "$@" parse_args "$@"
shift $((OPTIND - 1)) shift $((OPTIND - 1))
main "$@" main "$@"