mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-10-28 04:44:11 -07:00
update to v3 functions (#8)
* update to v3 functions * fix progress prompt appearing in rofi menus * modularize UI in ani-cli for rofi vs cli
This commit is contained in:
parent
737d54bcd2
commit
bd949bb7c7
12
aniwrapper
12
aniwrapper
@ -2,9 +2,6 @@
|
|||||||
|
|
||||||
set -Eeo pipefail
|
set -Eeo pipefail
|
||||||
|
|
||||||
#############
|
|
||||||
# Globals #
|
|
||||||
#############
|
|
||||||
CMD="/usr/bin/ani-cli"
|
CMD="/usr/bin/ani-cli"
|
||||||
CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/aniwrapper"
|
CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/aniwrapper"
|
||||||
CFG_FILE="$CFG_DIR/themes/aniwrapper.rasi"
|
CFG_FILE="$CFG_DIR/themes/aniwrapper.rasi"
|
||||||
@ -24,7 +21,7 @@ IS_PLAY_FROM_FILE=0
|
|||||||
IS_ROFI=1
|
IS_ROFI=1
|
||||||
IS_SYNC=0
|
IS_SYNC=0
|
||||||
IS_ALTERNATE_PLAYER=0
|
IS_ALTERNATE_PLAYER=0
|
||||||
VERBOSE=0
|
IS_VERBOSE=0
|
||||||
SILENT=0
|
SILENT=0
|
||||||
|
|
||||||
quit="8. Quit"
|
quit="8. Quit"
|
||||||
@ -60,7 +57,7 @@ Options:
|
|||||||
}
|
}
|
||||||
|
|
||||||
lg() {
|
lg() {
|
||||||
if ((VERBOSE)); then
|
if ((IS_VERBOSE)); then
|
||||||
inf "$*"
|
inf "$*"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -94,6 +91,7 @@ run() {
|
|||||||
elif ((!IS_CUSTOM_THEME)); then
|
elif ((!IS_CUSTOM_THEME)); then
|
||||||
args+=(-t"$theme")
|
args+=(-t"$theme")
|
||||||
fi
|
fi
|
||||||
|
lg "Running $CMD ${args[*]} -D$DPI $*"
|
||||||
$CMD "${args[@]}" -D"$DPI" "$@"
|
$CMD "${args[@]}" -D"$DPI" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -218,7 +216,7 @@ parse_args() {
|
|||||||
IS_CUSTOM_THEME=1
|
IS_CUSTOM_THEME=1
|
||||||
;;
|
;;
|
||||||
v)
|
v)
|
||||||
VERBOSE=1
|
IS_VERBOSE=1
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
help_text
|
help_text
|
||||||
@ -256,7 +254,7 @@ get_player() {
|
|||||||
|
|
||||||
# Check passed in flags and set cli arguments
|
# Check passed in flags and set cli arguments
|
||||||
check_flags() {
|
check_flags() {
|
||||||
if ((VERBOSE && SILENT)); then
|
if ((IS_VERBOSE && SILENT)); then
|
||||||
die "verbose and silent options cannot be used together"
|
die "verbose and silent options cannot be used together"
|
||||||
fi
|
fi
|
||||||
if ((IS_DOWNLOAD && IS_AUTOPLAY)); then
|
if ((IS_DOWNLOAD && IS_AUTOPLAY)); then
|
||||||
|
157
lib/ani-cli/UI
Normal file
157
lib/ani-cli/UI
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
VERSION="1.0.0"
|
||||||
|
|
||||||
|
retry() {
|
||||||
|
err "$*"
|
||||||
|
prompt
|
||||||
|
}
|
||||||
|
|
||||||
|
# display error message and exit
|
||||||
|
die() {
|
||||||
|
((!SILENT)) && printf "\033[1;31m%s\033[0m\n" "$*" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# display an error message to stderr (in red)
|
||||||
|
err() {
|
||||||
|
((!SILENT)) && printf "\33[2K\r\033[1;31m%s\033[0m\n" "$*" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
# display a log message if verbose mode is enabled
|
||||||
|
lg() {
|
||||||
|
((VERBOSE)) && printf "\033[1;35m%s\033[0m\n" "$*" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
# display an informational message (first argument in green, second in magenta)
|
||||||
|
inf() {
|
||||||
|
printf "\33[2K\r\033[1;35m%s \033[1;35m%s\033[0m\n" "$1" "$2"
|
||||||
|
}
|
||||||
|
|
||||||
|
progress() {
|
||||||
|
((!SILENT)) && printf "\33[2K\r\033[1;34m%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
|
||||||
|
prompt() {
|
||||||
|
printf "\033[1;35m%s\033[1;35m%s\033[1;34m\033[0m: " "$1" "$2"
|
||||||
|
}
|
||||||
|
|
||||||
|
# displays an even (cyan) line of a menu line with $2 as an indicator in [] and $1 as the option
|
||||||
|
menu_line_even() {
|
||||||
|
printf "\033[1;36m(\033[1;36m%s\033[1;36m) \033[1;36m%s\033[0m\n" "$2" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# displays an odd (yellow) line of a menu line with $2 as an indicator in [] and $1 as the option
|
||||||
|
menu_line_odd() {
|
||||||
|
printf "\033[1;33m(\033[1;33m%s\033[1;33m) \033[1;33m%s\033[0m\n" "$2" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# display alternating menu lines (even and odd)
|
||||||
|
menu_line_alternate() {
|
||||||
|
menu_line_parity=${menu_line_parity:-0}
|
||||||
|
if [ "$menu_line_parity" -eq 0 ]; then
|
||||||
|
menu_line_odd "$1" "$2"
|
||||||
|
menu_line_parity=1
|
||||||
|
else
|
||||||
|
menu_line_even "$1" "$2"
|
||||||
|
menu_line_parity=0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# displays a warning (red) line of a menu line with $2 as an indicator in [] and $1 as the option
|
||||||
|
menu_line_strong() {
|
||||||
|
printf "\033[1;34m[\033[1;33m%s\033[1;34m] \033[1;33m%s\033[0m\n" "$2" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Select anime from query results
|
||||||
|
anime_selection() {
|
||||||
|
search_results=$*
|
||||||
|
count=1
|
||||||
|
while read -r anime_id; do
|
||||||
|
anime_id=$(printf "%s" "$anime_id" | sed -E 's/\-episode\-.*//')
|
||||||
|
menu_line_alternate "$anime_id" "$count"
|
||||||
|
: count=$((count += 1))
|
||||||
|
done <<< "$search_results"
|
||||||
|
prompt "Enter choice"
|
||||||
|
read -r choice
|
||||||
|
|
||||||
|
# Check if input is a number
|
||||||
|
[[ "$choice" -eq "$choice" ]] 2> /dev/null || die "Invalid number entered"
|
||||||
|
|
||||||
|
count=1
|
||||||
|
while read -r anime_id; do
|
||||||
|
if [[ "$count" -eq "$choice" ]]; then
|
||||||
|
anime_id=$(printf "%s" "$anime_id" | sed -E 's/\-episode\-.*//')
|
||||||
|
selection_id=$anime_id
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
count=$((count + 1))
|
||||||
|
done <<< "$search_results"
|
||||||
|
|
||||||
|
[[ -z "$selection_id" ]] && die "Invalid number entered"
|
||||||
|
insert_history "search" "$selection_id" &
|
||||||
|
lg "Selection: $selection_id"
|
||||||
|
progress "(Gogoanime) Searching Episodes.."
|
||||||
|
episode_list "$selection_id"
|
||||||
|
al_episode_list
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# select episode from query results
|
||||||
|
episode_selection() {
|
||||||
|
ep_choice_start=1
|
||||||
|
if [ -n "$LAST_EP_NUMBER" ]; then
|
||||||
|
[[ "$is_download" -eq 1 ]] &&
|
||||||
|
inf "Range of episodes can be specified:" "start_number end_number"
|
||||||
|
inf "Anime:" "$anime_id"
|
||||||
|
prompt "Choose episode " "[$FIRST_EP_NUMBER-$LAST_EP_NUMBER]"
|
||||||
|
read -r ep_choice_start ep_choice_end
|
||||||
|
[[ -z "$ep_choice_end" ]] && ep_choice_end="$ep_choice_start"
|
||||||
|
fi
|
||||||
|
if (((ep_choice_start < 0 || ep_choice_start > LAST_EP_NUMBER) || ep_choice_end < ep_choice_start || ep_choice_end > LAST_EP_NUMBER)); then
|
||||||
|
die "Invalid episode/range entered: ep_start -> $ep_choice_start | ep_end -> $ep_choice_end"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
continue_watching() {
|
||||||
|
inf "Continue watching $selection_id?"
|
||||||
|
prompt "Next episode -> $((episode + 1)) [Y/n]"
|
||||||
|
read -r choice
|
||||||
|
[ -z "$choice" ] && choice="y"
|
||||||
|
[[ "$choice" =~ ^(y|Y|Yes)$ ]] && return 0 || return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# get the search query from user or from args
|
||||||
|
get_search_query() {
|
||||||
|
if [ $# -gt 0 ]; then
|
||||||
|
query="${*// /-}"
|
||||||
|
else
|
||||||
|
prompt "Search Anime"
|
||||||
|
read -r query
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
get_dl_dir() {
|
||||||
|
prompt "Enter download directory"
|
||||||
|
read -r download_dir
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
# sets the video quality
|
||||||
|
set_video_quality() {
|
||||||
|
((IS_MP4)) && qualities="best|1080p|720p|480p|360p|worst" || qualities="best|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
|
||||||
|
[ -z "$quality" ] && die "No quality selected"
|
||||||
|
}
|
||||||
|
|
||||||
|
# vim :ft=sh
|
211
lib/ani-cli/UI-ROFI
Normal file
211
lib/ani-cli/UI-ROFI
Normal file
@ -0,0 +1,211 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
VERSION="1.0.0"
|
||||||
|
|
||||||
|
retry() {
|
||||||
|
err "$*"
|
||||||
|
prompt
|
||||||
|
}
|
||||||
|
|
||||||
|
# display error message and exit
|
||||||
|
die() {
|
||||||
|
((!SILENT)) && printf "\033[1;31m%s\033[0m\n" "$*" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# display an error message to stderr (in red)
|
||||||
|
err() {
|
||||||
|
((!SILENT)) && printf "\33[2K\r\033[1;31m%s\033[0m\n" "$*" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
# display a log message if verbose mode is enabled
|
||||||
|
lg() {
|
||||||
|
((VERBOSE)) && printf "\033[1;35m%s\033[0m\n" "$*" >&2
|
||||||
|
}
|
||||||
|
|
||||||
|
# display an informational message (first argument in green, second in magenta)
|
||||||
|
inf() {
|
||||||
|
printf "\33[2K\r\033[1;35m%s \033[1;35m%s\033[0m\n" "$1" "$2"
|
||||||
|
}
|
||||||
|
|
||||||
|
progress() {
|
||||||
|
((!SILENT)) && printf "\33[2K\r\033[1;34m%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
|
||||||
|
prompt() {
|
||||||
|
printf "\033[1;35m%s\033[1;35m%s\033[1;34m\033[0m: " "$1" "$2"
|
||||||
|
}
|
||||||
|
|
||||||
|
# displays an even (cyan) line of a menu line with $2 as an indicator in [] and $1 as the option
|
||||||
|
menu_line_even() {
|
||||||
|
printf "\033[1;36m(\033[1;36m%s\033[1;36m) \033[1;36m%s\033[0m\n" "$2" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# displays an odd (yellow) line of a menu line with $2 as an indicator in [] and $1 as the option
|
||||||
|
menu_line_odd() {
|
||||||
|
printf "\033[1;33m(\033[1;33m%s\033[1;33m) \033[1;33m%s\033[0m\n" "$2" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# display alternating menu lines (even and odd)
|
||||||
|
menu_line_alternate() {
|
||||||
|
menu_line_parity=${menu_line_parity:-0}
|
||||||
|
if [ "$menu_line_parity" -eq 0 ]; then
|
||||||
|
menu_line_odd "$1" "$2"
|
||||||
|
menu_line_parity=1
|
||||||
|
else
|
||||||
|
menu_line_even "$1" "$2"
|
||||||
|
menu_line_parity=0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# displays a warning (red) line of a menu line with $2 as an indicator in [] and $1 as the option
|
||||||
|
menu_line_strong() {
|
||||||
|
printf "\033[1;34m[\033[1;33m%s\033[1;34m] \033[1;33m%s\033[0m\n" "$2" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Select anime from query results
|
||||||
|
anime_selection() {
|
||||||
|
search_results=$*
|
||||||
|
menu=""
|
||||||
|
searched=""
|
||||||
|
cnt=0
|
||||||
|
while read -r anime_id; do
|
||||||
|
anime_id=$(printf "%s" "$anime_id" | sed -E 's/\-episode\-.*//')
|
||||||
|
[[ -z "$menu" ]] && menu="$((cnt + 1)). $anime_id" ||
|
||||||
|
menu="$menu|$((cnt + 1)). $anime_id"
|
||||||
|
if ! check_db "search" "$anime_id"; then
|
||||||
|
[[ -z "$searched" ]] && searched="$cnt" || searched="$searched, $cnt"
|
||||||
|
fi
|
||||||
|
((++cnt))
|
||||||
|
done <<< "$search_results"
|
||||||
|
menu="$menu|$((++cnt)). Search another anime|$((++cnt)). Quit"
|
||||||
|
|
||||||
|
# get the anime from indexed list
|
||||||
|
msg="$(generate_span "Query: $query")"
|
||||||
|
selection="$(rofi -dpi "$DPI" -dmenu -no-custom \
|
||||||
|
-async-pre-read 33 -config "$ROFI_CFG" -l 15 -i -sep '|' \
|
||||||
|
-mesg "$msg" -a "$searched" -p "Enter selection" -window-title 'aniwrapper' <<< "$menu")"
|
||||||
|
choice="${selection%%.*}" # remmove everything from . to end
|
||||||
|
lg "CHOICE: $choice"
|
||||||
|
if ((choice == cnt)); then
|
||||||
|
die "Quitting"
|
||||||
|
elif ((choice == --cnt)); then
|
||||||
|
stream
|
||||||
|
return $?
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if input is a number
|
||||||
|
[[ "$choice" -eq "$choice" ]] 2> /dev/null || die "Invalid number entered"
|
||||||
|
|
||||||
|
count=1
|
||||||
|
while read -r anime_id; do
|
||||||
|
if [[ "$count" -eq "$choice" ]]; then
|
||||||
|
anime_id=$(printf "%s" "$anime_id" | sed -E 's/\-episode\-.*//')
|
||||||
|
selection_id=$anime_id
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
count=$((count + 1))
|
||||||
|
done <<< "$search_results"
|
||||||
|
|
||||||
|
[[ -z "$selection_id" ]] && die "Invalid number entered"
|
||||||
|
insert_history "search" "$selection_id" &
|
||||||
|
lg "Selection: $selection_id"
|
||||||
|
progress "(Gogoanime) Searching Episodes.."
|
||||||
|
episode_list "$selection_id"
|
||||||
|
al_episode_list
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# select episode from query results
|
||||||
|
episode_selection() {
|
||||||
|
ep_choice_start=1
|
||||||
|
lg "Anime ID: $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=""
|
||||||
|
while read -r i; do
|
||||||
|
if ((FIRST_EP_NUMBER == 0)); then
|
||||||
|
[[ -z "$watch_history" ]] && watch_history="$((i))" || watch_history="$watch_history, $((i))"
|
||||||
|
else
|
||||||
|
[[ -z "$watch_history" ]] && watch_history="$((--i))" || watch_history="$watch_history, $((--i))"
|
||||||
|
fi
|
||||||
|
done < <(run_stmt "$stmt")
|
||||||
|
lg "Episode watch history -> $watch_history"
|
||||||
|
|
||||||
|
# get user choice and set the start and end
|
||||||
|
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 "$FIRST_EP_NUMBER" "$LAST_EP_NUMBER" |
|
||||||
|
rofi -dpi "$DPI" -dmenu -l 12 \
|
||||||
|
-theme-str 'window {width: 45%;}' \
|
||||||
|
-a "$watch_history" \
|
||||||
|
-p "Select Episode [$FIRST_EP_NUMBER, $LAST_EP_NUMBER]:" \
|
||||||
|
-mesg "$msg" -window-title 'aniwrapper' \
|
||||||
|
-config "$ROFI_CFG"
|
||||||
|
)
|
||||||
|
ep_choice_start=$(printf '%s\n' "${choice}" | awk '{print $1}')
|
||||||
|
ep_choice_end=$(printf '%s\n' "${choice}" | awk '{print $NF}')
|
||||||
|
lg "START: $ep_choice_start | END: $ep_choice_end"
|
||||||
|
if (((ep_choice_start < 0 || ep_choice_start > LAST_EP_NUMBER) || ep_choice_end < ep_choice_start || ep_choice_end > LAST_EP_NUMBER)); then
|
||||||
|
die "Invalid episode/range entered: ep_start -> $ep_choice_start | ep_end -> $ep_choice_end"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
continue_watching() {
|
||||||
|
msg="$(printf '%s\n%s' "$(generate_span "Anime: $anime_id")" "$(generate_span "Next episode: $((episode + 1))")")"
|
||||||
|
choice=$(rofi -dmenu -dpi "$DPI" -config "$ROFI_CFG" \
|
||||||
|
-theme-str 'listview {columns: 1;} window {width: 25%;}' \
|
||||||
|
-i -l 2 -no-custom -sep '|' -a 0 -mesg "$msg" \
|
||||||
|
-p "Continue watching?" -window-title 'aniwrapper' <<< "Yes|No")
|
||||||
|
[[ "$choice" =~ ^(y|Y|Yes)$ ]] && return 0 || return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# get the search query from user or from args
|
||||||
|
get_search_query() {
|
||||||
|
if [ $# -gt 0 ]; then
|
||||||
|
query="${*// /-}"
|
||||||
|
else
|
||||||
|
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")" \
|
||||||
|
-config "$ROFI_CFG" -window-title 'aniwrapper' < <(run_stmt "$stmt"))
|
||||||
|
query="${query//[1-9]*\. /}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
get_dl_dir() {
|
||||||
|
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'
|
||||||
|
)
|
||||||
|
[ -z "$download_dir" ] && download_dir="$HOME/Videos/sauce/"
|
||||||
|
if [ ! -d "$download_dir" ]; then
|
||||||
|
mkdir -p "$download_dir" || die "Error creating directory: $download_dir"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# sets the video quality
|
||||||
|
set_video_quality() {
|
||||||
|
((IS_MP4)) && qualities="1. best|2. 1080p|3. 720p|4. 480p|5. 360p|6. worst" || qualities="1. best|2. 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")
|
||||||
|
}
|
||||||
|
|
||||||
|
# vim :ft=sh
|
41
setup.sh
41
setup.sh
@ -7,7 +7,7 @@
|
|||||||
######################
|
######################
|
||||||
VERBOSE=0
|
VERBOSE=0
|
||||||
|
|
||||||
log() {
|
lg() {
|
||||||
if [[ "$VERBOSE" -eq 1 ]]; then
|
if [[ "$VERBOSE" -eq 1 ]]; then
|
||||||
printf "%s\n" "$*"
|
printf "%s\n" "$*"
|
||||||
fi
|
fi
|
||||||
@ -16,7 +16,7 @@ log() {
|
|||||||
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"
|
lg "VERBOSE lgGING ENABLED"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -25,8 +25,8 @@ DB="history.sqlite3"
|
|||||||
DIR="${XDG_CONFIG_HOME:-$HOME/.config}/aniwrapper"
|
DIR="${XDG_CONFIG_HOME:-$HOME/.config}/aniwrapper"
|
||||||
MPV_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/mpv"
|
MPV_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/mpv"
|
||||||
|
|
||||||
log "CONFIG DIR:" "$DIR"
|
lg "CONFIG DIR:" "$DIR"
|
||||||
log "MPV DIR:" "$MPV_DIR"
|
lg "MPV DIR:" "$MPV_DIR"
|
||||||
|
|
||||||
# executes aniwrapper setup
|
# executes aniwrapper setup
|
||||||
# 1. create the aniwrapper directory in $XDG_CONFIG_HOME
|
# 1. create the aniwrapper directory in $XDG_CONFIG_HOME
|
||||||
@ -35,43 +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"
|
lg "INSTALL DIR: $DIR"
|
||||||
|
|
||||||
if [[ ! -d "$DIR" ]]; then
|
if [[ ! -d "$DIR" ]]; then
|
||||||
log "Creating directory $DIR"
|
lg "Creating directory $DIR"
|
||||||
mkdir -p "$DIR"
|
mkdir -p "$DIR"
|
||||||
log "Directory created"
|
lg "Directory created"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log "CREATING HISTORY DATABASE IF NOT EXISTS"
|
lg "CREATING HISTORY DATABASE IF NOT EXISTS"
|
||||||
sqlite3 "$DIR/$DB" < sql/history.sql
|
sqlite3 "$DIR/$DB" < sql/history.sql
|
||||||
log "FINISHED CREATING DB"
|
lg "FINISHED CREATING DB"
|
||||||
|
|
||||||
# log "themes directory does not exist in filesystem... Creating and moving themes"
|
lg "INSTALLING UI FILES TO $DIR/lib/ani-cli"
|
||||||
|
mkdir -p "$DIR/lib/ani-cli"
|
||||||
|
cp -r lib/ani-cli/* "$DIR/lib/ani-cli/"
|
||||||
|
lg "FINISHED INSTALLING UI FILES"
|
||||||
|
|
||||||
|
# lg "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..."
|
lg "Theme files moved..."
|
||||||
|
|
||||||
log "Creating mpv/scripts/ directory if it doesn't exist..."
|
lg "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..."
|
lg "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..."
|
lg "Moved skip-intro.lua into scripts directory..."
|
||||||
else
|
else
|
||||||
log "skip-intro.lua already exists in $XDG_CONFIG_HOME/mpv/scripts/... skipping"
|
lg "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"
|
lg "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..."
|
lg "Installed icons in config directory..."
|
||||||
}
|
}
|
||||||
|
|
||||||
if run_setup; then
|
if run_setup; then
|
||||||
log "Setup Complete...."
|
lg "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
|
||||||
|
Loading…
Reference in New Issue
Block a user