mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-11-22 03:19:53 -08:00
refactor code
This commit is contained in:
parent
3b64d74bf2
commit
aaaad7d986
98
aniwrapper
98
aniwrapper
@ -27,6 +27,30 @@ theme=default
|
||||
#############
|
||||
# Functions #
|
||||
#############
|
||||
help_text() {
|
||||
while IFS= read -r line; do
|
||||
printf "%s\n" "$line"
|
||||
done <<< "
|
||||
Usage:
|
||||
aniwrapper [-cdhvq] [-t <theme> or -T <config_path>]
|
||||
aniwrapper [-cv] [-t <theme> or -T <config_path>] -f <path_to_directory>
|
||||
aniwrapper -Q <query>
|
||||
aniwrapper -C
|
||||
Options:
|
||||
-h show this help text
|
||||
-q enable quality selection
|
||||
-c enable command-line mode (rofi disabled)
|
||||
-d download episode in command-line mode
|
||||
-C connect to history database
|
||||
|
||||
-t <aniwrapper (default)|dracula|fancy|flamingo|material|onedark> change rofi theme
|
||||
-T <config_path> specify custom rofi theme
|
||||
-f <path_to_directory> (no trailing slash) specify starting directory for play for file mode
|
||||
-Q <query> query the history database
|
||||
"
|
||||
exit 0
|
||||
}
|
||||
|
||||
logger() {
|
||||
if [[ "$VERBOSE" -eq 1 ]]; then
|
||||
printf "%s\n" "$*"
|
||||
@ -58,13 +82,6 @@ run() {
|
||||
fi
|
||||
}
|
||||
|
||||
create_default_download() {
|
||||
# make sure download directory exists
|
||||
if [ ! -d "$DEFAULT_DOWNLOAD" ]; then
|
||||
mkdir -p "$DEFAULT_DOWNLOAD"
|
||||
fi
|
||||
}
|
||||
|
||||
get_quality() {
|
||||
if [ "$IS_ROFI" -eq 1 ]; then
|
||||
selection=$(rofi -dmenu -config "$CFG_FILE" \
|
||||
@ -87,9 +104,7 @@ generate_span() {
|
||||
printf "%s\n" "$span"
|
||||
}
|
||||
|
||||
########
|
||||
# Main #
|
||||
########
|
||||
parse_args() {
|
||||
while getopts 'vhqcdf:-:t:T:CQ:' OPT; do
|
||||
case "$OPT" in
|
||||
h)
|
||||
@ -168,9 +183,9 @@ while getopts 'vhqcdf:-:t:T:CQ:' OPT; do
|
||||
esac
|
||||
done
|
||||
|
||||
logger "CONFIG DIR: $CFG_DIR"
|
||||
logger "ROFI CFG: $CFG_FILE"
|
||||
}
|
||||
|
||||
check_flags() {
|
||||
# Check if command-line flag is set
|
||||
if [[ "$IS_ROFI" -eq 0 ]] && [[ "$IS_DOWNLOAD" -eq 0 ]]; then
|
||||
run -c
|
||||
@ -189,10 +204,12 @@ elif [[ "$IS_ROFI" -eq 1 ]] && [[ "$IS_PLAY_FROM_FILE" -eq 1 ]] && [[ "$IS_CUSTO
|
||||
run "-f$play_path"
|
||||
exit $?
|
||||
fi
|
||||
}
|
||||
|
||||
# -------------------------------------------------------------------------------
|
||||
# Main
|
||||
# -------------------------------------------------------------------------------
|
||||
########
|
||||
# Main #
|
||||
########
|
||||
main() {
|
||||
choice=$(echo "${options[@]}" | rofi -dmenu -only-match -sep '|' \
|
||||
-config "$CFG_FILE" -l 6 -i -p "Aniwrapper")
|
||||
|
||||
@ -217,7 +234,6 @@ case "$selection" in
|
||||
-l 1 -p "Enter download dir:")
|
||||
# if dl_dir is none set to current directory
|
||||
[ "$dl_dir" == "" ] && dl_dir="$DEFAULT_DOWNLOAD"
|
||||
create_default_download
|
||||
run -d "$dl_dir"
|
||||
;;
|
||||
3.)
|
||||
@ -234,47 +250,28 @@ case "$selection" in
|
||||
# ---------------------------------------------------------------------------
|
||||
logger "Play from file selected"
|
||||
IS_PLAY_FROM_FILE=1
|
||||
msg="Provide a valid path to a directory or leave blank to go with the default: $HOME/Videos/sauce/"
|
||||
msg="$(printf '%s\n%s\n' "$msg" "The program will begin searching for media files from the supplied directory")"
|
||||
span=$(generate_span "$msg")
|
||||
span=$(printf '%s\n%s\n' "$(generate_span "Provide a valid path to a directory or leave blank to go with the default: $HOME/Videos/sauce/")" "$(generate_span "The program will begin searching for media files from the supplied directory")")
|
||||
play_dir=$(rofi -dmenu -config "$CFG_FILE" \
|
||||
-l 1 -mesg "$span" -p "Enter path to starting directory:")
|
||||
if [ -z "$play_dir" ]; then
|
||||
create_default_download
|
||||
mkdir -p "$DEFAULT_DOWNLOAD" || seppuku "error creating default download directory"
|
||||
run -f"$DEFAULT_DOWNLOAD"
|
||||
else
|
||||
run -f"$play_dir"
|
||||
fi
|
||||
exit $?
|
||||
;;
|
||||
5.)
|
||||
logger "Sync history database"
|
||||
username=$(rofi -dmenu -config "$CFG_FILE" \
|
||||
-l 1 -p "Enter the username of the remote user:")
|
||||
if [[ -z "$username" ]] || [[ "$username" == "" ]]; then
|
||||
logger "No username provided... exiting"
|
||||
exit 1
|
||||
fi
|
||||
host=$(rofi -dmenu -config "$CFG_FILE" \
|
||||
-l 1 -p "Enter the host for the remote machine (eg 192.168.1.99):")
|
||||
if [[ -z "$host" ]] || [[ "$host" == "" ]]; then
|
||||
logger "No host provided... exiting"
|
||||
exit 1
|
||||
fi
|
||||
port=$(rofi -dmenu -config "$CFG_FILE" \
|
||||
-l 1 -p "Enter in the ssh port for remote machine or leave blank for default [22]:")
|
||||
if [[ -z "$port" ]] || [[ "$port" == "" ]]; then
|
||||
port=22
|
||||
fi
|
||||
keypath=$(rofi -dmenu -config "$CFG_FILE" \
|
||||
-l 1 -p "Enter path to private key (leave blank if not needed or if unsure):")
|
||||
|
||||
if [[ -z "$keypath" ]]; then
|
||||
printf "%s\n%s\n%d\n%s\n" "$username" "$host" "$port" "" | run -s
|
||||
else
|
||||
printf "%s\n%s\n%d\n%s\n" "$username" "$host" "$port" "$keypath" | run -s
|
||||
fi
|
||||
|
||||
if [[ "$?" -ne 0 ]]; then
|
||||
roficmd="rofi -dmenu -config $CFG_FILE -l 0 -p"
|
||||
username=$($roficmd "Enter the username of the remote user:")
|
||||
[ -z "$username" ] && seppuku "No username provided... exiting"
|
||||
host=$($roficmd "Enter the host for the remote machine (eg 192.168.1.99):")
|
||||
[ -z "$host" ] && seppuku "No host provided... exiting"
|
||||
port=$($roficmd "Enter in the ssh port for remote machine or leave blank for default [22]:")
|
||||
[ -z "$port" ] && port=22
|
||||
keypath=$($roficmd "Enter path to private key (leave blank if not needed or if unsure):")
|
||||
if ! printf "%s\n%s\n%d\n%s\n" "$username" "$host" "$port" "$keypath" | run -s; then
|
||||
logger "Aniwrapper was unable to sync the databases..."
|
||||
exit 1
|
||||
else
|
||||
@ -293,3 +290,10 @@ case "$selection" in
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
parse_args "$@"
|
||||
logger "CONFIG DIR: $CFG_DIR"
|
||||
logger "ROFI CFG: $CFG_FILE"
|
||||
check_flags
|
||||
main
|
||||
|
Loading…
Reference in New Issue
Block a user