From 797df2b1fbb742618854f524b9ac78e955830444 Mon Sep 17 00:00:00 2001 From: ksyasuda Date: Wed, 5 Jan 2022 10:54:19 -0800 Subject: [PATCH] update to scrape sbplay --- ani-cli | 65 +++++++++++++++++++++++------------------------------- aniwrapper | 11 +++++---- 2 files changed, 33 insertions(+), 43 deletions(-) diff --git a/ani-cli b/ani-cli index e06d6e5..e7e63c9 100755 --- a/ani-cli +++ b/ani-cli @@ -120,29 +120,26 @@ get_dpage_link() { get_video_quality() { dpage_url=$1 - video_links=$(curl -s "$dpage_url" | sed -n -E 's/.*href="([^"]*)" download>Download.*/\1/p' | sed 's/amp;//') - case $quality in - best) - video_link=$(printf '%s' "$video_links" | tail -n 1) - ;; - worst) - video_link=$(printf '%s' "$video_links" | head -n 1) - ;; - *) - video_link=$(printf '%s' "$video_links" | grep -i "${quality}p") - if [ -z "$video_link" ]; then - err "Current video quality is not available (defaulting to highest quality)" - quality=best - video_link=$(printf '%s' "$video_links" | tail -n 1) - fi - ;; - esac + video_links=$(curl -s "$sb_url" | sed -n -E 's/.*a href="#" onclick="download_video([^"]*)".*/\1/p' | head -1) + m=$(printf "%s" "$quality" | cut -c1) + i=$(printf "%s" "$video_links" | cut -d\' -f2) + h=$(printf "%s" "$video_links" | cut -d\' -f6) + video_link=$(curl -s "https://sbplay2.com/dl?op=download_orig&id=$i&mode=$m&hash=$h" | sed -n -E 's/ /dev/null 2>&1 log "PLAYING VIDEO: $video_url" - log "REFERRER: $dpage_link" - nohup $player_fn --http-header-fields="Referer: $dpage_link" "$video_url" > /dev/null 2>&1 & + log "REFERRER: $referer_link" + nohup "$player_fn" --http-header-fields="Referer:$referer_link" "$video_url" > /dev/null 2>&1 & PID=$! printf "${c_green}\nVideo playing" else @@ -652,12 +643,12 @@ open_episode() { { mkdir -p "$dl_dir" || die "Could not create directory" if command -v "notify-send" > /dev/null; then - aria2c -x 16 -s 16 --referer "$dpage_link" "$video_url" --dir="$dl_dir" -o "${anime_id}-${episode}.mp4" --download-result=hide && + aria2c -x 16 -s 16 --referer="$referer_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 - # curl -L -# -e "$dpage_link" -C - "$play_link" -o "${anime_id}-${episode}.mp4" && - aria2c -x 16 -s 16 --referer "$dpage_link" "$video_url" --dir="$dl_dir" -o "${anime_id}-${episode}.mp4" --download-result=hide && + aria2c -x 16 -s 16 --referer="$referer_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" || 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" fi @@ -689,7 +680,7 @@ stream() { # skip search_anime function and assign $query anime_id="${query// /}" selection_id="$anime_id" - insert_history "$anime_id" "search" + insert_history "$anime_id" "search" & read -r last_ep_number <<< "$(search_eps "$selection_id")" fi episode_selection @@ -704,7 +695,7 @@ trap "printf '$c_reset'" INT HUP # option parsing scrape=query -quality=best +quality=normal is_rofi=1 is_download=0 download_dir="." diff --git a/aniwrapper b/aniwrapper index f328799..f491328 100755 --- a/aniwrapper +++ b/aniwrapper @@ -9,9 +9,8 @@ CMD="/usr/bin/ani-cli" DEFAULT_DOWNLOAD="$HOME/Videos/sauce" CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/aniwrapper" CFG_FILE="aniwrapper.rasi" -QUALITIES="1. best (default)|2. 1080p|3. 720p|4. 480p|5. 360p|6. worst" -QUALITY="best" -PLAYER_CMD="mpv -config-dir ${XDG_CONFIG_HOME:-$HOME/.config}/mpv" +QUALITIES="1. high|2. normal (default)|3. low" +QUALITY=normal GET_QUALITY=0 VERBOSE=0 IS_ROFI=1 @@ -20,7 +19,6 @@ IS_PLAY_FROM_FILE=0 quit="6. Quit" options="1. Stream|2. Download|3. Continue|4. Play from File|5. Sync History|$quit" -playable="\.mp4|\.mkv|\.ts|\.mp3" ############# # Functions # @@ -64,11 +62,12 @@ create_default_download() { get_quality() { if [ "$IS_ROFI" -eq 1 ]; then selection=$(rofi -dmenu -config "$CFG_DIR/$CFG_FILE" \ - -l 6 -theme-str 'listview {columns: 1;}' -p "Choose video quality:" \ + -l 3 -selected-row 1 \ + -theme-str 'listview {columns: 1;}' -p "Choose video quality:" \ -sep '|' <<< "$QUALITIES") QUALITY=$(awk '{print $2}' <<< "$selection") else - printf "%s" "Enter quality [ best|1080|720|480|360|worst ]: " + printf "%s" "Enter quality [$QUALITIES]: " read -r QUALITY fi log "selected quality: $QUALITY"