mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-10-28 04:44:11 -07:00
Compare commits
3 Commits
7a3a61bb58
...
4af41db0bf
Author | SHA1 | Date | |
---|---|---|---|
|
4af41db0bf | ||
|
8882405c0e | ||
|
4d704d4b32 |
123
ani-cli
123
ani-cli
@ -138,6 +138,54 @@ get_video_quality() {
|
||||
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() {
|
||||
for dep; do
|
||||
if ! command -v "$dep" > /dev/null; then
|
||||
@ -174,19 +222,19 @@ run_stmt() {
|
||||
check_db() {
|
||||
case "$1" in
|
||||
directory)
|
||||
stmt="SELECT DISTINCT COUNT(*) FROM file_history WHERE directory = '$2';"
|
||||
stmt="SELECT COUNT(*) FROM file_history WHERE directory = '$2';"
|
||||
;;
|
||||
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)
|
||||
stmt="SELECT DISTINCT COUNT(*) FROM search_history WHERE anime_name = '$2';"
|
||||
stmt="SELECT COUNT(*) FROM search_history WHERE anime_name = '$2';"
|
||||
;;
|
||||
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)
|
||||
stmt="SELECT DISTINCT COUNT(*) FROM anime WHERE anime_name = '$2';"
|
||||
stmt="SELECT COUNT(*) FROM anime WHERE anime_name = '$2';"
|
||||
;;
|
||||
esac
|
||||
res=$(run_stmt "$stmt")
|
||||
@ -291,7 +339,7 @@ sync_search_history() {
|
||||
fi
|
||||
((++cnt))
|
||||
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 "$errs errors on insert"
|
||||
}
|
||||
@ -310,7 +358,7 @@ sync_watch_history() {
|
||||
fi
|
||||
((++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 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 "$errs rows skipped on insert"
|
||||
}
|
||||
@ -436,7 +484,7 @@ get_search_query() {
|
||||
if [ $# -gt 0 ]; then
|
||||
query="${*// /-}"
|
||||
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"
|
||||
query=$(rofi -dpi "$DPI" -dmenu -l 15 -p "Search Anime:" \
|
||||
-mesg "$(generate_span "$msg")" \
|
||||
@ -549,7 +597,7 @@ episode_selection() {
|
||||
ep_choice_start=1
|
||||
if ((IS_ROFI == 1)); then
|
||||
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
|
||||
watch_history=""
|
||||
@ -793,7 +841,7 @@ main() {
|
||||
;;
|
||||
history)
|
||||
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")"
|
||||
[ -z "$search_results" ] && die "History is empty"
|
||||
if ! anime_selection "${search_results[@]}"; then
|
||||
@ -867,18 +915,14 @@ main() {
|
||||
choice=''
|
||||
while :; do
|
||||
inf "Currently playing $selection_id episode" "${episode// /}/$LAST_EP_NUMBER"
|
||||
if ((episode != LAST_EP_NUMBER)); then
|
||||
menu_line_alternate "next episode" "n"
|
||||
fi
|
||||
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
|
||||
((episode != LAST_EP_NUMBER)) && menu_line_alternate "next episode" "n"
|
||||
((episode != FIRST_EP_NUMBER)) && menu_line_alternate "previous episode" "p"
|
||||
((FIRST_EP_NUMBER != LAST_EP_NUMBER)) && menu_line_alternate "select episode" "s"
|
||||
menu_line_alternate "replay current episode" "r"
|
||||
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"
|
||||
prompt "Enter choice"
|
||||
read -r choice
|
||||
@ -904,34 +948,21 @@ main() {
|
||||
lg "NEW EPISODE: $selection_id - $episode"
|
||||
;;
|
||||
Q)
|
||||
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
|
||||
set_video_quality
|
||||
episode=$((episode))
|
||||
;;
|
||||
|
||||
d)
|
||||
get_dl_dir
|
||||
is_download=1
|
||||
break
|
||||
;;
|
||||
D)
|
||||
get_dl_dir
|
||||
set_video_quality
|
||||
is_download=1
|
||||
break
|
||||
;;
|
||||
q)
|
||||
break
|
||||
;;
|
||||
@ -945,7 +976,7 @@ main() {
|
||||
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 "$@"
|
||||
shift $((OPTIND - 1))
|
||||
main "$@"
|
||||
|
Loading…
Reference in New Issue
Block a user