mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-11-22 03:19:53 -08: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
218
ani-cli
218
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"
|
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>"
|
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[@]}" |
|
query=$(printf "%s\n" "${hist[@]}" |
|
||||||
rofi -dmenu -l 12 -p "Search Anime:" \
|
rofi -dmenu -l 12 -p "Search Anime:" \
|
||||||
-mesg "$span" \
|
-mesg "$span" \
|
||||||
@ -302,6 +302,9 @@ get_search_query() {
|
|||||||
# works with trailing '-' so remove for now
|
# works with trailing '-' so remove for now
|
||||||
# query="${query// /}"
|
# query="${query// /}"
|
||||||
log "Query: $query"
|
log "Query: $query"
|
||||||
|
elif [ "$is_rofi" -eq 0 ]; then
|
||||||
|
printf "Search Anime: "
|
||||||
|
read -r query
|
||||||
else
|
else
|
||||||
query=$*
|
query=$*
|
||||||
fi
|
fi
|
||||||
@ -317,61 +320,84 @@ get_search_query() {
|
|||||||
anime_selection() {
|
anime_selection() {
|
||||||
# Select anime from query results
|
# Select anime from query results
|
||||||
search_results=$*
|
search_results=$*
|
||||||
|
if [ "$is_rofi" -eq 1 ]; then
|
||||||
|
count=1
|
||||||
|
menu=()
|
||||||
|
res=()
|
||||||
|
while read -r anime_id; do
|
||||||
|
menu+="$count. $anime_id\n"
|
||||||
|
idx=$((count - 1))
|
||||||
|
res["$idx"]="$anime_id"
|
||||||
|
count=$((count + 1))
|
||||||
|
done <<-EOF
|
||||||
|
$search_results
|
||||||
|
EOF
|
||||||
|
|
||||||
|
searched=""
|
||||||
|
cnt=0
|
||||||
|
# Get the comma separated list of indexes of anime that has been searched before
|
||||||
|
for anime in "${res[@]}"; do
|
||||||
|
log "ANIME: $anime"
|
||||||
|
check_db "$anime" "search"
|
||||||
|
if [[ $? -gt 0 ]]; then
|
||||||
|
log "SEARCHED BEFORE"
|
||||||
|
if [[ "$searched" == "" ]]; then
|
||||||
|
searched="$((cnt++))"
|
||||||
|
else
|
||||||
|
searched="$searched, $((cnt++))"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
log "SEARCHED: $searched"
|
||||||
|
|
||||||
|
# get the anime from indexed list
|
||||||
|
user_input=$(printf "${menu[@]}" |
|
||||||
|
rofi -dmenu -config "$CFG_DIR/${ROFI_CFG}" \
|
||||||
|
-a "$searched" \
|
||||||
|
-l 12 -i -p "Enter number:")
|
||||||
|
[ -z "$user_input" ] && return 1
|
||||||
|
|
||||||
|
choice=$(printf '%s\n' "$user_input" | awk '{print $1}')
|
||||||
|
# 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"
|
||||||
|
|
||||||
count=1
|
count=1
|
||||||
menu=()
|
while read anime_id; do
|
||||||
res=()
|
# alternating colors for menu
|
||||||
while read -r anime_id; do
|
[ $((count % 2)) -eq 0 ] &&
|
||||||
menu+="$count. $anime_id\n"
|
menu_format_string=$menu_format_string_c1 ||
|
||||||
idx=$((count - 1))
|
menu_format_string=$menu_format_string_c2
|
||||||
res["$idx"]="$anime_id"
|
|
||||||
count=$((count + 1))
|
printf "$menu_format_string" "$count" "$anime_id"
|
||||||
|
count=$((count+1))
|
||||||
done <<-EOF
|
done <<-EOF
|
||||||
$search_results
|
$search_results
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
searched=""
|
# User input
|
||||||
cnt=0
|
printf "$c_blue%s$c_green" "Enter number: "
|
||||||
# Get the comma separated list of indexes of anime that has been searched before
|
read choice
|
||||||
for anime in "${res[@]}"; do
|
|
||||||
log "ANIME: $anime"
|
|
||||||
check_db "$anime" "search"
|
|
||||||
if [[ $? -gt 0 ]]; then
|
|
||||||
log "SEARCHED BEFORE"
|
|
||||||
if [[ "$searched" == "" ]]; then
|
|
||||||
searched="$((cnt++))"
|
|
||||||
else
|
|
||||||
searched="$searched, $((cnt++))"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
log "SEARCHED: $searched"
|
|
||||||
|
|
||||||
# get the anime from indexed list
|
|
||||||
user_input=$(printf "${menu[@]}" |
|
|
||||||
rofi -dmenu -config "$CFG_DIR/${ROFI_CFG}" \
|
|
||||||
-a "$searched" \
|
|
||||||
-l 12 -i -p "Enter number:")
|
|
||||||
[ -z "$user_input" ] && return 1
|
|
||||||
|
|
||||||
choice=$(printf '%s\n' "$user_input" | awk '{print $1}')
|
|
||||||
# Remove period after number
|
|
||||||
choice="${choice::-1}"
|
|
||||||
name=$(printf '%s\n' "$user_input" | awk '{print $NF}')
|
|
||||||
|
|
||||||
log "CHOICE: $name"
|
|
||||||
log "NAME: $name"
|
|
||||||
|
|
||||||
# check both choice and name are set
|
|
||||||
if [[ ! "$choice" ]] || [[ ! "$name" ]]; then
|
|
||||||
die "Invalid choice... committing seppuku"
|
|
||||||
fi
|
|
||||||
# Check if input is a number
|
|
||||||
[ "$choice" -eq "$choice" ] 2>/dev/null || die "Invalid number entered"
|
|
||||||
|
|
||||||
insert_history "$name" "search"
|
|
||||||
|
|
||||||
printf "$c_reset"
|
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"
|
||||||
|
|
||||||
# Select respective anime_id
|
# Select respective anime_id
|
||||||
count=1
|
count=1
|
||||||
@ -385,6 +411,12 @@ anime_selection() {
|
|||||||
$search_results
|
$search_results
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
[ -z "$name" ] && name="$anime_id"
|
||||||
|
log "NAME: $name"
|
||||||
|
insert_history "$name" "search"
|
||||||
|
|
||||||
|
printf "$c_reset"
|
||||||
|
|
||||||
[ -z "$selection_id" ] && die "Invalid number entered"
|
[ -z "$selection_id" ] && die "Invalid number entered"
|
||||||
|
|
||||||
read -r last_ep_number <<-EOF
|
read -r last_ep_number <<-EOF
|
||||||
@ -397,38 +429,48 @@ anime_selection() {
|
|||||||
##################
|
##################
|
||||||
|
|
||||||
episode_selection() {
|
episode_selection() {
|
||||||
# select episode number for anime
|
ep_choice_start="1"
|
||||||
log "Anime ID: $anime_id"
|
if [ "$is_rofi" -eq 1 ]; then
|
||||||
stmt="SELECT DISTINCT episode_number \
|
# select episode number for anime
|
||||||
FROM watch_history \
|
log "Anime ID: $anime_id"
|
||||||
WHERE anime_name = '$anime_id';"
|
stmt="SELECT DISTINCT episode_number \
|
||||||
hist=$(run_stmt "$stmt")
|
FROM watch_history \
|
||||||
log "HISTORY: ${hist[*]}"
|
WHERE anime_name = '$anime_id';"
|
||||||
|
hist=$(run_stmt "$stmt")
|
||||||
|
log "HISTORY: ${hist[*]}"
|
||||||
|
|
||||||
# Get Watch History for $anime_id as comma separated list
|
# Get Watch History for $anime_id as comma separated list
|
||||||
watch_history=""
|
watch_history=""
|
||||||
for i in $hist; do
|
for i in $hist; do
|
||||||
if [[ "$watch_history" == "" ]]; then
|
if [[ "$watch_history" == "" ]]; then
|
||||||
watch_history="$((--i))"
|
watch_history="$((--i))"
|
||||||
else
|
else
|
||||||
watch_history="$watch_history, $((--i))"
|
watch_history="$watch_history, $((--i))"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
log "WATCH HISTORY: %s\n" "$watch_history"
|
log "WATCH HISTORY: %s\n" "$watch_history"
|
||||||
# get user choice and set the start and end
|
# get user choice and set the start and end
|
||||||
msg='<span foreground="peachpuff" style="italic" size="small" weight="light">Range of episodes can be provided as: START_EPISODE - END_EPISODE</span>'
|
msg='<span foreground="peachpuff" style="italic" size="small" weight="light">Range of episodes can be provided as: START_EPISODE - END_EPISODE</span>'
|
||||||
choice=$(
|
choice=$(
|
||||||
seq 1 "$last_ep_number" |
|
seq 1 "$last_ep_number" |
|
||||||
rofi -dmenu -l 12 \
|
rofi -dmenu -l 12 \
|
||||||
-a "$watch_history" \
|
-a "$watch_history" \
|
||||||
-p "Select Episode [1, $last_ep_number]:" \
|
-p "Select Episode [1, $last_ep_number]:" \
|
||||||
-mesg "$msg" \
|
-mesg "$msg" \
|
||||||
-config "$CFG_DIR/${ROFI_CFG}"
|
-config "$CFG_DIR/${ROFI_CFG}"
|
||||||
)
|
)
|
||||||
ep_choice_start=$(printf '%s\n' "${choice}" | awk '{print $1}')
|
ep_choice_start=$(printf '%s\n' "${choice}" | awk '{print $1}')
|
||||||
ep_choice_end=$(printf '%s\n' "${choice}" | awk '{print $NF}')
|
ep_choice_end=$(printf '%s\n' "${choice}" | awk '{print $NF}')
|
||||||
log "START: $ep_choice_start | END: $ep_choice_end"
|
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
|
if [[ -z "$ep_choice_start" ]] && [[ -z "$ep_choice_end" ]]; then
|
||||||
die "No episode range entered"
|
die "No episode range entered"
|
||||||
fi
|
fi
|
||||||
@ -513,6 +555,7 @@ trap "printf '$c_reset'" INT HUP
|
|||||||
dep_ch "$player_fn" "curl" "sed" "grep" "sqlite3" "rofi"
|
dep_ch "$player_fn" "curl" "sed" "grep" "sqlite3" "rofi"
|
||||||
|
|
||||||
# option parsing
|
# option parsing
|
||||||
|
is_rofi=1
|
||||||
is_download=0
|
is_download=0
|
||||||
scrape=query
|
scrape=query
|
||||||
download_dir="."
|
download_dir="."
|
||||||
@ -520,7 +563,7 @@ is_playlist=0
|
|||||||
playlist_remove=0
|
playlist_remove=0
|
||||||
playlist_add=0
|
playlist_add=0
|
||||||
quality=best
|
quality=best
|
||||||
while getopts 'hd:Hpa:P:svq:' OPT; do
|
while getopts 'hd:Hpa:P:svq:c' OPT; do
|
||||||
case "$OPT" in
|
case "$OPT" in
|
||||||
h)
|
h)
|
||||||
help_text
|
help_text
|
||||||
@ -558,10 +601,13 @@ while getopts 'hd:Hpa:P:svq:' OPT; do
|
|||||||
v)
|
v)
|
||||||
VERBOSE=1
|
VERBOSE=1
|
||||||
;;
|
;;
|
||||||
q)
|
q)
|
||||||
quality="$OPTARG"
|
quality="$OPTARG"
|
||||||
log "passed in quality: $quality"
|
log "passed in quality: $quality"
|
||||||
;;
|
;;
|
||||||
|
c)
|
||||||
|
is_rofi=0
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
printf "%s\n" "Invalid option"
|
printf "%s\n" "Invalid option"
|
||||||
exit 1
|
exit 1
|
||||||
|
34
aniwrapper
34
aniwrapper
@ -13,8 +13,10 @@ DEFAULT_PLAYLIST="$CFG_DIR/playlists/playlist.txt"
|
|||||||
CFG_FILE="meh.rasi"
|
CFG_FILE="meh.rasi"
|
||||||
QUALITIES="1. best|2. worst"
|
QUALITIES="1. best|2. worst"
|
||||||
QUALITY="best"
|
QUALITY="best"
|
||||||
CHECK_QUALITY=0
|
GET_QUALITY=0
|
||||||
VERBOSE=0
|
VERBOSE=0
|
||||||
|
IS_ROFI=1
|
||||||
|
IS_DOWNLOAD=0
|
||||||
|
|
||||||
quit="6. Quit"
|
quit="6. Quit"
|
||||||
options="1. Stream|2. Download|3. Continue|4. Playlist|5. Sync History|$quit"
|
options="1. Stream|2. Download|3. Continue|4. Playlist|5. Sync History|$quit"
|
||||||
@ -46,10 +48,10 @@ quit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
run() {
|
run() {
|
||||||
if [[ "$CHECK_QUALITY" -eq 1 ]]; then
|
if [[ "$GET_QUALITY" -eq 1 ]]; then
|
||||||
get_quality
|
get_quality
|
||||||
else
|
else
|
||||||
log "CHECK_QUALITY disabled... using default: $QUALITY"
|
log "QUALITY flag not set... using default -> $QUALITY"
|
||||||
fi
|
fi
|
||||||
if [[ "$VERBOSE" -eq 0 ]]; then
|
if [[ "$VERBOSE" -eq 0 ]]; then
|
||||||
"$CMD" -q "$QUALITY" "$*"
|
"$CMD" -q "$QUALITY" "$*"
|
||||||
@ -67,7 +69,7 @@ log() {
|
|||||||
########
|
########
|
||||||
# Main #
|
# Main #
|
||||||
########
|
########
|
||||||
while getopts 'vhq' OPT; do
|
while getopts 'vhqcd' OPT; do
|
||||||
case "$OPT" in
|
case "$OPT" in
|
||||||
h)
|
h)
|
||||||
help_text
|
help_text
|
||||||
@ -76,8 +78,16 @@ while getopts 'vhq' OPT; do
|
|||||||
VERBOSE=1
|
VERBOSE=1
|
||||||
;;
|
;;
|
||||||
q)
|
q)
|
||||||
CHECK_QUALITY=1
|
QUALITY=1
|
||||||
log "Quality prompt enabled"
|
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"
|
log "Invalid option"
|
||||||
@ -86,7 +96,19 @@ while getopts 'vhq' OPT; do
|
|||||||
esac
|
esac
|
||||||
done
|
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 '|' \
|
choice=$(echo "${options[@]}" | rofi -dmenu -sep '|' \
|
||||||
-config "$CFG_DIR/$CFG_FILE" -l 6 -i -p "Aniwrapper")
|
-config "$CFG_DIR/$CFG_FILE" -l 6 -i -p "Aniwrapper")
|
||||||
|
Loading…
Reference in New Issue
Block a user