update to scrape sbplay

This commit is contained in:
ksyasuda 2022-01-05 10:54:19 -08:00
parent 7ca1907998
commit 797df2b1fb
2 changed files with 33 additions and 43 deletions

65
ani-cli
View File

@ -120,29 +120,26 @@ get_dpage_link() {
get_video_quality() { get_video_quality() {
dpage_url=$1 dpage_url=$1
video_links=$(curl -s "$dpage_url" | sed -n -E 's/.*href="([^"]*)" download>Download.*/\1/p' | sed 's/amp;//') video_links=$(curl -s "$sb_url" | sed -n -E 's/.*a href="#" onclick="download_video([^"]*)".*/\1/p' | head -1)
case $quality in m=$(printf "%s" "$quality" | cut -c1)
best) i=$(printf "%s" "$video_links" | cut -d\' -f2)
video_link=$(printf '%s' "$video_links" | tail -n 1) 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/<a href="([^"]*.mp4)".*/\1/p')
worst) if [ -z "$video_link" ]; then
video_link=$(printf '%s' "$video_links" | head -n 1) err "$quality quality doesn't exist, falling back to normal quality"
;; video_link=$(curl -s "https://sbplay2.com/dl?op=download_orig&id=$i&mode=n&hash=$h" | sed -n -E 's/<a href="([^"]*.mp4)".*/\1/p')
*) fi
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
printf '%s' "$video_link" printf '%s' "$video_link"
} }
get_links() { get_links() {
dpage_url="$1" dpage_url="$1"
video_url=$(get_video_quality "$dpage_url") sb_url=$(curl -s "$dpage_url" |
sed -n -E 's/^[[:space:]]*href="([^"]*)".*/\1/p' | grep -oE ".*sbplay.*")
video_url=$(get_video_quality "$sb_url")
printf '%s' "$video_url" printf '%s' "$video_url"
} }
@ -203,7 +200,7 @@ update_date() {
datetime=$(date +'%Y-%m-%d %H:%M:%S') datetime=$(date +'%Y-%m-%d %H:%M:%S')
stmt="" stmt=""
if [[ "$1" == "file" ]]; then if [[ "$1" == "file" ]]; then
log "UPDATING FILE_HISTORY: anime_name='$1', search_date='$datetime'" log "UPDATING FILE_HISTORY: directory='$2', filename='$3', search_date='$datetime'"
stmt="UPDATE file_history SET watch_date = '$datetime' \ stmt="UPDATE file_history SET watch_date = '$datetime' \
WHERE directory = '$2' and filename = '$3';" WHERE directory = '$2' and filename = '$3';"
elif [[ "$2" == "search" ]]; then elif [[ "$2" == "search" ]]; then
@ -306,13 +303,10 @@ sync_watch_history() {
log "Inserted $cnt rows into watch_history table" log "Inserted $cnt rows into watch_history table"
} }
#####################
## END of db code ##
#####################
##################### #####################
### Play from file### ### Play from file###
##################### #####################
# opens the passed in file with $PLAYER_CMD # opens the passed in file with $PLAYER_CMD
play_file() { play_file() {
log "Checking if file is playable" log "Checking if file is playable"
@ -320,7 +314,7 @@ play_file() {
log "File is playable..." log "File is playable..."
filename=$(grep -oE '[^/]*$' <<< "$1") filename=$(grep -oE '[^/]*$' <<< "$1")
log "FILENAME: $filename" log "FILENAME: $filename"
insert_history "file" "$1" "$filename" insert_history "file" "$1" "$filename" &
if [[ "$1" =~ .mp3 ]]; then if [[ "$1" =~ .mp3 ]]; then
log ".mp3 file found... playing without video" log ".mp3 file found... playing without video"
log "MPV COMMAND: $PLAYER_CMD --no-video $1" log "MPV COMMAND: $PLAYER_CMD --no-video $1"
@ -394,10 +388,6 @@ find_media() {
fi fi
} }
###########################
## END of Play from file ##
###########################
# get query # get query
get_search_query() { get_search_query() {
# Query the anime to stream/download # Query the anime to stream/download
@ -533,7 +523,7 @@ anime_selection() {
[ -z "$name" ] && name="$anime_id" [ -z "$name" ] && name="$anime_id"
log "NAME: $name" log "NAME: $name"
insert_history "$name" "search" insert_history "$name" "search" &
printf "$c_reset" printf "$c_reset"
@ -625,11 +615,12 @@ open_episode() {
# Don't update watch history if downloading episode # Don't update watch history if downloading episode
if [ "$is_download" -eq 0 ]; then if [ "$is_download" -eq 0 ]; then
insert_history "$anime_id" "$episode" insert_history "$anime_id" "$episode" &
fi fi
dpage_link=$(get_dpage_link "$anime_id" "$episode") dpage_link=$(get_dpage_link "$anime_id" "$episode")
video_url=$(get_links "$dpage_link") video_url=$(get_links "$dpage_link")
referer_link="https://sbplay2.com"
if [ $half_ep -eq 1 ]; then if [ $half_ep -eq 1 ]; then
episode=$temp_ep episode=$temp_ep
@ -639,8 +630,8 @@ open_episode() {
if [ "$is_download" -eq 0 ]; then if [ "$is_download" -eq 0 ]; then
kill "$PID" > /dev/null 2>&1 kill "$PID" > /dev/null 2>&1
log "PLAYING VIDEO: $video_url" log "PLAYING VIDEO: $video_url"
log "REFERRER: $dpage_link" log "REFERRER: $referer_link"
nohup $player_fn --http-header-fields="Referer: $dpage_link" "$video_url" > /dev/null 2>&1 & nohup "$player_fn" --http-header-fields="Referer:$referer_link" "$video_url" > /dev/null 2>&1 &
PID=$! PID=$!
printf "${c_green}\nVideo playing" printf "${c_green}\nVideo playing"
else else
@ -652,12 +643,12 @@ 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
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 "$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" notify-send -i "$MAISAN_ICON_PATH" "Download failed for ${anime_id//-/ } - Episode: $episode. Please retry or check your internet connection"
else else
# curl -L -# -e "$dpage_link" -C - "$play_link" -o "${anime_id}-${episode}.mp4" && 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 "${anime_id}-${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_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" printf "${c_red}Download failed for %s - Episode: %s, please retry or check your internet connection${c_reset}\n" "${anime_id//-/ }" "$episode"
fi fi
@ -689,7 +680,7 @@ stream() {
# skip search_anime function and assign $query # skip search_anime function and assign $query
anime_id="${query// /}" anime_id="${query// /}"
selection_id="$anime_id" selection_id="$anime_id"
insert_history "$anime_id" "search" insert_history "$anime_id" "search" &
read -r last_ep_number <<< "$(search_eps "$selection_id")" read -r last_ep_number <<< "$(search_eps "$selection_id")"
fi fi
episode_selection episode_selection
@ -704,7 +695,7 @@ trap "printf '$c_reset'" INT HUP
# option parsing # option parsing
scrape=query scrape=query
quality=best quality=normal
is_rofi=1 is_rofi=1
is_download=0 is_download=0
download_dir="." download_dir="."

View File

@ -9,9 +9,8 @@ CMD="/usr/bin/ani-cli"
DEFAULT_DOWNLOAD="$HOME/Videos/sauce" DEFAULT_DOWNLOAD="$HOME/Videos/sauce"
CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/aniwrapper" CFG_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/aniwrapper"
CFG_FILE="aniwrapper.rasi" CFG_FILE="aniwrapper.rasi"
QUALITIES="1. best (default)|2. 1080p|3. 720p|4. 480p|5. 360p|6. worst" QUALITIES="1. high|2. normal (default)|3. low"
QUALITY="best" QUALITY=normal
PLAYER_CMD="mpv -config-dir ${XDG_CONFIG_HOME:-$HOME/.config}/mpv"
GET_QUALITY=0 GET_QUALITY=0
VERBOSE=0 VERBOSE=0
IS_ROFI=1 IS_ROFI=1
@ -20,7 +19,6 @@ IS_PLAY_FROM_FILE=0
quit="6. Quit" quit="6. Quit"
options="1. Stream|2. Download|3. Continue|4. Play from File|5. Sync History|$quit" options="1. Stream|2. Download|3. Continue|4. Play from File|5. Sync History|$quit"
playable="\.mp4|\.mkv|\.ts|\.mp3"
############# #############
# Functions # # Functions #
@ -64,11 +62,12 @@ create_default_download() {
get_quality() { get_quality() {
if [ "$IS_ROFI" -eq 1 ]; then if [ "$IS_ROFI" -eq 1 ]; then
selection=$(rofi -dmenu -config "$CFG_DIR/$CFG_FILE" \ 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") -sep '|' <<< "$QUALITIES")
QUALITY=$(awk '{print $2}' <<< "$selection") QUALITY=$(awk '{print $2}' <<< "$selection")
else else
printf "%s" "Enter quality [ best|1080|720|480|360|worst ]: " printf "%s" "Enter quality [$QUALITIES]: "
read -r QUALITY read -r QUALITY
fi fi
log "selected quality: $QUALITY" log "selected quality: $QUALITY"