mirror of
https://github.com/ksyasuda/aniwrapper.git
synced 2024-10-28 04:44:11 -07:00
update to scrape sbplay
This commit is contained in:
parent
7ca1907998
commit
797df2b1fb
61
ani-cli
61
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")
|
||||
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/<a href="([^"]*.mp4)".*/\1/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)
|
||||
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
|
||||
;;
|
||||
esac
|
||||
|
||||
printf '%s' "$video_link"
|
||||
}
|
||||
|
||||
get_links() {
|
||||
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"
|
||||
}
|
||||
|
||||
@ -203,7 +200,7 @@ update_date() {
|
||||
datetime=$(date +'%Y-%m-%d %H:%M:%S')
|
||||
stmt=""
|
||||
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' \
|
||||
WHERE directory = '$2' and filename = '$3';"
|
||||
elif [[ "$2" == "search" ]]; then
|
||||
@ -306,13 +303,10 @@ sync_watch_history() {
|
||||
log "Inserted $cnt rows into watch_history table"
|
||||
}
|
||||
|
||||
#####################
|
||||
## END of db code ##
|
||||
#####################
|
||||
|
||||
#####################
|
||||
### Play from file###
|
||||
#####################
|
||||
|
||||
# opens the passed in file with $PLAYER_CMD
|
||||
play_file() {
|
||||
log "Checking if file is playable"
|
||||
@ -320,7 +314,7 @@ play_file() {
|
||||
log "File is playable..."
|
||||
filename=$(grep -oE '[^/]*$' <<< "$1")
|
||||
log "FILENAME: $filename"
|
||||
insert_history "file" "$1" "$filename"
|
||||
insert_history "file" "$1" "$filename" &
|
||||
if [[ "$1" =~ .mp3 ]]; then
|
||||
log ".mp3 file found... playing without video"
|
||||
log "MPV COMMAND: $PLAYER_CMD --no-video $1"
|
||||
@ -394,10 +388,6 @@ find_media() {
|
||||
fi
|
||||
}
|
||||
|
||||
###########################
|
||||
## END of Play from file ##
|
||||
###########################
|
||||
|
||||
# get query
|
||||
get_search_query() {
|
||||
# Query the anime to stream/download
|
||||
@ -533,7 +523,7 @@ anime_selection() {
|
||||
|
||||
[ -z "$name" ] && name="$anime_id"
|
||||
log "NAME: $name"
|
||||
insert_history "$name" "search"
|
||||
insert_history "$name" "search" &
|
||||
|
||||
printf "$c_reset"
|
||||
|
||||
@ -625,11 +615,12 @@ open_episode() {
|
||||
|
||||
# Don't update watch history if downloading episode
|
||||
if [ "$is_download" -eq 0 ]; then
|
||||
insert_history "$anime_id" "$episode"
|
||||
insert_history "$anime_id" "$episode" &
|
||||
fi
|
||||
|
||||
dpage_link=$(get_dpage_link "$anime_id" "$episode")
|
||||
video_url=$(get_links "$dpage_link")
|
||||
referer_link="https://sbplay2.com"
|
||||
|
||||
if [ $half_ep -eq 1 ]; then
|
||||
episode=$temp_ep
|
||||
@ -639,8 +630,8 @@ open_episode() {
|
||||
if [ "$is_download" -eq 0 ]; then
|
||||
kill "$PID" > /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="."
|
||||
|
11
aniwrapper
11
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"
|
||||
|
Loading…
Reference in New Issue
Block a user