2021-10-30 16:30:40 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2021-12-16 00:21:58 -08:00
|
|
|
set -Eeuo pipefail
|
2021-11-02 10:09:02 -07:00
|
|
|
|
2021-12-16 00:21:58 -08:00
|
|
|
#############
|
|
|
|
# Globals #
|
|
|
|
#############
|
|
|
|
[ -z "$XDG_CONFIG_HOME" ] && XDG_CONFIG_HOME="$HOME/.config"
|
|
|
|
CMD="/usr/bin/ani-cli"
|
2021-11-08 00:37:24 -08:00
|
|
|
DEFAULT_DOWNLOAD="$HOME/Videos/sauce"
|
|
|
|
CFG_DIR="$XDG_CONFIG_HOME/aniwrapper"
|
2021-11-12 17:22:22 -08:00
|
|
|
DEFAULT_PLAYLIST="$CFG_DIR/playlists/playlist.txt"
|
2021-11-02 15:18:23 -07:00
|
|
|
CFG_FILE="meh.rasi"
|
2021-12-16 00:21:58 -08:00
|
|
|
QUALITIES="1. best|2. worst"
|
|
|
|
QUALITY="best"
|
|
|
|
CHECK_QUALITY=0
|
2021-11-09 00:54:55 -08:00
|
|
|
VERBOSE=0
|
2021-11-01 00:23:51 -07:00
|
|
|
|
2021-11-11 14:13:11 -08:00
|
|
|
quit="6. Quit"
|
|
|
|
options="1. Stream|2. Download|3. Continue|4. Playlist|5. Sync History|$quit"
|
2021-10-30 16:30:40 -07:00
|
|
|
|
2021-11-11 14:13:11 -08:00
|
|
|
|
2021-12-16 00:21:58 -08:00
|
|
|
#############
|
|
|
|
# Functions #
|
|
|
|
#############
|
|
|
|
get_quality() {
|
|
|
|
selection=$(rofi -dmenu -config "$CFG_DIR/$CFG_FILE" \
|
|
|
|
-l 1 -p "Choose video quality:" -sep '|' <<< "$QUALITIES")
|
|
|
|
QUALITY=$(awk '{print $2}' <<< "$selection")
|
|
|
|
log "selected quality: $QUALITY"
|
|
|
|
if [[ "$QUALITY" == 'best' || "$QUALITY" == 'worst' ]]; then
|
|
|
|
log "QUALITY: $QUALITY"
|
|
|
|
else
|
|
|
|
seppuku "Something went wrong getting the quality: $QUALITY... exiting"
|
|
|
|
fi
|
|
|
|
}
|
2021-10-30 16:30:40 -07:00
|
|
|
|
2021-11-08 00:37:24 -08:00
|
|
|
seppuku() {
|
|
|
|
printf "%s\n" "$*"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
quit() {
|
|
|
|
printf "%s\n" 'Quitting...'
|
2021-10-30 16:30:40 -07:00
|
|
|
exit 0
|
2021-11-08 00:37:24 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
run() {
|
2021-12-16 00:21:58 -08:00
|
|
|
if [[ "$CHECK_QUALITY" -eq 1 ]]; then
|
|
|
|
get_quality
|
|
|
|
else
|
|
|
|
log "CHECK_QUALITY disabled... using default: $QUALITY"
|
|
|
|
fi
|
2021-11-11 15:17:55 -08:00
|
|
|
if [[ "$VERBOSE" -eq 0 ]]; then
|
2021-12-16 00:21:58 -08:00
|
|
|
"$CMD" -q "$QUALITY" "$*"
|
2021-11-11 15:17:55 -08:00
|
|
|
else
|
2021-12-16 00:21:58 -08:00
|
|
|
"$CMD" -q "$QUALITY" -v "$*"
|
2021-11-11 15:17:55 -08:00
|
|
|
fi
|
2021-11-08 00:37:24 -08:00
|
|
|
}
|
|
|
|
|
2021-11-08 17:41:46 -08:00
|
|
|
log() {
|
|
|
|
if [[ "$VERBOSE" -eq 1 ]]; then
|
|
|
|
printf "%s\n" "$*"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-12-16 00:21:58 -08:00
|
|
|
########
|
|
|
|
# Main #
|
|
|
|
########
|
|
|
|
while getopts 'vhq' OPT; do
|
|
|
|
case "$OPT" in
|
|
|
|
h)
|
|
|
|
help_text
|
|
|
|
;;
|
|
|
|
v)
|
|
|
|
VERBOSE=1
|
|
|
|
;;
|
|
|
|
q)
|
|
|
|
CHECK_QUALITY=1
|
|
|
|
log "Quality prompt enabled"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
log "Invalid option"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
[ "$VERBOSE" -eq 1 ] && printf "%s\n" "CONFIG DIR: $CFG_DIR"
|
|
|
|
|
|
|
|
choice=$(echo "${options[@]}" | rofi -dmenu -sep '|' \
|
|
|
|
-config "$CFG_DIR/$CFG_FILE" -l 6 -i -p "Aniwrapper")
|
|
|
|
|
2021-11-11 14:13:11 -08:00
|
|
|
[ "$choice" == "$quit" ] && quit
|
2021-10-30 16:30:40 -07:00
|
|
|
|
|
|
|
selection=$(printf "%s\n" "$choice" | awk '{ print $1 }')
|
|
|
|
|
2021-11-11 14:13:11 -08:00
|
|
|
case "$selection" in
|
2021-11-22 12:42:07 -08:00
|
|
|
1.)
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# streaming
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
log "Streaming mode"
|
|
|
|
run
|
|
|
|
;;
|
|
|
|
2.)
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# download
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
log "Download anime"
|
|
|
|
dl_dir=$(rofi -dmenu -config "$CFG_DIR/$CFG_FILE" \
|
|
|
|
-l 1 -p "Enter download dir:")
|
|
|
|
# if dl_dir is none set to current directory
|
|
|
|
[ "$dl_dir" == "" ] && dl_dir="$DEFAULT_DOWNLOAD"
|
|
|
|
run -d "$dl_dir"
|
|
|
|
;;
|
|
|
|
3.)
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# continue
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
log "Continue watching"
|
|
|
|
run -H
|
|
|
|
;;
|
|
|
|
4.)
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# playlist mode
|
|
|
|
# ---------------------------------------------------------------------------
|
2021-11-08 17:41:46 -08:00
|
|
|
log "Playlist mode"
|
2021-11-22 12:42:07 -08:00
|
|
|
options="1. Play playlist|2. Add to playlist|3. Delete from playlist|4. Quit"
|
2021-11-08 00:37:24 -08:00
|
|
|
choice=$(printf "%s\n" "${options[@]}" |
|
|
|
|
rofi -dmenu -sep '|' \
|
|
|
|
-config "$CFG_DIR/$CFG_FILE" -l 4 -i -p "Enter choice:")
|
2021-11-08 00:55:36 -08:00
|
|
|
[ -z "$choice" ] && seppuku "No choice selected"
|
2021-11-11 14:13:11 -08:00
|
|
|
[ "$choice" == "$quit" ] && quit
|
2021-11-04 19:45:17 -07:00
|
|
|
selection=$(printf "%s\n" "$choice" | awk '{ print $1 }')
|
|
|
|
if [[ "$selection" == "1." ]]; then
|
2021-11-22 12:42:07 -08:00
|
|
|
# ------------------------------------------------------------------
|
|
|
|
# watch playlist
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
log "Playlist mode"
|
|
|
|
options="1. From file|2. Streaming|3. Quit"
|
|
|
|
choice=$(printf "%s\n" "${options[@]}" |
|
|
|
|
rofi -dmenu -sep '|' \
|
|
|
|
-config "$CFG_DIR/$CFG_FILE" -l 4 -i -p "Enter choice:")
|
2021-11-08 00:55:36 -08:00
|
|
|
[ -z "$choice" ] && seppuku "No choice selected"
|
2021-11-22 12:42:07 -08:00
|
|
|
[ "$choice" == "$quit" ] && quit
|
|
|
|
log "Selection: $choice"
|
|
|
|
selection=$(printf "%s\n" "$choice" | awk '{ print $1 }')
|
|
|
|
if [[ "$selection" == "1." ]]; then
|
|
|
|
# --------------------------------------------------------------
|
|
|
|
# watch playlist from file (downloaded videos)
|
|
|
|
# --------------------------------------------------------------
|
|
|
|
log "Watching playlist from file"
|
|
|
|
PLAYLIST_DIR="$HOME/Videos/sauce"
|
|
|
|
log "Default playlist directory: $PLAYLIST_DIR"
|
|
|
|
choice=$(cd "$PLAYLIST_DIR" && find . -mindepth 1 -type d |
|
|
|
|
cut -c 3- |
|
|
|
|
rofi -dmenu \
|
|
|
|
-config "$CFG_DIR/$CFG_FILE" -l 5 -i -p "Choose playlist:")
|
|
|
|
[ -z "$choice" ] && seppuku "No choice selected"
|
|
|
|
log "Choice" "$choice"
|
|
|
|
run -P "$PLAYLIST_DIR/$choice"
|
|
|
|
elif [[ "$selection" == "2." ]]; then
|
|
|
|
# --------------------------------------------------------------
|
|
|
|
# watch playlist of 'queued' videos to stream
|
|
|
|
# --------------------------------------------------------------
|
|
|
|
log "Watching from 'queue'"
|
|
|
|
choice=$(rofi -dmenu \
|
|
|
|
-config "$CFG_DIR/$CFG_FILE" \
|
|
|
|
-l 1 -p "Enter path to playlist file (or leave blank for default):")
|
|
|
|
if [[ "$choice" ]]; then
|
|
|
|
PLAYLIST_FILE="$choice"
|
|
|
|
else
|
|
|
|
PLAYLIST_FILE="$DEFAULT_PLAYLIST"
|
|
|
|
fi
|
|
|
|
run -p
|
|
|
|
fi
|
2021-11-04 19:45:17 -07:00
|
|
|
elif [[ "$selection" == "2." ]]; then
|
2021-11-22 12:42:07 -08:00
|
|
|
# ------------------------------------------------------------------
|
|
|
|
# add to playlist
|
|
|
|
# ------------------------------------------------------------------
|
|
|
|
log "Add to playlist"
|
2021-11-12 17:22:22 -08:00
|
|
|
choice=$(rofi -dmenu \
|
|
|
|
-config "$CFG_DIR/$CFG_FILE" \
|
|
|
|
-l 1 -p "Enter path to playlist file (or leave blank for default):")
|
|
|
|
if [[ "$choice" ]]; then
|
|
|
|
PLAYLIST_FILE="$choice"
|
|
|
|
else
|
|
|
|
PLAYLIST_FILE="$DEFAULT_PLAYLIST"
|
|
|
|
fi
|
2021-11-22 12:42:07 -08:00
|
|
|
run -a "$PLAYLIST_FILE"
|
|
|
|
elif [[ "$selection" == "3." ]]; then
|
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
# delete from playlist
|
|
|
|
# -----------------------------------------------------------------------
|
|
|
|
log "Delete from playlist"
|
|
|
|
choice=$(rofi -dmenu \
|
|
|
|
-config "$CFG_DIR/$CFG_FILE" \
|
|
|
|
-l 1 -p "Enter path to playlist file (or leave blank for default):")
|
|
|
|
if [[ "$choice" ]]; then
|
|
|
|
PLAYLIST_FILE="$choice"
|
2021-11-12 17:22:22 -08:00
|
|
|
else
|
2021-11-22 12:42:07 -08:00
|
|
|
PLAYLIST_FILE="$DEFAULT_PLAYLIST"
|
|
|
|
fi
|
|
|
|
[ "$VERBOSE" -eq 1 ] && log "playlist file: $PLAYLIST_FILE"
|
|
|
|
lines=""
|
|
|
|
cnt=0
|
|
|
|
while read -r line; do
|
|
|
|
if [[ "$cnt" -eq 0 ]]; then
|
|
|
|
lines="$((cnt + 1)). $line"
|
|
|
|
else
|
|
|
|
lines="$lines|$((cnt + 1)). $line"
|
|
|
|
fi
|
|
|
|
((cnt++))
|
|
|
|
done <"$PLAYLIST_FILE"
|
|
|
|
choice=$(rofi -dmenu -l 12 \
|
|
|
|
-sep '|' \
|
|
|
|
-config "$CFG_DIR/$CFG_FILE" -p "Choose episode to delete:" \
|
|
|
|
<<<"${lines[*]}")
|
|
|
|
log "choice: $choice"
|
|
|
|
selection=$(awk '{print $1}' <<<"$choice")
|
|
|
|
idx=${selection//\./}
|
|
|
|
log "index selected: $idx"
|
|
|
|
log "deleting entry: $idx"
|
|
|
|
if [[ -z "$idx" ]]; then
|
|
|
|
log "no entry selected"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
sed -ie "$idx"d "$PLAYLIST_FILE"
|
|
|
|
if [ "$?" -eq 0 ]; then
|
|
|
|
log "$selection deleted from playlist"
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
log "there was a problem deleting $choice"
|
|
|
|
exit 1
|
2021-11-12 17:22:22 -08:00
|
|
|
fi
|
2021-11-22 12:42:07 -08:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
5.)
|
|
|
|
log "Sync history database"
|
|
|
|
username=$(rofi -dmenu -config "$CFG_DIR/$CFG_FILE" \
|
|
|
|
-l 1 -p "Enter the username of the remote user:")
|
|
|
|
if [[ -z "$username" ]] || [[ "$username" == "" ]]; then
|
|
|
|
log "No username provided... exiting"
|
2021-11-11 14:13:11 -08:00
|
|
|
exit 1
|
2021-11-18 15:55:41 -08:00
|
|
|
fi
|
2021-11-22 12:42:07 -08:00
|
|
|
host=$(rofi -dmenu -config "$CFG_DIR/$CFG_FILE" \
|
|
|
|
-l 1 -p "Enter the host for the remote machine (eg 192.168.1.99):")
|
|
|
|
if [[ -z "$host" ]] || [[ "$host" == "" ]]; then
|
|
|
|
log "No host provided... exiting"
|
2021-11-18 15:55:41 -08:00
|
|
|
exit 1
|
2021-11-11 14:13:11 -08:00
|
|
|
fi
|
2021-11-22 12:42:07 -08:00
|
|
|
port=$(rofi -dmenu -config "$CFG_DIR/$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_DIR/$CFG_FILE" \
|
|
|
|
-l 1 -p "Enter path to private key (leave blank if not needed or if unsure):")
|
2021-11-20 13:07:47 -08:00
|
|
|
|
2021-11-22 12:42:07 -08:00
|
|
|
if [[ -z "$keypath" ]]; then
|
|
|
|
printf "%s\n%s\n%d\n%s\n" "$username" "$host" "$port" "" | run -s
|
|
|
|
# printf "%s\n%s\n%d\n%s\n" "$username" "$host" "$port" "" | ani-cli -s
|
|
|
|
else
|
|
|
|
# printf "%s\n%s\n%d\n%s\n" "$username" "$host" "$port" "$keypath" | ani-cli -s
|
|
|
|
printf "%s\n%s\n%d\n%s\n" "$username" "$host" "$port" "$keypath" | run -s
|
|
|
|
fi
|
2021-11-20 13:07:47 -08:00
|
|
|
|
2021-11-22 12:42:07 -08:00
|
|
|
if [[ "$?" -ne 0 ]]; then
|
|
|
|
log "Aniwrapper was unable to sync the databases..."
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
log "Databases synced successfully"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
6.)
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# get out
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
printf "%s\n" "Quitting..."
|
2021-11-18 15:55:41 -08:00
|
|
|
exit 0
|
2021-11-22 12:42:07 -08:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
log "Invalid choice..."
|
|
|
|
exit 1
|
|
|
|
;;
|
2021-11-11 14:13:11 -08:00
|
|
|
|
|
|
|
esac
|