mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-10-28 04:44:11 -07:00
add ability to disable rofi with -c flag
it's basically just ani-cli then, but I haven't found a way to do optional parameters in getopts yet
This commit is contained in:
parent
3009a6d72f
commit
e883c5fa6a
62
ani-cli
62
ani-cli
@ -290,7 +290,7 @@ get_search_query() {
|
||||
|
||||
msg="Choose from list of searched anime below, or enter a unique name of an anime to search for"
|
||||
span="<span foreground='peachpuff' style='italic' size='small' weight='light'>$msg</span>"
|
||||
if [ -z "$*" ]; then
|
||||
if [ -z "$*" ] && [ "$is_rofi" -eq 1 ]; then
|
||||
query=$(printf "%s\n" "${hist[@]}" |
|
||||
rofi -dmenu -l 12 -p "Search Anime:" \
|
||||
-mesg "$span" \
|
||||
@ -302,6 +302,9 @@ get_search_query() {
|
||||
# works with trailing '-' so remove for now
|
||||
# query="${query// /}"
|
||||
log "Query: $query"
|
||||
elif [ "$is_rofi" -eq 0 ]; then
|
||||
printf "Search Anime: "
|
||||
read -r query
|
||||
else
|
||||
query=$*
|
||||
fi
|
||||
@ -317,6 +320,7 @@ get_search_query() {
|
||||
anime_selection() {
|
||||
# Select anime from query results
|
||||
search_results=$*
|
||||
if [ "$is_rofi" -eq 1 ]; then
|
||||
count=1
|
||||
menu=()
|
||||
res=()
|
||||
@ -358,21 +362,43 @@ anime_selection() {
|
||||
# Remove period after number
|
||||
choice="${choice::-1}"
|
||||
name=$(printf '%s\n' "$user_input" | awk '{print $NF}')
|
||||
else
|
||||
menu_format_string='[%d] %s\n'
|
||||
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"
|
||||
|
||||
log "CHOICE: $name"
|
||||
count=1
|
||||
while read anime_id; do
|
||||
# alternating colors for menu
|
||||
[ $((count % 2)) -eq 0 ] &&
|
||||
menu_format_string=$menu_format_string_c1 ||
|
||||
menu_format_string=$menu_format_string_c2
|
||||
|
||||
printf "$menu_format_string" "$count" "$anime_id"
|
||||
count=$((count+1))
|
||||
done <<-EOF
|
||||
$search_results
|
||||
EOF
|
||||
|
||||
# User input
|
||||
printf "$c_blue%s$c_green" "Enter number: "
|
||||
read choice
|
||||
printf "$c_reset"
|
||||
name="$anime_id"
|
||||
fi
|
||||
|
||||
log "CHOICE: $choice"
|
||||
|
||||
if [ "$is_rofi" -eq 1 ]; then
|
||||
log "NAME: $name"
|
||||
|
||||
# check both choice and name are set
|
||||
if [[ ! "$choice" ]] || [[ ! "$name" ]]; then
|
||||
die "Invalid choice... committing seppuku"
|
||||
fi
|
||||
fi
|
||||
# Check if input is a number
|
||||
[ "$choice" -eq "$choice" ] 2>/dev/null || die "Invalid number entered"
|
||||
|
||||
insert_history "$name" "search"
|
||||
|
||||
printf "$c_reset"
|
||||
|
||||
# Select respective anime_id
|
||||
count=1
|
||||
while read -r anime_id; do
|
||||
@ -385,6 +411,12 @@ anime_selection() {
|
||||
$search_results
|
||||
EOF
|
||||
|
||||
[ -z "$name" ] && name="$anime_id"
|
||||
log "NAME: $name"
|
||||
insert_history "$name" "search"
|
||||
|
||||
printf "$c_reset"
|
||||
|
||||
[ -z "$selection_id" ] && die "Invalid number entered"
|
||||
|
||||
read -r last_ep_number <<-EOF
|
||||
@ -397,6 +429,8 @@ anime_selection() {
|
||||
##################
|
||||
|
||||
episode_selection() {
|
||||
ep_choice_start="1"
|
||||
if [ "$is_rofi" -eq 1 ]; then
|
||||
# select episode number for anime
|
||||
log "Anime ID: $anime_id"
|
||||
stmt="SELECT DISTINCT episode_number \
|
||||
@ -429,6 +463,14 @@ episode_selection() {
|
||||
ep_choice_start=$(printf '%s\n' "${choice}" | awk '{print $1}')
|
||||
ep_choice_end=$(printf '%s\n' "${choice}" | awk '{print $NF}')
|
||||
log "START: $ep_choice_start | END: $ep_choice_end"
|
||||
elif [ $last_ep_number -gt 1 ]; then
|
||||
[ $is_download -eq 1 ] &&
|
||||
printf "Range of episodes can be specified: start_number end_number\n"
|
||||
|
||||
printf "${c_blue}Choose episode $c_cyan[1-%d]$c_reset:$c_green " $last_ep_number
|
||||
read ep_choice_start ep_choice_end
|
||||
printf "$c_reset"
|
||||
fi
|
||||
if [[ -z "$ep_choice_start" ]] && [[ -z "$ep_choice_end" ]]; then
|
||||
die "No episode range entered"
|
||||
fi
|
||||
@ -513,6 +555,7 @@ trap "printf '$c_reset'" INT HUP
|
||||
dep_ch "$player_fn" "curl" "sed" "grep" "sqlite3" "rofi"
|
||||
|
||||
# option parsing
|
||||
is_rofi=1
|
||||
is_download=0
|
||||
scrape=query
|
||||
download_dir="."
|
||||
@ -520,7 +563,7 @@ is_playlist=0
|
||||
playlist_remove=0
|
||||
playlist_add=0
|
||||
quality=best
|
||||
while getopts 'hd:Hpa:P:svq:' OPT; do
|
||||
while getopts 'hd:Hpa:P:svq:c' OPT; do
|
||||
case "$OPT" in
|
||||
h)
|
||||
help_text
|
||||
@ -562,6 +605,9 @@ while getopts 'hd:Hpa:P:svq:' OPT; do
|
||||
quality="$OPTARG"
|
||||
log "passed in quality: $quality"
|
||||
;;
|
||||
c)
|
||||
is_rofi=0
|
||||
;;
|
||||
*)
|
||||
printf "%s\n" "Invalid option"
|
||||
exit 1
|
||||
|
34
aniwrapper
34
aniwrapper
@ -13,8 +13,10 @@ DEFAULT_PLAYLIST="$CFG_DIR/playlists/playlist.txt"
|
||||
CFG_FILE="meh.rasi"
|
||||
QUALITIES="1. best|2. worst"
|
||||
QUALITY="best"
|
||||
CHECK_QUALITY=0
|
||||
GET_QUALITY=0
|
||||
VERBOSE=0
|
||||
IS_ROFI=1
|
||||
IS_DOWNLOAD=0
|
||||
|
||||
quit="6. Quit"
|
||||
options="1. Stream|2. Download|3. Continue|4. Playlist|5. Sync History|$quit"
|
||||
@ -46,10 +48,10 @@ quit() {
|
||||
}
|
||||
|
||||
run() {
|
||||
if [[ "$CHECK_QUALITY" -eq 1 ]]; then
|
||||
if [[ "$GET_QUALITY" -eq 1 ]]; then
|
||||
get_quality
|
||||
else
|
||||
log "CHECK_QUALITY disabled... using default: $QUALITY"
|
||||
log "QUALITY flag not set... using default -> $QUALITY"
|
||||
fi
|
||||
if [[ "$VERBOSE" -eq 0 ]]; then
|
||||
"$CMD" -q "$QUALITY" "$*"
|
||||
@ -67,7 +69,7 @@ log() {
|
||||
########
|
||||
# Main #
|
||||
########
|
||||
while getopts 'vhq' OPT; do
|
||||
while getopts 'vhqcd' OPT; do
|
||||
case "$OPT" in
|
||||
h)
|
||||
help_text
|
||||
@ -76,8 +78,16 @@ while getopts 'vhq' OPT; do
|
||||
VERBOSE=1
|
||||
;;
|
||||
q)
|
||||
CHECK_QUALITY=1
|
||||
QUALITY=1
|
||||
log "Quality prompt enabled"
|
||||
;;
|
||||
c)
|
||||
IS_ROFI=0
|
||||
log "Command-line (ani-cli) mode set"
|
||||
;;
|
||||
d)
|
||||
IS_DOWNLOAD=1
|
||||
log "Download flag set..."
|
||||
;;
|
||||
*)
|
||||
log "Invalid option"
|
||||
@ -86,7 +96,19 @@ while getopts 'vhq' OPT; do
|
||||
esac
|
||||
done
|
||||
|
||||
[ "$VERBOSE" -eq 1 ] && printf "%s\n" "CONFIG DIR: $CFG_DIR"
|
||||
log "CONFIG DIR: $CFG_DIR"
|
||||
|
||||
# Check if command-line flag is set
|
||||
if [[ "$IS_ROFI" -eq 0 ]] && [[ "$IS_DOWNLOAD" -eq 0 ]]; then
|
||||
run -c
|
||||
exit $?
|
||||
elif [[ "$IS_ROFI" -eq 0 ]] && [[ "$IS_DOWNLOAD" -eq 1 ]]; then
|
||||
printf "%s" "Enter download dir: "
|
||||
read -r dl_dir
|
||||
log "Download dir: $dl_dir"
|
||||
run "-cd $dl_dir"
|
||||
exit $?
|
||||
fi
|
||||
|
||||
choice=$(echo "${options[@]}" | rofi -dmenu -sep '|' \
|
||||
-config "$CFG_DIR/$CFG_FILE" -l 6 -i -p "Aniwrapper")
|
||||
|
Loading…
Reference in New Issue
Block a user