convert tabs to spaces

This commit is contained in:
ksyasuda 2022-02-07 12:06:31 -08:00
parent b272fc3994
commit fa958884bb
3 changed files with 1142 additions and 1142 deletions

1578
ani-cli

File diff suppressed because it is too large Load Diff

View File

@ -34,9 +34,9 @@ theme=default
# Functions # # Functions #
############# #############
help_text() { help_text() {
while IFS= read -r line; do while IFS= read -r line; do
printf "%s\n" "$line" printf "%s\n" "$line"
done <<< " done <<< "
Usage: Usage:
aniwrapper [-dhpqSv] [-t <theme> | -T <config_path>] [<query>] aniwrapper [-dhpqSv] [-t <theme> | -T <config_path>] [<query>]
aniwrapper -f <directory_path> [-t <theme> | -T <config_path>] [-pSv] [<query>]\ aniwrapper -f <directory_path> [-t <theme> | -T <config_path>] [-pSv] [<query>]\
@ -60,368 +60,368 @@ Options:
} }
lg() { lg() {
if ((VERBOSE == 1)); then if ((VERBOSE == 1)); then
inf "$*" inf "$*"
fi fi
} }
# display an informational message (first argument in green, second in magenta) # display an informational message (first argument in green, second in magenta)
inf() { inf() {
printf "\033[1;32m%s \033[1;35m%s\033[0m\n" "$1" "$2" printf "\033[1;32m%s \033[1;35m%s\033[0m\n" "$1" "$2"
} }
# prompts the user with message in $1-2 ($1 in blue, $2 in magenta) and saves the input to the variables in $REPLY and $REPLY2 # prompts the user with message in $1-2 ($1 in blue, $2 in magenta) and saves the input to the variables in $REPLY and $REPLY2
prompt() { prompt() {
printf "\033[1;34m%s\033[1;35m%s\033[1;34m: \033[0m" "$1" "$2" printf "\033[1;34m%s\033[1;35m%s\033[1;34m: \033[0m" "$1" "$2"
} }
seppuku() { seppuku() {
printf "%s\n" "$*" printf "%s\n" "$*"
exit 1 exit 1
} }
quit() { quit() {
((SILENT != 1)) && lg 'Quitting...' ((SILENT != 1)) && lg 'Quitting...'
exit 0 exit 0
} }
run() { run() {
if ((IS_PLAY_FROM_FILE == 0 && IS_SYNC == 0 && GET_QUALITY == 1)); then if ((IS_PLAY_FROM_FILE == 0 && IS_SYNC == 0 && GET_QUALITY == 1)); then
get_quality get_quality
fi fi
if ((SILENT == 1)); then if ((SILENT == 1)); then
if ((IS_CUSTOM_THEME == 0)); then if ((IS_CUSTOM_THEME == 0)); then
"$CMD" -D"$DPI" -Sq "$QUALITY" -t "$theme" -p "$PLAYER_FN" "$@" "$CMD" -D"$DPI" -Sq "$QUALITY" -t "$theme" -p "$PLAYER_FN" "$@"
else else
"$CMD" -D"$DPI" -Sq "$QUALITY" -T "$CFG_FILE" -p "$PLAYER_FN" "$@" "$CMD" -D"$DPI" -Sq "$QUALITY" -T "$CFG_FILE" -p "$PLAYER_FN" "$@"
fi fi
elif ((VERBOSE == 1)); then elif ((VERBOSE == 1)); then
if ((IS_CUSTOM_THEME == 0)); then if ((IS_CUSTOM_THEME == 0)); then
"$CMD" -D"$DPI" -vq "$QUALITY" -t "$theme" -p "$PLAYER_FN" "$@" "$CMD" -D"$DPI" -vq "$QUALITY" -t "$theme" -p "$PLAYER_FN" "$@"
else else
"$CMD" -D"$DPI" -vq "$QUALITY" -T "$CFG_FILE" -p "$PLAYER_FN" "$@" "$CMD" -D"$DPI" -vq "$QUALITY" -T "$CFG_FILE" -p "$PLAYER_FN" "$@"
fi fi
else else
if ((IS_CUSTOM_THEME == 0)); then if ((IS_CUSTOM_THEME == 0)); then
"$CMD" -D"$DPI" -q "$QUALITY" -t "$theme" -p "$PLAYER_FN" "$@" "$CMD" -D"$DPI" -q "$QUALITY" -t "$theme" -p "$PLAYER_FN" "$@"
else else
"$CMD" -D"$DPI" -q "$QUALITY" -T "$CFG_FILE" -p "$PLAYER_FN" "$@" "$CMD" -D"$DPI" -q "$QUALITY" -T "$CFG_FILE" -p "$PLAYER_FN" "$@"
fi fi
fi fi
} }
get_quality() { get_quality() {
if ((IS_ROFI == 1)); then if ((IS_ROFI == 1)); then
selection=$(rofi -dpi "$DPI" -dmenu -config "$CFG_FILE" \ selection=$(rofi -dpi "$DPI" -dmenu -config "$CFG_FILE" \
-l 5 -selected-row 0 -a 0 \ -l 5 -selected-row 0 -a 0 \
-theme-str 'listview {columns: 1;} window {width: 20%;}' \ -theme-str 'listview {columns: 1;} window {width: 20%;}' \
-p "Choose video quality:" \ -p "Choose video quality:" \
-sep '|' -only-match <<< "$QUALITIES") -sep '|' -only-match <<< "$QUALITIES")
QUALITY=$(awk '{print $2}' <<< "$selection") QUALITY=$(awk '{print $2}' <<< "$selection")
else else
qualities="best|1080p|720p|480p|360p|worst" qualities="best|1080p|720p|480p|360p|worst"
prompt "Choose quality " "[$qualities]" prompt "Choose quality " "[$qualities]"
read -r QUALITY read -r QUALITY
while [[ ! "$QUALITY" =~ ($qualities) ]]; do while [[ ! "$QUALITY" =~ ($qualities) ]]; do
lg "$QUALITY not a valid quality -> [$qualities]" lg "$QUALITY not a valid quality -> [$qualities]"
prompt "Choose quality " "[$qualities]" prompt "Choose quality " "[$qualities]"
read -r QUALITY read -r QUALITY
done done
fi fi
lg "selected quality: $QUALITY" lg "selected quality: $QUALITY"
} }
# generates a span mesg for rofi given # generates a span mesg for rofi given
# input: message: str # input: message: str
generate_span() { generate_span() {
msg="$*" msg="$*"
span="<span foreground='#ecbe7b' style='italic' size='small'>$msg</span>" span="<span foreground='#ecbe7b' style='italic' size='small'>$msg</span>"
printf "%s\n" "$span" printf "%s\n" "$span"
} }
set_theme() { set_theme() {
new_theme="$1" new_theme="$1"
case "$new_theme" in case "$new_theme" in
aniwrapper) aniwrapper)
ROFI_THEME=aniwrapper.rasi ROFI_THEME=aniwrapper.rasi
;; ;;
dracula) dracula)
ROFI_THEME=aniwrapper-dracula.rasi ROFI_THEME=aniwrapper-dracula.rasi
;; ;;
doomone | doom-one) doomone | doom-one)
ROFI_THEME=aniwrapper-doomone.rasi ROFI_THEME=aniwrapper-doomone.rasi
;; ;;
fancy) fancy)
ROFI_THEME=aniwrapper-fancy.rasi ROFI_THEME=aniwrapper-fancy.rasi
;; ;;
flamingo) flamingo)
ROFI_THEME=aniwrapper-flamingo.rasi ROFI_THEME=aniwrapper-flamingo.rasi
;; ;;
material) material)
ROFI_THEME=aniwrapper-material.rasi ROFI_THEME=aniwrapper-material.rasi
;; ;;
nord) nord)
ROFI_THEME=aniwrapper-nord.rasi ROFI_THEME=aniwrapper-nord.rasi
;; ;;
onedark) onedark)
ROFI_THEME=aniwrapper-onedark.rasi ROFI_THEME=aniwrapper-onedark.rasi
;; ;;
*) *)
seppuku "$theme not a valid theme file. Themes: [$THEMES]" seppuku "$theme not a valid theme file. Themes: [$THEMES]"
;; ;;
esac esac
lg "Chosen theme -> $ROFI_THEME" lg "Chosen theme -> $ROFI_THEME"
CFG_FILE="$CFG_DIR/themes/$ROFI_THEME" CFG_FILE="$CFG_DIR/themes/$ROFI_THEME"
} }
parse_args() { parse_args() {
while getopts 'vhqcdf:-:t:T:CQ:D:Sp' OPT; do while getopts 'vhqcdf:-:t:T:CQ:D:Sp' OPT; do
case "$OPT" in case "$OPT" in
h) h)
help_text help_text
exit 0 exit 0
;; ;;
v) v)
VERBOSE=1 VERBOSE=1
;; ;;
q) q)
GET_QUALITY=1 GET_QUALITY=1
lg "Quality prompt enabled" lg "Quality prompt enabled"
;; ;;
c) c)
IS_ROFI=0 IS_ROFI=0
lg "Command-line (ani-cli) mode set" lg "Command-line (ani-cli) mode set"
;; ;;
d) d)
IS_DOWNLOAD=1 IS_DOWNLOAD=1
lg "Download flag set..." lg "Download flag set..."
;; ;;
f) f)
IS_PLAY_FROM_FILE=1 IS_PLAY_FROM_FILE=1
play_path="$OPTARG" play_path="$OPTARG"
lg "Play from file flag set... skipping main menu" lg "Play from file flag set... skipping main menu"
lg "PLAY_PATH: $play_path" lg "PLAY_PATH: $play_path"
;; ;;
t) t)
theme="$OPTARG" theme="$OPTARG"
set_theme "$theme" set_theme "$theme"
;; ;;
C) C)
lg "Connecting to history database -> $CFG_DIR/history.sqlite3" lg "Connecting to history database -> $CFG_DIR/history.sqlite3"
sqlite3 "$CFG_DIR/history.sqlite3" sqlite3 "$CFG_DIR/history.sqlite3"
exit $? exit $?
;; ;;
Q) Q)
query="$OPTARG" query="$OPTARG"
lg "DATABASE QUERY: $query" lg "DATABASE QUERY: $query"
sqlite3 -line "$CFG_DIR/history.sqlite3" "$query" sqlite3 -line "$CFG_DIR/history.sqlite3" "$query"
exit $? exit $?
;; ;;
T) T)
CFG_FILE="$OPTARG" CFG_FILE="$OPTARG"
[ ! -f "$CFG_FILE" ] && seppuku "config file $CFG_FILE does not exist" [ ! -f "$CFG_FILE" ] && seppuku "config file $CFG_FILE does not exist"
IS_CUSTOM_THEME=1 IS_CUSTOM_THEME=1
;; ;;
D) D)
DPI="$OPTARG" DPI="$OPTARG"
;; ;;
S) S)
SILENT=1 SILENT=1
;; ;;
p) p)
IS_ALTERNATE_PLAYER=1 IS_ALTERNATE_PLAYER=1
;; ;;
*) *)
help_text help_text
exit 1 exit 1
;; ;;
esac esac
done done
} }
get_player() { get_player() {
msg1="Choose from the supported players, or supply your own player command (full functionality not guaranteed)" msg1="Choose from the supported players, or supply your own player command (full functionality not guaranteed)"
msg2="if using an unsupported player, it must be able to play URLs for streaming from the internet" msg2="if using an unsupported player, it must be able to play URLs for streaming from the internet"
if ((IS_ROFI == 1)); then if ((IS_ROFI == 1)); then
PLAYER_FN=$( PLAYER_FN=$(
awk '{print $NF}' < <(rofi -dmenu -config "$CFG_FILE" -DPI "$DPI" \ awk '{print $NF}' < <(rofi -dmenu -config "$CFG_FILE" -DPI "$DPI" \
-l 4 -theme-str 'listview {columns: 1;} window {width: 40%;}' \ -l 4 -theme-str 'listview {columns: 1;} window {width: 40%;}' \
-p "Enter video player:" \ -p "Enter video player:" \
-mesg "$(printf "%s\n%s\n" "$(generate_span "$msg1")" "$(generate_span "$msg2")")" \ -mesg "$(printf "%s\n%s\n" "$(generate_span "$msg1")" "$(generate_span "$msg2")")" \
-a 0 -sep '|' <<< "$SUPPORTED_PLAYERS") -a 0 -sep '|' <<< "$SUPPORTED_PLAYERS")
) )
else else
printf "%s\n%s\n" "$msg1" "$msg2" printf "%s\n%s\n" "$msg1" "$msg2"
printf "%s\n" "SUPPORTED PLAYERS:" printf "%s\n" "SUPPORTED PLAYERS:"
# while read -r player; do # while read -r player; do
# printf "%s\n" "$player" # printf "%s\n" "$player"
# done <<< "$(printf "%s\n" "$SUPPORTED_PLAYERS" | sed 's/|/\n/g')" # done <<< "$(printf "%s\n" "$SUPPORTED_PLAYERS" | sed 's/|/\n/g')"
# bash version # bash version
while IFS='|' read -ra players; do while IFS='|' read -ra players; do
printf "%s\n" "${players[@]}" printf "%s\n" "${players[@]}"
done <<< "$SUPPORTED_PLAYERS" done <<< "$SUPPORTED_PLAYERS"
prompt "Enter player" prompt "Enter player"
read -r PLAYER_FN read -r PLAYER_FN
fi fi
[ -z "$PLAYER_FN" ] && PLAYER_FN=mpv [ -z "$PLAYER_FN" ] && PLAYER_FN=mpv
if ! command -v "$PLAYER_FN" > /dev/null; then if ! command -v "$PLAYER_FN" > /dev/null; then
seppuku "ERROR: $PLAYER_FN does not exist" seppuku "ERROR: $PLAYER_FN does not exist"
fi fi
} }
check_flags() { check_flags() {
# Check if command-line flag is set # Check if command-line flag is set
if ((VERBOSE == 1 && SILENT == 1)); then if ((VERBOSE == 1 && SILENT == 1)); then
seppuku "verbose and silent options cannot be used together" seppuku "verbose and silent options cannot be used together"
fi fi
if ((IS_DOWNLOAD == 0 && IS_ALTERNATE_PLAYER == 1)); then if ((IS_DOWNLOAD == 0 && IS_ALTERNATE_PLAYER == 1)); then
get_player get_player
lg "SELECTED PLAYER FN -> $PLAYER_FN" lg "SELECTED PLAYER FN -> $PLAYER_FN"
fi fi
if ((IS_ROFI == 0 && IS_DOWNLOAD == 0)); then if ((IS_ROFI == 0 && IS_DOWNLOAD == 0)); then
run -c "$@" run -c "$@"
exit $? exit $?
elif ((IS_ROFI == 0 && IS_DOWNLOAD == 1)); then elif ((IS_ROFI == 0 && IS_DOWNLOAD == 1)); then
prompt "Enter download directory" prompt "Enter download directory"
read -r dl_dir read -r dl_dir
lg "Download dir: $dl_dir" lg "Download dir: $dl_dir"
if [ ! -d "$dl_dir" ]; then if [ ! -d "$dl_dir" ]; then
mkdir -p "$dl_dir" || seppuku "Error creating directory: $dl_dir" mkdir -p "$dl_dir" || seppuku "Error creating directory: $dl_dir"
fi fi
run "-cd $dl_dir" "$@" run "-cd $dl_dir" "$@"
exit $? exit $?
elif ((IS_ROFI == 1 && IS_PLAY_FROM_FILE == 1 && IS_CUSTOM_THEME == 1)); then elif ((IS_ROFI == 1 && IS_PLAY_FROM_FILE == 1 && IS_CUSTOM_THEME == 1)); then
run "-f$play_path" -T "$CFG_FILE" "$@" run "-f$play_path" -T "$CFG_FILE" "$@"
exit $? exit $?
elif ((IS_ROFI == 1 && IS_PLAY_FROM_FILE == 1 && IS_CUSTOM_THEME == 0)); then elif ((IS_ROFI == 1 && IS_PLAY_FROM_FILE == 1 && IS_CUSTOM_THEME == 0)); then
run "-f$play_path" -t "$theme" "$@" run "-f$play_path" -t "$theme" "$@"
exit $? exit $?
fi fi
} }
get_dl_dir() { get_dl_dir() {
dl_dir=$( dl_dir=$(
rofi -dpi "$DPI" -dmenu -config "$CFG_FILE" \ rofi -dpi "$DPI" -dmenu -config "$CFG_FILE" \
-theme-str 'listview {columns: 1;} window {width: 45%;}' \ -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/")" \ -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:" -l 1 -p "Enter download dir:"
) )
# if dl_dir is none set to current directory # if dl_dir is none set to current directory
[ "$dl_dir" == "" ] && dl_dir="$DEFAULT_DOWNLOAD" [ "$dl_dir" == "" ] && dl_dir="$DEFAULT_DOWNLOAD"
if [ ! -d "$dl_dir" ]; then if [ ! -d "$dl_dir" ]; then
mkdir -p "$dl_dir" || seppuku "Error creating directory: $dl_dir" mkdir -p "$dl_dir" || seppuku "Error creating directory: $dl_dir"
fi fi
} }
######## ########
# Main # # Main #
######## ########
main() { main() {
((SILENT != 1)) && lg "CONFIG DIR: $CFG_DIR" ((SILENT != 1)) && lg "CONFIG DIR: $CFG_DIR"
((SILENT != 1)) && lg "ROFI CFG: $CFG_FILE" ((SILENT != 1)) && lg "ROFI CFG: $CFG_FILE"
choice=$(echo "${options[@]}" | rofi -dpi "$DPI" -dmenu -only-match -sep '|' \ choice=$(echo "${options[@]}" | rofi -dpi "$DPI" -dmenu -only-match -sep '|' \
-theme-str 'listview {columns: 1;} window {width: 45%;}' \ -theme-str 'listview {columns: 1;} window {width: 45%;}' \
-config "$CFG_FILE" -l 7 -i -p "Aniwrapper") -config "$CFG_FILE" -l 7 -i -p "Aniwrapper")
[ "$choice" == "$quit" ] && quit [ "$choice" == "$quit" ] && quit
selection=$(printf "%s\n" "$choice" | awk '{ print $1 }') selection=$(printf "%s\n" "$choice" | awk '{ print $1 }')
case "$selection" in case "$selection" in
1.) 1.)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# streaming # streaming
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
lg "Streaming mode" lg "Streaming mode"
run run
;; ;;
2.) 2.)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# download # download
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
lg "Download anime" lg "Download anime"
get_dl_dir && run -d "$dl_dir" get_dl_dir && run -d "$dl_dir"
;; ;;
3.) 3.)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# continue # continue
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
lg "Continue watching" lg "Continue watching"
run -H run -H
;; ;;
4.) 4.)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# play # play
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
lg "Play from file selected" lg "Play from file selected"
IS_PLAY_FROM_FILE=1 IS_PLAY_FROM_FILE=1
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")") 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 -dpi "$DPI" -dmenu -config "$CFG_FILE" \ play_dir=$(rofi -dpi "$DPI" -dmenu -config "$CFG_FILE" \
-theme-str 'listview {columns: 1;} window {width: 45%;}' \ -theme-str 'listview {columns: 1;} window {width: 45%;}' \
-l 1 -mesg "$span" -p "Enter path to starting directory:") -l 1 -mesg "$span" -p "Enter path to starting directory:")
if [ -z "$play_dir" ]; then if [ -z "$play_dir" ]; then
mkdir -p "$DEFAULT_DOWNLOAD" || seppuku "error creating default download directory" mkdir -p "$DEFAULT_DOWNLOAD" || seppuku "error creating default download directory"
run -f"$DEFAULT_DOWNLOAD" run -f"$DEFAULT_DOWNLOAD"
else else
run -f"$play_dir" run -f"$play_dir"
fi fi
exit $? exit $?
;; ;;
5.) 5.)
lg "Sync history database" lg "Sync history database"
IS_SYNC=1 IS_SYNC=1
roficmd="rofi -dpi $DPI -dmenu -config $CFG_FILE -l 0 -p" roficmd="rofi -dpi $DPI -dmenu -config $CFG_FILE -l 0 -p"
username=$($roficmd "Enter the username of the remote user:" -theme-str 'window {width: 45%;}') username=$($roficmd "Enter the username of the remote user:" -theme-str 'window {width: 45%;}')
[ -z "$username" ] && seppuku "No username provided... exiting" [ -z "$username" ] && seppuku "No username provided... exiting"
host=$($roficmd "Enter the host for the remote machine (eg 192.168.1.99):" -theme-str 'window {width: 45%;}') host=$($roficmd "Enter the host for the remote machine (eg 192.168.1.99):" -theme-str 'window {width: 45%;}')
[ -z "$host" ] && seppuku "No host provided... exiting" [ -z "$host" ] && seppuku "No host provided... exiting"
port=$($roficmd "Enter in the ssh port for remote machine or leave blank for default [22]:" -theme-str 'window {width: 45%;}') port=$($roficmd "Enter in the ssh port for remote machine or leave blank for default [22]:" -theme-str 'window {width: 45%;}')
[ -z "$port" ] && port=22 [ -z "$port" ] && port=22
keypath=$($roficmd "Enter path to private key (leave blank if not needed or if unsure):" -theme-str 'window {width: 45%;}') keypath=$($roficmd "Enter path to private key (leave blank if not needed or if unsure):" -theme-str 'window {width: 45%;}')
if ! printf "%s\n%s\n%d\n%s\n" "$username" "$host" "$port" "$keypath" | run -s; then if ! printf "%s\n%s\n%d\n%s\n" "$username" "$host" "$port" "$keypath" | run -s; then
lg "Aniwrapper was unable to sync the databases..." lg "Aniwrapper was unable to sync the databases..."
exit 1 exit 1
else else
lg "Databases synced successfully" lg "Databases synced successfully"
quit quit
fi fi
;; ;;
6.) 6.)
# ----------------------------------------------------------------- # -----------------------------------------------------------------
# choose theme # choose theme
# ----------------------------------------------------------------- # -----------------------------------------------------------------
[ -z "$THEMES" ] && seppuku "No themes provided... exiting" [ -z "$THEMES" ] && seppuku "No themes provided... exiting"
choice=$(rofi -dmenu -config "$CFG_FILE" -dpi "$DPI" \ choice=$(rofi -dmenu -config "$CFG_FILE" -dpi "$DPI" \
-theme-str 'listview {columns: 1;} window {width: 45%;}' \ -theme-str 'listview {columns: 1;} window {width: 45%;}' \
-only-match -l 4 -i -p "Choose theme: " -sep '|' \ -only-match -l 4 -i -p "Choose theme: " -sep '|' \
-theme-str 'listview { columns: 2; }' <<< "$THEMES") -theme-str 'listview { columns: 2; }' <<< "$THEMES")
theme=$(awk '{ print $1 }' <<< "$choice") theme=$(awk '{ print $1 }' <<< "$choice")
set_theme "$theme" set_theme "$theme"
main main
;; ;;
7.) 7.)
# ----------------------------------------------------------------- # -----------------------------------------------------------------
# get out # get out
# ----------------------------------------------------------------- # -----------------------------------------------------------------
quit quit
;; ;;
*) *)
help_text help_text
;; ;;
esac esac
} }
parse_args "$@" parse_args "$@"
shift $((OPTIND - 1)) shift $((OPTIND - 1))
if [ $# -gt 0 ]; then if [ $# -gt 0 ]; then
check_flags "$*" check_flags "$*"
if [ "$IS_DOWNLOAD" -eq 0 ]; then if [ "$IS_DOWNLOAD" -eq 0 ]; then
run "$*" run "$*"
elif [ "$IS_DOWNLOAD" -eq 1 ]; then elif [ "$IS_DOWNLOAD" -eq 1 ]; then
get_dl_dir && run -d "$dl_dir" "$*" get_dl_dir && run -d "$dl_dir" "$*"
fi fi
else else
check_flags check_flags
main main
fi fi

View File

@ -8,16 +8,16 @@
VERBOSE=0 VERBOSE=0
log() { log() {
if [[ "$VERBOSE" -eq 1 ]]; then if [[ "$VERBOSE" -eq 1 ]]; then
printf "%s\n" "$*" printf "%s\n" "$*"
fi fi
} }
if [[ $# -ge 1 ]]; then if [[ $# -ge 1 ]]; then
if [[ "$1" == "-v" || "$1" == "--verbose" ]]; then if [[ "$1" == "-v" || "$1" == "--verbose" ]]; then
VERBOSE=1 VERBOSE=1
log "VERBOSE LOGGING ENABLED" log "VERBOSE LOGGING ENABLED"
fi fi
fi fi
DB="history.sqlite3" DB="history.sqlite3"
@ -35,48 +35,48 @@ log "MPV DIR:" "$MPV_DIR"
# 4. move skip-intro.lua into mpv/scripts folder # 4. move skip-intro.lua into mpv/scripts folder
# 5. move the aniwrapper icon to $XDG_CONFIG_HOME/aniwrapper/ directory # 5. move the aniwrapper icon to $XDG_CONFIG_HOME/aniwrapper/ directory
run_setup() { run_setup() {
log "INSTALL DIR: $DIR" log "INSTALL DIR: $DIR"
if [[ ! -d "$DIR" ]]; then if [[ ! -d "$DIR" ]]; then
log "Creating directory $DIR" log "Creating directory $DIR"
mkdir -p "$DIR" mkdir -p "$DIR"
log "Directory created" log "Directory created"
fi fi
if [[ ! -f "$DIR/$DB" ]]; then if [[ ! -f "$DIR/$DB" ]]; then
log "CREATING HISTORY DATABASE" log "CREATING HISTORY DATABASE"
sqlite3 "$DIR/$DB" < sql/search_history_tbl.sql sqlite3 "$DIR/$DB" < sql/search_history_tbl.sql
sqlite3 "$DIR/$DB" < sql/watch_history_tbl.sql sqlite3 "$DIR/$DB" < sql/watch_history_tbl.sql
sqlite3 "$DIR/$DB" < sql/file_history.sql sqlite3 "$DIR/$DB" < sql/file_history.sql
log "FINISHED CREATING DB" log "FINISHED CREATING DB"
fi fi
# log "themes directory does not exist in filesystem... Creating and moving themes" # log "themes directory does not exist in filesystem... Creating and moving themes"
mkdir -p "$DIR/themes" mkdir -p "$DIR/themes"
cp themes/* "$DIR/themes/" cp themes/* "$DIR/themes/"
log "Theme files moved..." log "Theme files moved..."
log "Creating mpv/scripts/ directory if it doesn't exist..." log "Creating mpv/scripts/ directory if it doesn't exist..."
mkdir -p "$MPV_DIR/scripts/" mkdir -p "$MPV_DIR/scripts/"
if [[ ! -f "$MPV_DIR/scripts/skip-intro.lua" ]]; then if [[ ! -f "$MPV_DIR/scripts/skip-intro.lua" ]]; then
log "Moving skip-intro.lua into mpv scripts directory..." log "Moving skip-intro.lua into mpv scripts directory..."
cp lua/skip-intro.lua "$MPV_DIR/scripts/" cp lua/skip-intro.lua "$MPV_DIR/scripts/"
log "Moved skip-intro.lua into scripts directory..." log "Moved skip-intro.lua into scripts directory..."
else else
log "skip-intro.lua already exists in $XDG_CONFIG_HOME/mpv/scripts/... skipping" log "skip-intro.lua already exists in $XDG_CONFIG_HOME/mpv/scripts/... skipping"
fi fi
if [[ ! -d "$DIR/icons" ]]; then if [[ ! -d "$DIR/icons" ]]; then
log "Creating icons directory" log "Creating icons directory"
mkdir -p "$DIR/icons" mkdir -p "$DIR/icons"
fi fi
cp .assets/icons/* "$DIR/icons/" cp .assets/icons/* "$DIR/icons/"
log "Installed icons in config directory..." log "Installed icons in config directory..."
} }
if run_setup; then if run_setup; then
log "Setup Complete...." log "Setup Complete...."
else else
printf "%s\n" "There was an error during setup" printf "%s\n" "There was an error during setup"
exit 1 exit 1
fi fi