diff --git a/README.md b/README.md index 405a7af..8a67ecb 100644 --- a/README.md +++ b/README.md @@ -193,7 +193,7 @@ aniwrapper -C aniwrapper -Q # Choose rofi theme from presets -aniwrapper -t +aniwrapper -t # Specify custom rofi config aniwrapper -T @@ -258,7 +258,7 @@ ani-cli -H ani-cli -s # choose quality -ani-cli -q +ani-cli -q # choose rofi theme from presets ani-cli -t diff --git a/ani-cli b/ani-cli index 5af4e6b..26f9cd1 100755 --- a/ani-cli +++ b/ani-cli @@ -49,44 +49,7 @@ logger() { [ "$VERBOSE" -eq 1 ] && printf "%s\n" "$*" >&2 } -search_anime() { - # get anime name along with its id - logger "NUM ARGS: $#" - if [[ $# -gt 1 ]]; then - # if multi-word query, concatenate into one string and replace spaces with '-' - search="$*" - search="${search// /-}" - else - # if one word, remove leading or trailing whitespace - search="${1// /}" - fi - logger "Search Query: $search" - titlepattern=' /dev/null || die "Invalid number entered: $ep_choice_start" episodes=$ep_choice_start if [ -n "$ep_choice_end" ]; then @@ -110,23 +73,48 @@ get_dpage_link() { fi printf '%s' "$anime_page" | - sed -n -E 's/.*rel="13" data-video="([^"]*)".*/\1/p' | cut -d/ -f5 + sed -n -E 's/^[[:space:]]* /dev/stderr + ajax_url="https://gogoplay.io/encrypt-ajax.php" + + #get the id from the url + video_id=$(printf "$1" | cut -d\? -f2 | cut -d\& -f1 | sed 's/id=//g') + logger "video_id -> $video_id" > /dev/stderr + + #construct ajax parameters + secret_key='3235373436353338353932393338333936373634363632383739383333323838' + iv='34323036393133333738303038313335' + ajax=$(printf "$video_id" | openssl enc -aes256 -K "$secret_key" -iv "$iv" -a) + logger "ajax -> $ajax" > /dev/stderr + + #send the request to the ajax url + curl -s -H 'x-requested-with:XMLHttpRequest' "$ajax_url" -d "id=$ajax" -d "time=69420691337800813569" | tr '"' '\n' | sed -nE 's/.*cdn\.com.*/\0/p' | sed 's/\\//g' + logger "END: decrypt_link()" > /dev/stderr } get_video_quality() { dpage_url=$1 - - video_links=$(curl -s "https://sbplay2.com/d/$dpage_url" | sed -n -E 's/.*a href="#" onclick="download_video([^"]*)".*/\1/p' | head -1) - logger "VIDEO LINKS: $video_links" 1> /dev/stderr - m=$(printf "%s" "$quality" | cut -c1) - h=$(printf "%s" "$video_links" | cut -d\' -f6) - logger "constructed video link -> https://sbplay2.com/dl?op=download_orig&id=$dpage_url&mode=$m&hash=$h" 1> /dev/stderr - video_link=$(curl -s "https://sbplay2.com/dl?op=download_orig&id=$dpage_url&mode=$m&hash=$h" | sed -n -E 's/ /dev/null; then @@ -151,16 +135,22 @@ notification() { fi } +generate_span() { + msg="$*" + span="$msg" + printf "%s\n" "$span" +} + ##################### ## Database Code ## ##################### +run_stmt() { + printf "%s\n" "$1" | sqlite3 -noheader "$HISTORY_DB" +} + +# Return number of matches for anime/episode in db check_db() { - # Return number of matches for anime/episode in db - # args: - # $1: anime name: str - # $2: either 'search' or 'watch' for which db to query - # logger "BEGIN check_db()" if [[ "$1" == "directory" ]]; then stmt="SELECT DISTINCT COUNT(*) \ FROM file_history \ @@ -182,7 +172,6 @@ check_db() { fi res=$(run_stmt "$stmt") return $res - # logger "END check_db... Result -> $res" } # return true (0) if $source_dt > $target_dt @@ -236,9 +225,9 @@ update_date() { run_stmt "$stmt" } +# inserts into search/watch history db +# check the anime_name/id insert_history() { - # inserts into search/watch history db - # check the anime_name/id datetime=$(date +'%Y-%m-%d %H:%M:%S') logger "Checking if ($*) exists in db" check_db "$@" @@ -276,18 +265,15 @@ sync_search_history() { errs=0 while read -r line; do anime_name=$(awk -F '|' '{print $2}' <<< "$line") - # logger "Checking if $anime_name has been searched..." res=$(sqlite3 -noheader "$HISTORY_DB" "SELECT COUNT(*) FROM search_history WHERE anime_name = '$anime_name'") if [[ "$res" -eq 0 ]]; then search_date=$(awk -F '|' '{print $3}' <<< "$line") - # logger "Not found in db... Adding ($anime_name|$search_date) to search history..." if ! sqlite3 "$HISTORY_DB" "INSERT INTO search_history(anime_name, search_date) VALUES('$anime_name', '$search_date')"; then ((++errs)) continue fi ((++cnt)) fi - # logger done < <(sqlite3 -list -noheader "$temp_db" "SELECT DISTINCT * FROM search_history") logger "$cnt rows inserted into search_history table" logger "$errs errors on insert" @@ -298,11 +284,8 @@ sync_watch_history() { errs=0 while read -r line; do anime_name="${line/ //}" - # some spacing for log messages - # logger && logger "ANIME: $anime_name" # for each episode of $anime_name on the remote machine, check local while read -r ep; do - # logger episode_num=$(awk -F '|' '{print $1}' <<< "$ep") watch_date=$(awk -F '|' '{print $NF}' <<< "$ep") if ! insert_history "$anime_name" "$episode_num" "$watch_date"; then @@ -426,6 +409,10 @@ find_media() { esac } +##################### +## main code ## +##################### + # get query get_search_query() { # Get search history @@ -450,15 +437,39 @@ get_search_query() { fi } -generate_span() { - msg="$*" - span="$msg" - printf "%s\n" "$span" +search_anime() { + # get anime name along with its id + logger "NUM ARGS: $#" + if [[ $# -gt 1 ]]; then + # if multi-word query, concatenate into one string and replace spaces with '-' + search="$*" + search="${search// /-}" + else + # if one word, remove leading or trailing whitespace + search="${1// /}" + fi + logger "Search Query: $search" + titlepattern=' /dev/null 2>&1 - logger "PLAYING VIDEO: $video_url" - logger "REFERRER: $referer_link" - nohup "$player_fn" --http-header-fields="Referer:$referer_link" "$video_url" > /dev/null 2>&1 & + nohup "$player_fn" --http-header-fields="Referer:$dpage_link" "$video_url" > /dev/null 2>&1 & PID=$! if command -v "notify-send" > /dev/null; then notify-send -i "$ANIWRAPPER_ICON_PATH" "Playing $anime_id - Episode $episode" @@ -672,18 +678,17 @@ open_episode() { fi else logger "Downloading episode $episode ..." - logger "$video_url" dl_dir="${ddir// /}/$anime_id" # add 0 padding to the episode name episode=$(printf "%03d" "$episode") { mkdir -p "$dl_dir" || die "Could not create directory" if command -v "notify-send" > /dev/null; then - aria2c -x 16 -s 16 --referer="$referer_link" "$video_url" --dir="$dl_dir" -o "$episode.mp4" --download-result=hide && + aria2c -x 16 -s 16 --referer="$dpage_link" "$video_url" --dir="$dl_dir" -o "$episode.mp4" --download-result=hide && notify-send -i "$ANIWRAPPER_ICON_PATH" "Download complete for ${anime_id//-/ } - Episode: $episode" || notify-send -i "$MAISAN_ICON_PATH" "Download failed for ${anime_id//-/ } - Episode: $episode. Please retry or check your internet connection" else - aria2c -x 16 -s 16 --referer="$referer_link" "$video_url" --dir="$dl_dir" -o "$episode.mp4" --download-result=hide && + aria2c -x 16 -s 16 --referer="$dpage_link" "$video_url" --dir="$dl_dir" -o "$episode.mp4" --download-result=hide && printf "${c_green}Downloaded complete for %s - Episode: %s${c_reset}\n" "${anime_id//-/ }" "$episode" || printf "${c_red}Download failed for %s - Episode: %s, please retry or check your internet connection${c_reset}\n" "${anime_id//-/ }" "$episode" @@ -724,16 +729,12 @@ stream() { episode_selection } -############ -# Start Up # -############ - # to clear the colors when exited using SIGINT trap "printf '$c_reset'" INT HUP # option parsing scrape=query -quality=normal +quality=best is_rofi=1 is_download=0 download_dir="." diff --git a/aniwrapper b/aniwrapper index 874d77c..6cb9252 100755 --- a/aniwrapper +++ b/aniwrapper @@ -11,7 +11,7 @@ CFG_FILE="$CFG_DIR/themes/aniwrapper.rasi" DEFAULT_DOWNLOAD="$HOME/Videos/sauce" ROFI_THEME="aniwrapper.rasi" THEMES="aniwrapper (default)|dracula|doomone|fancy|flamingo|material|nord|onedark" -QUALITIES="1. high|2. normal (default)|3. low" +QUALITIES="1. best (default)|2. 1080p|3. 720p|4. 360p|5. worst" QUALITY=normal DPI=96 GET_QUALITY=0 @@ -85,9 +85,9 @@ run() { get_quality() { if [ "$IS_ROFI" -eq 1 ]; then selection=$(rofi -dpi "$DPI" -dmenu -config "$CFG_FILE" \ - -l 3 -selected-row 1 \ + -l 5 -selected-row 0 \ -theme-str 'listview {columns: 1;}' -p "Choose video quality:" \ - -sep '|' <<< "$QUALITIES") + -sep '|' -only-match <<< "$QUALITIES") QUALITY=$(awk '{print $2}' <<< "$selection") else printf "%s" "Enter quality [$QUALITIES]: "