add basic playlist functionality for 'queuing'

This commit is contained in:
ksyasuda 2021-11-04 18:37:16 -07:00
parent 40202b7c65
commit a5033db481
3 changed files with 166 additions and 51 deletions

130
ani-cli
View File

@ -6,7 +6,7 @@ if [[ -z "$XDG_CONFIG_HOME" ]]; then
fi fi
CFG_DIR="$XDG_CONFIG_HOME/ani-cli" CFG_DIR="$XDG_CONFIG_HOME/ani-cli"
CFG_FILE="meh.rasi" ROFI_CFG="meh.rasi"
HISTORY_DB="$XDG_CONFIG_HOME/ani-cli/history.sqlite3" HISTORY_DB="$XDG_CONFIG_HOME/ani-cli/history.sqlite3"
@ -194,16 +194,21 @@ get_search_query() {
# Query the anime to stream/download # Query the anime to stream/download
# Get search history # Get search history
stmt="SELECT DISTINCT anime_name \ # Construct string "<id>. <anime_name>"
stmt="SELECT DISTINCT id || '. ' || anime_name \
FROM search_history \ FROM search_history \
ORDER BY search_date DESC;" ORDER BY search_date DESC;"
# hist=$(echo "$stmt" | sqlite3 -noheader "$HISTORY_DB") # hist=$(echo "$stmt" | sqlite3 -noheader "$HISTORY_DB")
hist=$(run_stmt "$stmt") hist=$(run_stmt "$stmt")
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 "$*" ]; 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:" \
-config "$CFG_DIR/${CFG_FILE}") -mesg "$span" \
-config "$CFG_DIR/${ROFI_CFG}" | awk '{print $NF}')
[ "$VERBOSE" -eq 1 ] && printf "%s\n" "Query: $query"
# printf "Search Anime: " # printf "Search Anime: "
# read -r query # read -r query
else else
@ -235,7 +240,7 @@ anime_selection() {
menu_format_string=$menu_format_string_c2 menu_format_string=$menu_format_string_c2
# printf "$menu_format_string" "$count" "$anime_id" # printf "$menu_format_string" "$count" "$anime_id"
menu+="$count - $anime_id\n" menu+="$count. $anime_id\n"
idx=$((count - 1)) idx=$((count - 1))
res["$idx"]="$anime_id" res["$idx"]="$anime_id"
count=$((count + 1)) count=$((count + 1))
@ -263,25 +268,32 @@ anime_selection() {
# get the anime from indexed list # get the anime from indexed list
user_input=$(printf "${menu[@]}" | user_input=$(printf "${menu[@]}" |
rofi -dmenu -config "$CFG_DIR/${CFG_FILE}" \ rofi -dmenu -config "$CFG_DIR/${ROFI_CFG}" \
-a "$searched" \ -a "$searched" \
-l 12 -i -p "Enter number:") -l 12 -i -p "Enter number:")
[ "$?" -ne 0 ] && return 1 [ "$?" -ne 0 ] && return 1
choice=$(printf '%s\n' "$user_input" | awk '{print $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}') name=$(printf '%s\n' "$user_input" | awk '{print $NF}')
if [[ "$VERBOSE" -eq 1 ]]; then if [[ "$VERBOSE" -eq 1 ]]; then
printf "%s\n" "CHOICE: $name"
printf "%s\n" "NAME: $name" printf "%s\n" "NAME: $name"
fi fi
insert_history "$name" "search"
echo "Number Chosen: $choice"
# User input
# printf "$c_blue%s$c_green" "Enter number: "
# read choice
printf "$c_reset"
# check both choice and name are set
if [[ ! "$choice" ]] || [[ ! "$name" ]]; then
die "Invalid choice... committing seppuku"
fi
# Check if input is a number # Check if input is a number
[ "$choice" -eq "$choice" ] 2>/dev/null || die "Invalid number entered" [ "$choice" -eq "$choice" ] 2>/dev/null || die "Invalid number entered"
insert_history "$name" "search"
printf "$c_reset"
# Select respective anime_id # Select respective anime_id
count=1 count=1
while read anime_id; do while read anime_id; do
@ -338,18 +350,20 @@ episode_selection() {
-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/${CFG_FILE}" -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}')
[ "$VERBOSE" -eq 1 ] && printf "%s\n" "START: $ep_choice_start | END: $ep_choice_end"
if [[ -z "$ep_choice_start" ]] && [[ -z "$ep_choice_end" ]]; then
die "No episode range entered"
fi
# if only one episode was entered, set ep_choice_end to empty string so only selected episode plays # if only one episode was entered, set ep_choice_end to empty string so only selected episode plays
# otherwise plays from ep 1 - ep_choice_start # otherwise plays from ep 1 - ep_choice_start
if [[ "$ep_choice_start" -eq "$ep_choice_end" ]]; then if [[ "$ep_choice_start" -eq "$ep_choice_end" ]]; then
ep_choice_end="" ep_choice_end=""
fi fi
[ "$VERBOSE" -eq 1 ] && printf "%s\n" "START: $ep_choice_start | END: $ep_choice_end"
# read ep_choice_start ep_choice_end # read ep_choice_start ep_choice_end
printf "$c_reset" printf "$c_reset"
@ -360,9 +374,10 @@ open_episode() {
episode=$2 episode=$2
ddir=$3 ddir=$3
if [[ ! "$is_playlist" ]]; then
# clear the screen # clear the screen
printf '\x1B[2J\x1B[1;1H' printf '\x1B[2J\x1B[1;1H'
if [ $episode -lt 1 ] || [ $episode -gt $last_ep_number ]; then if [[ $episode -lt 1 ]] || [[ $episode -gt $last_ep_number ]]; then
err "Episode out of range" err "Episode out of range"
stmt="SELECT DISTINCT episode_number \ stmt="SELECT DISTINCT episode_number \
FROM watch_history \ FROM watch_history \
@ -375,9 +390,10 @@ open_episode() {
fi fi
episode=$(printf "%s\n" "${hist[@]}" | episode=$(printf "%s\n" "${hist[@]}" |
rofi -dmenu -l 12 -p "Choose Episode:" \ rofi -dmenu -l 12 -p "Choose Episode:" \
-config "$CFG_DIR/${CFG_FILE}") -config "$CFG_DIR/${ROFI_CFG}")
printf "$c_reset" printf "$c_reset"
fi fi
fi
[ "$VERBOSE" -eq 1 ] && printf "Getting data for episode %d\n" $episode [ "$VERBOSE" -eq 1 ] && printf "Getting data for episode %d\n" $episode
@ -414,14 +430,23 @@ open_episode() {
# add 0 padding to the episode name # add 0 padding to the episode name
episode=$(printf "%03d" $episode) episode=$(printf "%03d" $episode)
{ {
# (
# echo "$DDIR"
# cd "$ddir" || return 1
# mkdir -p "$anime_id" && cd "$anime_id" || return 1
# ffmpeg -headers "Referer: $dpage_url" -i "$video_url" \
# -codec copy "${anime_id}-${episode}.mkv" >/dev/null 2>&1 &&
# printf "${c_green}Downloaded episode: %s${c_reset}\n" "$episode" ||
# printf "${c_red}Download failed episode: %s${c_reset}\n" "$episode"
# )
( (
echo "$DDIR" echo "$DDIR"
cd "$ddir" || return 1 cd "$ddir" || return 1
mkdir -p "$anime_id" && cd "$anime_id" || return 1 mkdir -p "$anime_id" && cd "$anime_id" || return 1
ffmpeg -headers "Referer: $dpage_url" -i "$video_url" \ ffmpeg -headers "Referer: $dpage_url" -i "$video_url" \
-codec copy "${anime_id}-${episode}.mkv" >/dev/null 2>&1 && -codec copy "${anime_id}-${episode}.mkv" >/dev/null 2>&1 &&
printf "${c_green}Downloaded episode: %s${c_reset}\n" "$episode" || notify-send "Downloaded episode: $episode" ||
printf "${c_red}Download failed episode: %s${c_reset}\n" "$episode" notify-send "Download failed episode: $episode"
) )
} }
fi fi
@ -441,7 +466,11 @@ is_download=0
list_history=0 list_history=0
scrape=query scrape=query
download_dir="." download_dir="."
while getopts 'hd:Hl' OPT; do is_playlist=0
playlist_remove=0
playlist_add=0
playlist_file="$CFG_DIR/playlists/playlist.txt"
while getopts 'hd:Hlpad' OPT; do
case $OPT in case $OPT in
h) h)
help_text help_text
@ -461,6 +490,18 @@ while getopts 'hd:Hl' OPT; do
l) l)
list_history=1 list_history=1
;; ;;
p)
scrape=playlist
is_playlist=1
;;
a)
is_add=1
scrape=add
;;
d)
is_delete=1
scrape=delete
;;
esac esac
done done
shift $((OPTIND - 1)) shift $((OPTIND - 1))
@ -475,7 +516,7 @@ if [[ "$list_history" -eq 1 ]]; then
ORDER BY search_date DESC" ORDER BY search_date DESC"
hist=$(run_stmt "$stmt") hist=$(run_stmt "$stmt")
printf "%s\n" "${hist[@]}" | printf "%s\n" "${hist[@]}" |
rofi -config "$CFG_DIR/${CFG_FILE}" \ rofi -config "$CFG_DIR/${ROFI_CFG}" \
-dmenu -l 12 -i -p "Search History" -dmenu -l 12 -i -p "Search History"
exit 0 exit 0
fi fi
@ -487,6 +528,7 @@ case $scrape in
search_results=$(search_anime "$query") search_results=$(search_anime "$query")
[ -z "$search_results" ] && die "No search results found" [ -z "$search_results" ] && die "No search results found"
anime_selection "$search_results" anime_selection "$search_results"
[ $? -ne 0 ] && die "No anime selection found"
episode_selection episode_selection
;; ;;
history) history)
@ -501,6 +543,42 @@ case $scrape in
echo "EPISODE: $ep_choice_start" echo "EPISODE: $ep_choice_start"
# 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)
lines=$(cat "$playlist_file" | wc -l)
[ "$VERBOSE" -eq 1 ] && printf "%s%d\n" "Num lines in playlist: " "$lines"
if [[ "$lines" -eq 0 ]]; then
get_search_query "$*"
search_results=$(search_anime "$query")
[ -z "$search_results" ] && die "No search results found"
anime_selection "$search_results"
[ $? -ne 0 ] && die "No anime selection found"
episode_selection
else
line=($(sed '1q;d' "$playlist_file"))
if [[ "${#line[@]}" -ne 2 ]]; then
die "Something went wrong with the playlist file... exiting"
fi
selection_id="${line[0]}"
episodes=($selection_id)
ep_choice_start="${line[1]}"
ep_choice_end=""
read last_ep_number <<-EOF
$(search_eps "$selection_id")
EOF
[ "$VERBOSE" -eq 1 ] && printf "Anime: %s Episode: %d\n" "$episodes" "$ep_choice_start"
[ "$VERBOSE" -eq 1 ] && printf "Episodes: %s\n" "${episodes[@]}"
fi
;;
add)
get_search_query "$*"
search_results=$(search_anime "$query")
[ -z "$search_results" ] && die "No search results found"
anime_selection "$search_results"
[ $? -ne 0 ] && die "No anime selection found"
episode_selection
;;
delete)
;;
esac esac
{ # checking input { # checking input
@ -518,8 +596,20 @@ esac
grep -q -w "${selection_id}" "$logfile" || grep -q -w "${selection_id}" "$logfile" ||
printf "%s\t%d\n" "$selection_id" $((episode + 1)) >>"$logfile" printf "%s\t%d\n" "$selection_id" $((episode + 1)) >>"$logfile"
for ep in $episodes; do for ep in $episodes; do
if [[ "$is_add" -eq 1 ]]; then
echo "ID: $selection_id"
echo "EPISODES: $episodes"
printf "%s\n" "$selection_id $ep" >> "$playlist_file"
echo "Added to playlist file"
exit 0
else
open_episode "$selection_id" "$ep" "$download_dir" open_episode "$selection_id" "$ep" "$download_dir"
if [[ "$is_playlist" -eq 1 ]]; then
sed -i '1d' "$playlist_file"
fi
fi
done done
episode=${ep_choice_end:-$ep_choice_start} episode=${ep_choice_end:-$ep_choice_start}

View File

@ -4,6 +4,7 @@
CMD=/usr/local/bin/ani-cli CMD=/usr/local/bin/ani-cli
DEFAULT="$HOME/Videos/sauce/" DEFAULT="$HOME/Videos/sauce/"
DEFAULT_PLAYLIST="$HOME/Videos/sauce/playlists/playlist.txt"
CFG_DIR="$XDG_CONFIG_HOME/ani-cli" CFG_DIR="$XDG_CONFIG_HOME/ani-cli"
CFG_FILE="meh.rasi" CFG_FILE="meh.rasi"
@ -11,11 +12,11 @@ CFG_FILE="meh.rasi"
# not a wrapper around the ani-cli-rofi # not a wrapper around the ani-cli-rofi
options="1. Stream|2. Download|3. Continue|4. Quit" options="1. Stream|2. Download|3. Continue|4. Queue|5. Quit"
choice=$(echo "${options[@]}" | rofi -dmenu -sep '|' -config "$CFG_DIR/$CFG_FILE" -l 4 -i -p "Enter choice:") choice=$(echo "${options[@]}" | rofi -dmenu -sep '|' -config "$CFG_DIR/$CFG_FILE" -l 4 -i -p "Enter choice:")
[ "$choice" == "4. Quit" ] && ( [ "$choice" == "5. Quit" ] && (
echo 'Quitting...' echo 'Quitting...'
exit 0 exit 0
) )
@ -27,10 +28,25 @@ if [[ "$selection" == "1." ]]; then
$CMD $CMD
elif [[ "$selection" == "2." ]]; then elif [[ "$selection" == "2." ]]; then
dl_dir=$(rofi -dmenu -config "$CFG_DIR/$CFG_FILE" \ dl_dir=$(rofi -dmenu -config "$CFG_DIR/$CFG_FILE" \
-l 1 -p "Enter downlaod dir:") -l 1 -p "Enter download dir:")
# if dl_dir is none set to current directory # if dl_dir is none set to current directory
[ "$dl_dir" == "" ] && dl_dir="$DEFAULT" [ "$dl_dir" == "" ] && dl_dir="$DEFAULT"
$CMD -d "$dl_dir" $CMD -d "$dl_dir"
elif [[ "$selection" == "3." ]]; then elif [[ "$selection" == "3." ]]; then
$CMD -H $CMD -H
elif [[ "$selection" == "4." ]]; then
options="1. Play playlist|2. Add to playlist|3. Delete from playlist|4. Quit"
choice=$(echo "${options[@]}" | rofi -dmenu -sep '|' -config "$CFG_DIR/$CFG_FILE" -l 4 -i -p "Enter choice:")
[ "$choice" == "4. Quit" ] && (
echo 'Quitting...'
exit 0
)
selection=$(printf "%s\n" "$choice" | awk '{ print $1 }')
if [[ "$selection" == "1." ]]; then
"$CMD" -p
elif [[ "$selection" == "2." ]]; then
"$CMD" -a
elif [[ "$selection" == "3." ]]; then
"$CMD" -r
fi
fi fi

View File

@ -1,5 +1,5 @@
configuration { configuration {
font: "Open Sans 15"; font: "Open Sans 35";
display-drun: "Dmenu"; display-drun: "Dmenu";
scroll-method: 0; scroll-method: 0;
disable-history: false; disable-history: false;
@ -8,17 +8,18 @@ configuration {
* { * {
selected-normal-foreground: rgba ( 255, 147, 5, 100 % ); selected-normal-foreground: rgba ( 255, 147, 5, 100 % );
foreground: rgba ( 196, 203, 212, 100 % ); /* foreground: rgba ( 196, 203, 212, 100 % ); */
foreground: #ecbe7b;
normal-foreground: @foreground; normal-foreground: @foreground;
alternate-normal-background: rgba ( 45, 48, 59, 1 % ); alternate-normal-background: rgba ( 45, 48, 59, 1 % );
red: rgba ( 220, 50, 47, 100 % ); red: #ff6c6b;
selected-urgent-foreground: rgba ( 249, 249, 249, 100 % ); selected-urgent-foreground: rgba ( 249, 249, 249, 100 % );
blue: rgba ( 38, 139, 210, 100 % ); blue: #51afef;
urgent-foreground: rgba ( 204, 102, 102, 100 % ); urgent-foreground: rgba ( 204, 102, 102, 100 % );
alternate-urgent-background: rgba ( 75, 81, 96, 90 % ); alternate-urgent-background: rgba ( 75, 81, 96, 90 % );
active-foreground: rgba ( 101, 172, 255, 100 % ); active-foreground: #51afef;
lightbg: rgba ( 238, 232, 213, 100 % ); lightbg: rgba ( 238, 232, 213, 100 % );
selected-active-foreground: rgba ( 249, 249, 249, 100 % ); selected-active-foreground: #1E90FF;
alternate-active-background: rgba ( 45, 48, 59, 88 % ); alternate-active-background: rgba ( 45, 48, 59, 88 % );
background: rgba ( 45, 48, 59, 88 % ); background: rgba ( 45, 48, 59, 88 % );
alternate-normal-foreground: @foreground; alternate-normal-foreground: @foreground;
@ -35,9 +36,8 @@ configuration {
alternate-active-foreground: @active-foreground; alternate-active-foreground: @active-foreground;
active-background: rgba ( 29, 31, 33, 17 % ); active-background: rgba ( 29, 31, 33, 17 % );
selected-active-background: rgba ( 26, 28, 35, 100 % ); selected-active-background: rgba ( 26, 28, 35, 100 % );
black: #1d1d1d; black: #464b55;
blackwidget: #262626; blackwidget: #262626;
} }
@ -131,6 +131,7 @@ element.alternate.active {
text-color: #51afef; text-color: #51afef;
border-color: #51afef; border-color: #51afef;
} }
scrollbar { scrollbar {
width: 4px ; width: 4px ;
border: 0; border: 0;
@ -138,37 +139,45 @@ scrollbar {
handle-width: 8px ; handle-width: 8px ;
padding: 0; padding: 0;
} }
mode-switcher { mode-switcher {
border: 2px 0px 0px ; border: 2px 0px 0px ;
border-color: @separatorcolor; border-color: @separatorcolor;
} }
button { button {
spacing: 0; spacing: 0;
text-color: @normal-foreground; text-color: @normal-foreground;
} }
button.selected { button.selected {
background-color: @selected-normal-background; background-color: @selected-normal-background;
text-color: @selected-normal-foreground; text-color: @selected-normal-foreground;
} }
inputbar { inputbar {
spacing: 0; spacing: 0;
text-color: @normal-foreground; text-color: @normal-foreground;
padding: 5px ; padding: 6px;
} }
case-indicator { case-indicator {
spacing: 0; spacing: 0;
text-color: @normal-foreground; text-color: @normal-foreground;
} }
entry { entry {
padding: 6px 10px; padding: 6px 10px;
spacing: 0; spacing: 0;
text-color: @normal-foreground; text-color: @normal-foreground;
} }
prompt { prompt {
spacing: 0; spacing: 0;
text-color: #51afef; text-color: #51afef;
padding: 5px 0px; padding: 4px 0px;
} }
inputbar { inputbar {
children: [ prompt,textbox-prompt-colon,entry,case-indicator ]; children: [ prompt,textbox-prompt-colon,entry,case-indicator ];
padding: 15px 0px; padding: 15px 0px;
@ -179,5 +188,5 @@ textbox-prompt-colon {
str: ":"; str: ":";
margin: 0px 0.3em 0em 0em ; margin: 0px 0.3em 0em 0em ;
text-color: #51afef; text-color: #51afef;
padding: 5px 0px; padding: 4px 0px;
} }