Add option to browse recently updated anime (#6)

* add recently updated anime option

* update aniwrapper menu ordering and increase columns to 2

* replace hardcoded base_url with variable
This commit is contained in:
Kyle Yasuda 2022-06-12 00:00:37 -07:00 committed by GitHub
parent ba6c302022
commit 4828923abb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 8 deletions

34
ani-cli
View File

@ -877,7 +877,7 @@ parse_args() {
is_download=0
is_resume=0
is_autoplay=0
while getopts 'ad:Hsvq:cf:t:T:CQ:D:Sp:r' OPT; do
while getopts 'ad:Hsvq:cf:t:T:CQ:D:Sp:rR' OPT; do
case "$OPT" in
a)
is_autoplay=1
@ -890,6 +890,9 @@ parse_args() {
r)
is_resume=1
;;
R)
scrape=recent
;;
H)
scrape=history
;;
@ -1098,6 +1101,35 @@ main() {
play_file "$video_path"
exit $?
;;
recent)
# get list of recently added anime from $BASE_URL
recently_updated="$(curl -s "$BASE_URL" | sed -nE 's_^[[:space:]]*<a href="/videos/([^"]*)">_\1_p')"
while read -r updated_episode; do
anime_name=$(printf "%s" "$updated_episode" | sed -E 's/\-episode\-.*//')
lg "ANIME NAME: $anime_name"
if ! check_db "search" "$anime_name"; then
stmt="SELECT COUNT(*) FROM watch_history WHERE anime_name = '$anime_name' AND episode_number = '${updated_episode##*-episode-}';"
lg "QUERY: $stmt"
if [[ "$(run_stmt "$stmt")" -ne 0 ]]; then
lg "$updated_episode watched before... adding to watched list"
[[ -z "$watched" ]] && watched="$cnt" || watched="$watched, $cnt"
fi
fi
((++cnt))
done <<< "$recently_updated"
selection="$(rofi -dpi "$DPI" -dmenu -no-custom -config "$ROFI_CFG" \
-l 15 -a "$watched" -i -p "Enter selection" -async-pre-read 30 \
-window-title 'aniwrapper' <<< "$recently_updated")"
if [ -z "$selection" ]; then
die "No selection made"
fi
lg "SELECTION: $selection"
# get everything before -episode-
selection_id="${selection%%-episode-*}"
# get everything after -episode-
ep_choice_start="${selection##*-episode-}"
search_eps "$selection_id" "$ep_choice_start"
;;
esac
check_input

View File

@ -27,8 +27,8 @@ IS_ALTERNATE_PLAYER=0
VERBOSE=0
SILENT=0
quit="7. Quit"
options="1. Stream|2. Download|3. Continue|4. Play from File|5. Sync History|6. Choose Theme|$quit"
quit="8. Quit"
options="1. Stream|2. Download|3. Continue|4. Recently Updated|5. Play from File|6. Sync History|7. Choose Theme|$quit"
theme=default
help_text() {
@ -332,8 +332,8 @@ main() {
((SILENT != 1)) && lg "CONFIG DIR: $CFG_DIR"
((SILENT != 1)) && lg "ROFI CFG: $CFG_FILE"
choice=$(echo "${options[@]}" | rofi -dpi "$DPI" -dmenu -no-custom -sep '|' \
-theme-str 'listview {columns: 1;} window {width: 45%;}' \
-config "$CFG_FILE" -l 7 -i -p "Aniwrapper" -window-title 'aniwrapper')
-theme-str 'listview {columns: 2;} window {width: 45%;}' \
-config "$CFG_FILE" -l 4 -i -p "Aniwrapper" -window-title 'aniwrapper')
[ "$choice" == "$quit" ] && quit
@ -353,6 +353,10 @@ main() {
run -H
;;
4.)
lg "Showing recently updated anime"
run -R
;;
5.)
lg "Play from file selected"
IS_PLAY_FROM_FILE=1
span=$(printf '%s\n%s\n' "$(generate_span "Provide a path to a valid directory, or choose from the list below")" "$(generate_span "The program will begin searching for media files from the supplied directory")")
@ -374,7 +378,7 @@ main() {
fi
exit $?
;;
5.)
6.)
lg "Sync history database"
IS_SYNC=1
roficmd="rofi -dpi $DPI -dmenu -config $CFG_FILE -l 0 -p"
@ -393,7 +397,7 @@ main() {
quit
fi
;;
6.)
7.)
[ -z "$THEMES" ] && die "No themes provided... exiting"
theme_idx="$(get_theme_idx)"
lg "Theme index: $theme_idx"
@ -406,7 +410,7 @@ main() {
set_theme "$theme"
main
;;
7.)
8.)
quit
;;
*)