mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-10-28 04:44:11 -07:00
clean up code a bit
This commit is contained in:
parent
7e71788604
commit
ebc8587e6f
41
ani-cli
41
ani-cli
@ -15,7 +15,6 @@ SILENT=0
|
||||
|
||||
player_fn="mpv"
|
||||
playable="\.mp4|\.mkv|\.ts|\.mp3|\.webm"
|
||||
prog="ani-cli"
|
||||
c_red="\033[1;31m"
|
||||
c_green="\033[1;32m"
|
||||
c_yellow="\033[1;33m"
|
||||
@ -24,17 +23,6 @@ c_magenta="\033[1;35m"
|
||||
c_cyan="\033[1;36m"
|
||||
c_reset="\033[0m"
|
||||
|
||||
help_text() {
|
||||
while IFS= read -r line; do
|
||||
printf "%s\n" "$line"
|
||||
done <<- EOF
|
||||
USAGE: $prog <query>
|
||||
-h show this help text
|
||||
-d download episode
|
||||
-H continue where you left off
|
||||
EOF
|
||||
}
|
||||
|
||||
die() {
|
||||
((SILENT != 1)) && printf "$c_red%s$c_reset\n" "$*" >&2
|
||||
exit 1
|
||||
@ -59,8 +47,8 @@ check_input() {
|
||||
fi
|
||||
}
|
||||
|
||||
# get the download page url
|
||||
get_dpage_link() {
|
||||
# get the download page url
|
||||
anime_id=$1
|
||||
ep_no=$2
|
||||
|
||||
@ -190,7 +178,7 @@ update_date() {
|
||||
stmt=""
|
||||
case "$1" in
|
||||
directory)
|
||||
lg "UPDATING FILE_HISTORY: directory='$2', filename='DIRECTORY', search_date='$datetime'"
|
||||
lg "UPDATING FILE_HISTORY for with directory: directory='$2', filename='DIRECTORY', search_date='$datetime'"
|
||||
stmt="UPDATE file_history SET watch_date = '$datetime' WHERE directory = '$2' and filename = '$3';"
|
||||
;;
|
||||
file)
|
||||
@ -211,7 +199,7 @@ update_date() {
|
||||
lg "Passed in date is older or same than current date... doing nothing"
|
||||
return 1
|
||||
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' WHERE anime_name = '$2' AND episode_number = $3;"
|
||||
;;
|
||||
watch)
|
||||
@ -370,8 +358,7 @@ get_directory_data() {
|
||||
find_media() {
|
||||
inp="$1"
|
||||
[ -z "$inp" ] && die "No directory"
|
||||
# workaround to allow logging w/o affecting return output
|
||||
lg "INPUT DIR: $inp" 1> /dev/stderr
|
||||
lg "BEGIN find_media() on $inp" 1> /dev/stderr
|
||||
|
||||
# base case hit when a file is found
|
||||
if [ -f "$inp" ]; then
|
||||
@ -418,9 +405,7 @@ find_media() {
|
||||
#####################
|
||||
|
||||
get_search_query() {
|
||||
# Get search history
|
||||
stmt="SELECT DISTINCT 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"
|
||||
if [ "$IS_ROFI" -eq 1 ]; then
|
||||
query=$(rofi -dpi "$DPI" -dmenu -l 15 -p "Search Anime:" \
|
||||
@ -435,8 +420,8 @@ get_search_query() {
|
||||
fi
|
||||
}
|
||||
|
||||
# get anime name along with its id
|
||||
search_anime() {
|
||||
# get anime name along with its id
|
||||
lg "NUM ARGS: $#"
|
||||
if [[ $# -gt 1 ]]; then
|
||||
# if multi-word query, concatenate into one string and replace spaces with '-'
|
||||
@ -466,8 +451,8 @@ search_eps() {
|
||||
'
|
||||
}
|
||||
|
||||
# Select anime from query results
|
||||
anime_selection() {
|
||||
# Select anime from query results
|
||||
search_results=$*
|
||||
if [ "$IS_ROFI" -eq 1 ]; then
|
||||
menu=()
|
||||
@ -514,7 +499,7 @@ anime_selection() {
|
||||
menu_format_string_c1="$c_blue[$c_cyan%d$c_blue] $c_reset%s\n"
|
||||
menu_format_string_c2="$c_blue[$c_cyan%d$c_blue] $c_yellow%s$c_reset\n"
|
||||
count=1
|
||||
while read anime_id; do
|
||||
while read -r anime_id; do
|
||||
# alternating colors for menu
|
||||
[ $((count % 2)) -eq 0 ] &&
|
||||
menu_format_string=$menu_format_string_c1 ||
|
||||
@ -576,7 +561,9 @@ episode_selection() {
|
||||
lg "Episode watch history -> $watch_history"
|
||||
|
||||
# get user choice and set the start and end
|
||||
msg=$(printf "%s\n%s" "$(generate_span "Anime Name: $anime_id")" "$(generate_span "Range of episodes can be provided as: START_EPISODE - END_EPISODE")")
|
||||
msg1="Anime Name: $anime_id"
|
||||
msg2="Range of episodes can be provided as: START_EPISODE - END_EPISODE"
|
||||
[ "$is_download" -eq 1 ] && msg=$(printf "%s\n%s" "$(generate_span "$msg1")" "$(generate_span "$msg2")") || msg=$(printf "%s\n" "$(generate_span "$msg1")")
|
||||
choice=$(
|
||||
seq 1 "$last_ep_number" |
|
||||
rofi -dpi "$DPI" -dmenu -l 12 \
|
||||
@ -707,7 +694,6 @@ stream() {
|
||||
episode_selection
|
||||
}
|
||||
|
||||
# option parsing
|
||||
parse_args() {
|
||||
# to clear the colors when exited using SIGINT
|
||||
trap "printf '$c_reset'" INT HUP
|
||||
@ -716,12 +702,8 @@ parse_args() {
|
||||
is_download=0
|
||||
download_dir="."
|
||||
half_ep=0
|
||||
while getopts 'hd:Hsvq:cf:t:T:CQ:D:S' OPT; do
|
||||
while getopts 'd:Hsvq:cf:t:T:CQ:D:S' OPT; do
|
||||
case "$OPT" in
|
||||
h)
|
||||
help_text
|
||||
exit 0
|
||||
;;
|
||||
d)
|
||||
is_download=1
|
||||
download_dir="$OPTARG"
|
||||
@ -891,7 +873,6 @@ main() {
|
||||
|
||||
check_input
|
||||
|
||||
# plays selected episode(s)
|
||||
for ep in $episodes; do
|
||||
open_episode "$selection_id" "$ep" "$download_dir"
|
||||
done
|
||||
|
Loading…
Reference in New Issue
Block a user