fix continue and add delete from playlist

made it so playlist file is specified directly in ani-cli instead of
going with the default
This commit is contained in:
ksyasuda 2021-11-12 17:22:22 -08:00
parent 1c5ff3bc78
commit ff703721f6
3 changed files with 88 additions and 27 deletions

31
ani-cli
View File

@ -498,8 +498,7 @@ download_dir="."
is_playlist=0 is_playlist=0
playlist_remove=0 playlist_remove=0
playlist_add=0 playlist_add=0
playlist_file="$CFG_DIR/playlists/playlist.txt" while getopts 'hd:Hlpa:P:sv' OPT; do
while getopts 'hd:HlpadP:sv' OPT; do
case "$OPT" in case "$OPT" in
h) h)
help_text help_text
@ -526,10 +525,7 @@ while getopts 'hd:HlpadP:sv' OPT; do
a) a)
is_add=1 is_add=1
scrape=add scrape=add
;; playlist_file="${OPTARG/ //}"
d)
is_delete=1
scrape=delete
;; ;;
P) P)
is_playlist=1 is_playlist=1
@ -580,16 +576,21 @@ case $scrape in
episode_selection episode_selection
;; ;;
history) history)
# search_results=$(sed -n -E 's/\t[0-9]*//p' "$logfile")
stmt="SELECT DISTINCT anime_name FROM watch_history ORDER BY watch_date DESC" stmt="SELECT DISTINCT anime_name FROM watch_history ORDER BY watch_date DESC"
search_results=$(printf "%s\n" "$stmt" | sqlite3 -noheader "$HISTORY_DB") search_results=$(printf "%s\n" "$stmt" | sqlite3 -noheader "$HISTORY_DB")
[ -z "$search_results" ] && die "History is empty" [ -z "$search_results" ] && die "History is empty"
anime_selection "${search_results[@]}" anime_selection "${search_results[@]}"
[ $? -ne 0 ] && die "No anime selection found" [ $? -ne 0 ] && die "No anime selection found"
stmt="SELECT episode_number FROM watch_history ORDER BY watch_date DESC LIMIT 1" [ "$VERBOSE" -eq 1 ] && printf "%s\n" "SELECTION: $selection_id"
run_stmt "$stmt"
ep_choice_start=$? stmt="SELECT episode_number \
echo "EPISODE: $ep_choice_start" FROM watch_history \
WHERE anime_name = '$selection_id' \
ORDER BY watch_date DESC \
LIMIT 1"
ep_choice_start=$(run_stmt "$stmt")
[ "$VERBOSE" -eq 1 ] && printf "%s\n" "Most recently watched episode: $ep_choice_start"
# search_results=$(sed -n -E 's/\t[0-9]*//p' "$logfile")
# ep_choice_start=$(sed -n -E "s/${selection_id}\t//p" "$logfile") # ep_choice_start=$(sed -n -E "s/${selection_id}\t//p" "$logfile")
;; ;;
playlist) playlist)
@ -626,7 +627,6 @@ case $scrape in
[ $? -ne 0 ] && die "No anime selection found" [ $? -ne 0 ] && die "No anime selection found"
episode_selection episode_selection
;; ;;
delete) ;;
sync) sync)
printf "%s" "Enter username for remote user: " printf "%s" "Enter username for remote user: "
read -r username read -r username
@ -687,7 +687,6 @@ for ep in $episodes; do
fi fi
printf "%s\n" "$selection_id $ep" >>"$playlist_file" printf "%s\n" "$selection_id $ep" >>"$playlist_file"
[ "$VERBOSE" -eq 1 ] && printf "%s\n" "Added to playlist file" [ "$VERBOSE" -eq 1 ] && printf "%s\n" "Added to playlist file"
exit 0
else else
open_episode "$selection_id" "$ep" "$download_dir" open_episode "$selection_id" "$ep" "$download_dir"
if [[ "$is_playlist" -eq 1 ]]; then if [[ "$is_playlist" -eq 1 ]]; then
@ -695,6 +694,12 @@ for ep in $episodes; do
fi fi
fi fi
done done
if [[ "$is_add" -eq 1 ]]; then
printf "%s\n" "Finished adding to playlist file... exiting"
exit 0
fi
episode=${ep_choice_end:-$ep_choice_start} episode=${ep_choice_end:-$ep_choice_start}
choice='' choice=''

View File

@ -4,8 +4,8 @@
CMD=/usr/local/bin/ani-cli CMD=/usr/local/bin/ani-cli
DEFAULT_DOWNLOAD="$HOME/Videos/sauce" DEFAULT_DOWNLOAD="$HOME/Videos/sauce"
DEFAULT_PLAYLIST="$HOME/Videos/sauce/playlists/playlist.txt"
CFG_DIR="$XDG_CONFIG_HOME/aniwrapper" CFG_DIR="$XDG_CONFIG_HOME/aniwrapper"
DEFAULT_PLAYLIST="$CFG_DIR/playlists/playlist.txt"
CFG_FILE="meh.rasi" CFG_FILE="meh.rasi"
VERBOSE=0 VERBOSE=0
@ -100,9 +100,9 @@ case "$selection" in
[ "$choice" == "$quit" ] && quit [ "$choice" == "$quit" ] && quit
selection=$(printf "%s\n" "$choice" | awk '{ print $1 }') selection=$(printf "%s\n" "$choice" | awk '{ print $1 }')
if [[ "$selection" == "1." ]]; then if [[ "$selection" == "1." ]]; then
# ----------------------------------------------------------------------- # ------------------------------------------------------------------
# watch playlist # watch playlist
# ----------------------------------------------------------------------- # ------------------------------------------------------------------
log "Playlist mode" log "Playlist mode"
options="1. From file|2. Streaming|3. Quit" options="1. From file|2. Streaming|3. Quit"
choice=$(printf "%s\n" "${options[@]}" | choice=$(printf "%s\n" "${options[@]}" |
@ -113,9 +113,9 @@ case "$selection" in
log "Selection: $choice" log "Selection: $choice"
selection=$(printf "%s\n" "$choice" | awk '{ print $1 }') selection=$(printf "%s\n" "$choice" | awk '{ print $1 }')
if [[ "$selection" == "1." ]]; then if [[ "$selection" == "1." ]]; then
# ------------------------------------------------------------------- # --------------------------------------------------------------
# watch playlist from file (downloaded videos) # watch playlist from file (downloaded videos)
# ------------------------------------------------------------------- # --------------------------------------------------------------
log "Watching playlist from file" log "Watching playlist from file"
PLAYLIST_DIR="$HOME/Videos/sauce" PLAYLIST_DIR="$HOME/Videos/sauce"
log "Default playlist directory: $PLAYLIST_DIR" log "Default playlist directory: $PLAYLIST_DIR"
@ -127,24 +127,80 @@ case "$selection" in
log "Choice" "$choice" log "Choice" "$choice"
run -P "$PLAYLIST_DIR/$choice" run -P "$PLAYLIST_DIR/$choice"
elif [[ "$selection" == "2." ]]; then elif [[ "$selection" == "2." ]]; then
# ------------------------------------------------------------------- # --------------------------------------------------------------
# watch playlist of 'queued' videos to stream # watch playlist of 'queued' videos to stream
# ------------------------------------------------------------------- # --------------------------------------------------------------
log "Watching from 'queue'" 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 run -p
fi fi
elif [[ "$selection" == "2." ]]; then elif [[ "$selection" == "2." ]]; then
# ----------------------------------------------------------------------- # ------------------------------------------------------------------
# add to playlist # add to playlist
# ----------------------------------------------------------------------- # ------------------------------------------------------------------
log "Add to playlist" log "Add to playlist"
run -a 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 -a "$PLAYLIST_FILE"
elif [[ "$selection" == "3." ]]; then elif [[ "$selection" == "3." ]]; then
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
# delete from playlist # delete from playlist
# ----------------------------------------------------------------------- # -----------------------------------------------------------------------
log "Not implemented yet" log "Delete from playlist"
run -r 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
[ "$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
fi
fi fi
;; ;;
5.) 5.)

4
db.sh
View File

@ -80,10 +80,10 @@ while getopts 'cdrqCs' OPT; do
;; ;;
C) C)
log "Cleaning up database..." log "Cleaning up database..."
stmt="DELETE FROM search_history WHERE anime_name IS NULL or anime_name = ''" stmt="DELETE FROM search_history WHERE anime_name IS NULL OR anime_name = ''"
log "Cleaning up search history..." log "Cleaning up search history..."
sqlite3 "$DIR/$DB" <<<"$stmt" sqlite3 "$DIR/$DB" <<<"$stmt"
stmt="DELETE FROM watch_history WHERE anime_name IS NULL or anime_name = ''" stmt="DELETE FROM watch_history WHERE anime_name IS NULL OR anime_name = '' OR episode_number = 0"
log "Cleaning up watch history..." log "Cleaning up watch history..."
sqlite3 "$DIR/$DB" <<<"$stmt" sqlite3 "$DIR/$DB" <<<"$stmt"
;; ;;