Compare commits

...

4 Commits

Author SHA1 Message Date
ksyasuda
50af29a5bd make silent option more silent 2022-01-31 03:25:52 -08:00
ksyasuda
86f5da5976 Merge branch 'master' of github.com:ksyasuda/aniwrapper 2022-01-31 03:23:26 -08:00
ksyasuda
9a19dbf60c fix bug with marking played files as active 2022-01-31 03:18:08 -08:00
ksyasuda
ddb8d01ff2 only get base_url if scrape is stream or history 2022-01-31 02:42:35 -08:00
2 changed files with 12 additions and 9 deletions

15
ani-cli
View File

@ -1,6 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
BASE_URL=$(curl -s -L -o /dev/null -w "%{url_effective}\n" https://gogoanime.cm)
CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/aniwrapper" CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/aniwrapper"
HISTORY_DB="$CFG_DIR/history.sqlite3" HISTORY_DB="$CFG_DIR/history.sqlite3"
PLAYER_CMD="mpv" PLAYER_CMD="mpv"
@ -15,7 +14,6 @@ SILENT=0
player_fn="mpv" player_fn="mpv"
playable="\.mp4|\.mkv|\.ts|\.mp3|\.webm" playable="\.mp4|\.mkv|\.ts|\.mp3|\.webm"
playable_list="mp4,mkv,ts,mp3,webm"
prog="ani-cli" prog="ani-cli"
c_red="\033[1;31m" c_red="\033[1;31m"
c_green="\033[1;32m" c_green="\033[1;32m"
@ -336,6 +334,7 @@ get_directory_data() {
[ "$search_dir" = "/" ] && cnt=0 # account for no ../ on / [ "$search_dir" = "/" ] && cnt=0 # account for no ../ on /
for directory in "$1"/*; do for directory in "$1"/*; do
directory="${directory##*/}" directory="${directory##*/}"
[ ! -d "$search_dir/$directory" ] && continue
[ -z "$inputlist" ] && inputlist="$directory" || inputlist="$inputlist|$directory" [ -z "$inputlist" ] && inputlist="$directory" || inputlist="$inputlist|$directory"
if ! check_db "directory" "$search_dir/$directory"; then if ! check_db "directory" "$search_dir/$directory"; then
lg "$search_dir/$directory opened before... adding $cnt to list" 1> /dev/stderr lg "$search_dir/$directory opened before... adding $cnt to list" 1> /dev/stderr
@ -345,7 +344,8 @@ get_directory_data() {
done done
shopt -s nullglob # set nullglob to avoid printing output if no files with extension exist shopt -s nullglob # set nullglob to avoid printing output if no files with extension exist
shopt -s nocaseglob # case insensitive globbing shopt -s nocaseglob # case insensitive globbing
for filename in "$1"/*."{$playable_list}"; do for filename in "$search_dir"/*.{mp4,mkv,ts,mp3,webm}; do
filename="${filename##*/}"
[ -z "$inputlist" ] && inputlist="$filename" || inputlist="$inputlist|$filename" [ -z "$inputlist" ] && inputlist="$filename" || inputlist="$inputlist|$filename"
if ! check_db "file" "$search_dir" "$filename"; then if ! check_db "file" "$search_dir" "$filename"; then
lg "$filename watched before... adding $cnt to list" 1> /dev/stderr lg "$filename watched before... adding $cnt to list" 1> /dev/stderr
@ -355,13 +355,14 @@ get_directory_data() {
done done
shopt -u nullglob shopt -u nullglob
shopt -u nocaseglob shopt -u nocaseglob
lg "INPUTLIST: $inputlist"
if [[ -n "$inputlist" && "$search_dir" != / ]]; then if [[ -n "$inputlist" && "$search_dir" != / ]]; then
inputlist="../|$inputlist|Back|Quit" inputlist="../|$inputlist|Back|Quit"
elif [[ -z "$inputlist" && "$search_dir" != / ]]; then elif [[ -z "$inputlist" && "$search_dir" != / ]]; then
inputlist="../|Back|Quit" inputlist="../|Back|Quit"
elif [[ "$search_dir" = / ]]; then elif [[ "$search_dir" = / ]]; then
inputlist="$inputlist|Back|Quit" inputlist="$inputlist|Back|Quit"
else
inputlist="Quit"
fi fi
lg "INPUT LIST: $inputlist" 1> /dev/stderr lg "INPUT LIST: $inputlist" 1> /dev/stderr
lg "WATCHED LIST: $watched" 1> /dev/stderr lg "WATCHED LIST: $watched" 1> /dev/stderr
@ -689,13 +690,13 @@ open_episode() {
{ {
mkdir -p "$dl_dir" || die "Could not create directory" mkdir -p "$dl_dir" || die "Could not create directory"
if command -v "notify-send" > /dev/null; then if command -v "notify-send" > /dev/null; then
if aria2c --referer="$dpage_link" "$video_url" --dir="$dl_dir" -o "$episode.mp4" --download-result=hide; then if aria2c -x 16 -s 16 --referer="$dpage_link" "$video_url" --dir="$dl_dir" -o "$episode.mp4" --download-result=hide; then
notify-send -i "$ANIWRAPPER_ICON_PATH" "Download complete for ${anime_id//-/ } - Episode: $episode" notify-send -i "$ANIWRAPPER_ICON_PATH" "Download complete for ${anime_id//-/ } - Episode: $episode"
else else
notify-send -i "$MAISAN_ICON_PATH" "Download failed for ${anime_id//-/ } - Episode: $episode. Please retry or check your internet connection" notify-send -i "$MAISAN_ICON_PATH" "Download failed for ${anime_id//-/ } - Episode: $episode. Please retry or check your internet connection"
fi fi
else else
if aria2c --referer="$dpage_link" "$video_url" --dir="$dl_dir" -o "$episode.mp4" --download-result=hide; then if aria2c -x 16 -s 16 --referer="$dpage_link" "$video_url" --dir="$dl_dir" -o "$episode.mp4" --download-result=hide; then
((SILENT != 1)) && printf "${c_green}Downloaded complete for %s - Episode: %s${c_reset}\n" "${anime_id//-/ }" "$episode" ((SILENT != 1)) && printf "${c_green}Downloaded complete for %s - Episode: %s${c_reset}\n" "${anime_id//-/ }" "$episode"
else else
((SILENT != 1)) && printf "${c_red}Download failed for %s - Episode: %s, please retry or check your internet connection${c_reset}\n" "${anime_id//-/ }" "$episode" ((SILENT != 1)) && printf "${c_red}Download failed for %s - Episode: %s, please retry or check your internet connection${c_reset}\n" "${anime_id//-/ }" "$episode"
@ -851,9 +852,11 @@ parse_args() {
main() { main() {
case $scrape in case $scrape in
query) query)
BASE_URL=$(curl -s -L -o /dev/null -w "%{url_effective}\n" https://gogoanime.cm)
stream stream
;; ;;
history) history)
BASE_URL=$(curl -s -L -o /dev/null -w "%{url_effective}\n" https://gogoanime.cm)
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"

View File

@ -65,7 +65,7 @@ seppuku() {
} }
quit() { quit() {
lg 'Quitting...' ((SILENT != 1)) && lg 'Quitting...'
exit 0 exit 0
} }
@ -326,7 +326,7 @@ main() {
} }
parse_args "$@" parse_args "$@"
lg "CONFIG DIR: $CFG_DIR" ((SILENT != 1)) && lg "CONFIG DIR: $CFG_DIR"
lg "ROFI CFG: $CFG_FILE" ((SILENT != 1)) && lg "ROFI CFG: $CFG_FILE"
check_flags check_flags
main main