Refactor and bump version to 3.0.0

This commit is contained in:
coolnsx
2024-02-07 00:30:11 +05:30
parent 592e280068
commit e33bfcb6b8
2 changed files with 209 additions and 452 deletions

View File

@@ -1,5 +1,5 @@
<h1> Refactoring the script and using fzf for UI. WIP </h1> ### This script is refactored and now using fzf (make sure it is installed as script now checks for it) for showing menus, if you don't like fzf then you can continue to use old one. I would suggest to try fzf based one.
<p align=center> <p align=center>
<br> <br>
@@ -50,18 +50,14 @@ Install termux [(Guide)](https://termux.com/)
```sh ```sh
pkg update pkg update
pkg install git termux-tools ncurses-utils openssl-tool ffmpeg -y pkg install git termux-tools ncurses-utils openssl-tool ffmpeg fzf aria2 -y
git clone https://github.com/CoolnsX/dra-cla && cd dra-cla git clone https://github.com/CoolnsX/dra-cla && cd dra-cla
cp dra-cla $PREFIX/bin/dra-cla cp dra-cla $PREFIX/bin/dra-cla
echo 'am start -n is.xyz.mpv/.MPVActivity "$1"' > $PREFIX/bin/mpv
chmod +x $PREFIX/bin/mpv
``` ```
Install mpv-android [(Link)](https://play.google.com/store/apps/details?id=is.xyz.mpv) Install mpv-android [(Link)](https://play.google.com/store/apps/details?id=is.xyz.mpv)
*Add ```referrer="https://asianembed.io"``` to mpv.conf (Open mpv app, goto three dots top right->Settings->Advanced-->Edit mpv.conf)* For VLC: pass ``` dra-cla -v ```
*Note: VLC android doesn't support referrer option. So it will not work*
## Uninstall ## Uninstall
@@ -70,6 +66,7 @@ Install mpv-android [(Link)](https://play.google.com/store/apps/details?id=is.xy
## Dependencies ## Dependencies
- fzf (new)
- grep - grep
- sed - sed
- curl - curl

650
dra-cla
View File

@@ -1,152 +1,157 @@
#!/bin/sh #!/bin/sh
VERSION="2.2.2" #shellcheck disable=SC2154
####################### # most important variables.
# AUXILIARY FUNCTIONS # VERSION="3.0.0"
####################### CHANNEL="main"
base_url="https://pladrac.net"
logdir="${XDG_CACHE_HOME:-$HOME/.cache}"
logfile="$logdir/dra-hsts"
quality=best
scrape=query
agent="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/12$(head -5 /dev/urandom | tr -dc '0-2' | cut -c1).0.0.0 Safari/537.36"
trap 'rm -f '"$logfile"'.new' INT HUP
help_text () { ############
# help #
############
help_text() {
while IFS= read -r line; do while IFS= read -r line; do
printf "%s\n" "$line" printf "%s\n" "$line"
done <<-EOF done <<-EOF
Usage: Usage:
${0##*/} [-v] [-q <quality>] [-a <episode>] [-d | -p <download_dir>] [<query>] ${0##*/} [-v] [-q <quality>] [-a <episode>] [-d | -p <download_dir>] [<query>]
${0##*/} [-v] [-q <quality>] -c ${0##*/} [-v] [-q <quality>] -c
${0##*/} -h | -D | -U | -V ${0##*/} -h | -D | -U | -V
Options: Options:
-c continue watching drama from history -c continue watching drama from history
-a specify episode to watch -a specify episode to watch
-h show helptext -h show helptext
-d download episode -d download episode
-p download episode to specified directory -p download episode to specified directory
-q set video quality (best|worst|360|480|720|1080) -q set video quality (best|worst|360|480|720|1080)
-v use VLC as the media player -v use VLC as the media player
-D delete history -D delete Entire history
-U fetch update from github -U fetch update from github
-V print version number and exit -V print version number and exit
Episode selection: Episode selection:
Multiple episodes can be chosen given a range Multiple episodes can be chosen given a range
Choose episode [1-13]: 1 6 Choose episode [1-13]: 1 6
This would choose episodes 1 2 3 4 5 6 This would choose episodes 1 2 3 4 5 6
To select the last episode use -1
When selecting non-interactively, the first result will be When selecting non-interactively (eg: -a <ep_no>), the first result will be
selected, if drama is passed selected, if drama is passed as Args
EOF EOF
} }
version_text () { ############
inf "Version: $VERSION" >&2 # Update #
} ############
die () { update_script() {
err "$*" log "Checking For Updates.." >&2
exit 1 update="$(curl -A "$agent" -s "https://raw.githubusercontent.com/CoolnsX/dra-cla/$CHANNEL/dra-cla" | diff -u "$0" -)"
}
# get the newest version of this script from github and replace it
update_script () {
update="$(curl -s "https://raw.githubusercontent.com/CoolnsX/dra-cla/main/dra-cla" | diff -u "$0" -)"
if [ -z "$update" ]; then if [ -z "$update" ]; then
inf "Script is up to date :)" log "Script is up to date :)\n" "32" >&2
exit 0
fi
#dry run
if [ "$1" -eq 0 ]; then
log "Update Available!!\n" "32" >&2
log "To Update, type: ${sudo}${0##*/} -U" "33" >&2
exit 0
fi
#warning: this updates the codebase of script.
if printf '%s\n' "$update" | patch "$0" -; then
log "Script has been updated\n" "32" >&2
exit 0
else else
if printf '%s\n' "$update" | patch "$0" - ; then log "Can't update for some reason!\n" "31" >&2
inf "Script has been updated" exit 1
else
die "Can't update for some reason!"
fi
fi fi
} }
# checks if dependencies are present ############
dep_ch () { # UI #
for dep; do ############
if ! command -v "$dep" >/dev/null ; then
err "Program \"$dep\" not found. Please install it." log() {
#aria2c is in the package aria2 #shellcheck disable=SC2059
[ "$dep" = "aria2c" ] && err "To install aria2c, Type <your_package_manager> aria2" printf "\033[2K\r\033[1;${2:-36}m${1}\033[0m"
die }
fi
menu() {
fzf --prompt="$1 >> " --layout=reverse --border --height=20 -0 -1 -m
}
ask() {
log "$1" "33"
}
#############
# Logic #
#############
dep_ch() {
for dep in $(printf "%s" "$1" | tr ' ' '\n'); do
command -v "$dep" >/dev/null || {
log "Program $dep not found. Please install it\n" "31"
[ "$dep" = "aria2c" ] && log "To install $dep, Type <your_package_manager> aria2" "32"
exit 1
}
done done
} }
download () { download() {
case $2 in case "$1" in
*m3u8*) *m3u8*) ;;
ffmpeg -loglevel error -stats -referer "$1" -i "$2" -c copy "$download_dir/${3}${4}.mp4" ;; *) aria2c --enable-rpc=false --check-certificate=false --continue --summary-interval=0 -x16 -s16 "$1" --dir="$download_dir" -o "$2.mp4" --download-result=hide ;;
*) esac
aria2c --summary-interval=0 -x 16 -s 16 --referer="$1" "$2" --dir="$download_dir" -o "${3}${4}.mp4" --download-result=hide ;;
esac
} }
############# open_episode() {
# SEARCHING #
#############
# gets drama names along with its id for search term
search_drama () {
search=$(printf '%s' "$1" | tr ' ' '-' )
curl -s "$base_url/search.html?keyword=$search" |
sed -nE 's_^[[:space:]]*<a href="/videos/([^"]*)">_\1_p'
}
check_episode () {
curl -s "$base_url/videos/$1" | sed '/Latest Episodes/,$d' | sed -nE "s_^[[:space:]]*<a href.*videos/${2}(.*)\">_\1_p"
}
process_hist_entry () {
temp_drama_id=$(printf "%s" "$drama_id" | sed 's/[0-9]*.$//')
latest_ep=$(printf "%s" "$drama_id" | sed "s/$temp_drama_id//g")
current_ep=$(check_episode "$drama_id" "$temp_drama_id" | head -n 1)
if [ -n "$current_ep" ] && [ "$current_ep" -ge "$latest_ep" ]; then
printf "%s\n" "$drama_id"
fi
}
# compares history with asianembed, only shows unfinished drama
search_history () {
tput clear tput clear
[ ! -s "$logfile" ] && die "History is empty" log "Fetching $title Episode $episode.."
search_results=$(while read -r drama_id; do process_hist_entry & done < "$logfile"; wait) [ -z "$dpage_link" ] && dpage_link=$(curl -s -A "$agent" "$base_url/videos/${id}${episode}" | sed -nE 's_^[[:space:]]*<iframe src="([^"]*)".*_https:\1_p')
[ -z "$search_results" ] && die "No unwatched episodes" get_video_url
one_hist=$(printf '%s\n' "$search_results" | grep -e "$" -c) if grep -q "$id" "$logfile"; then
[ "$one_hist" = 1 ] && select_first=1 sed -E "s/^${id}.*/${id}$((episode + 1))/" "$logfile" >"${logfile}.new"
drama_selection "$search_results" else
ep_choice_start=$(sed -n -E "s/${selection_id}(.*)/\1/p" "$logfile") printf "%s%s\n" "$id" "$((episode + 1))" >>"$logfile"
} fi
[ -z "$video_link" ] && log "Video URL not found" "31"
[ "$player_function" = "download" ] && display="Downloading $title Episode $episode/$total_eps on $player_function\n" || display="Streaming $title Episode $episode/$total_eps\n"
log "$display" "32"
[ -z "$nohup" ] && ! printf "%s" "$player_function" | grep -q "android" && log "To play next Episode, quit the player."
################## #media Player
# URL PROCESSING # case "$player_function" in
################## mpv*) $nohup $player_function --force-media-title="${title} Episode ${episode}" "$video_link" >/dev/null 2>&1 ;;
android_mpv) am start --user 0 -a android.intent.action.VIEW -d "$video_link" -n is.xyz.mpv/.MPVActivity >/dev/null 2>&1 ;;
vlc*) $nohup $player_function --play-and-exit --meta-title="${title} Episode ${episode}" "$video_link" >/dev/null 2>&1 ;;
android_vlc) am start --user 0 -a android.intent.action.VIEW -d "$video_link" -n org.videolan.vlc/org.videolan.vlc.gui.video.VideoPlayerActivity -e "title" "${title} Episode ${episode}" >/dev/null 2>&1 ;;
download) "$player_function" "$video_link" "${title} Episode ${episode}" ;;
esac
# get the download page url dpage_link=""
get_dpage_link() { [ -f "$logfile.new" ] && mv "${logfile}.new" "$logfile"
drama_id="$1"
ep_no="$2"
curl -s "$base_url/videos/${drama_id}${ep_no}" | sed -nE 's_^[[:space:]]*<iframe src="([^"]*)".*_\1_p' |
sed 's/^/https:/g'
} }
decrypt_link() { decrypt_link() {
fembed_id=$(curl -A "uwu" -s "$1" | sed -nE 's_.*fembed.*/v/([^#]*).*_\1_p')
[ -z "$fembed_id" ] || video_links=$(curl -A "uwu" -s -X POST "https://fembed9hd.com/api/source/$fembed_id" -H "x-requested-with:XMLHttpRequest" | sed -e 's/\\//g' -e 's/.*data"://' | tr "}" "\n" | sed -nE 's/.*file":"(.*)","label":"([^"]*)".*/\2>\1/p')
[ -z "$video_links" ] || return 0
secret_key='3933343232313932343333393532343839373532333432393038353835373532' secret_key='3933343232313932343333393532343839373532333432393038353835373532'
iv='39323632383539323332343335383235' iv='39323632383539323332343335383235'
ajax_url="$base_url/encrypt-ajax.php" ajax_url="$base_url/encrypt-ajax.php"
ajax=$(printf "%s" "$1" | sed -nE 's/.*id=([^&]*)&.*/\1/p' | openssl enc -e -aes256 -K "$secret_key" -iv "$iv" -a) ajax=$(printf "%s" "$1" | sed -nE 's/.*id=([^&]*)&.*/\1/p' | openssl enc -e -aes256 -K "$secret_key" -iv "$iv" -a)
video_links=$(curl -s -H "X-Requested-With:XMLHttpRequest" "$ajax_url" -d "id=$ajax" | sed -e 's/{"data":"//' -e 's/"}/\n/' -e 's/\\//g' | base64 -d | openssl enc -d -aes256 -K "$secret_key" -iv "$iv" | sed -e 's/\].*/\]/' -e 's/\\//g' | tr '{|}' '\n' | sed -nE 's/\"file\":"([^"]*)".*label.*P.*/\1/p') video_links=$(curl -A "$agent" -s -H "X-Requested-With:XMLHttpRequest" "$ajax_url" -d "id=$ajax" | sed -e 's/{"data":"//' -e 's/"}/\n/' -e 's/\\//g' | base64 -d | openssl enc -d -aes256 -K "$secret_key" -iv "$iv" | sed -e 's/\].*/\]/' -e 's/\\//g' | tr '{|}' '\n' | sed -nE 's/\"file\":"([^"]*)".*label.*P.*/\1/p')
} }
# chooses the link for the set quality get_video_url() {
get_video_quality() { decrypt_link "$dpage_link"
dpage_url="$1"
decrypt_link "$dpage_url"
case $quality in case $quality in
best) best)
video_link=$(printf '%s' "$video_links" | head -n 4 | tail -n 1 | cut -d'>' -f2) video_link=$(printf '%s' "$video_links" | head -n 4 | tail -n 1 | cut -d'>' -f2)
@@ -157,275 +162,51 @@ get_video_quality() {
*) *)
video_link=$(printf '%s' "$video_links" | grep -i "${quality}p" | head -n 1 | cut -d'>' -f2) video_link=$(printf '%s' "$video_links" | grep -i "${quality}p" | head -n 1 | cut -d'>' -f2)
if [ -z "$video_link" ]; then if [ -z "$video_link" ]; then
err "Current video quality is not available (defaulting to best quality)" log "Current video quality is not available (defaulting to best quality)\n" "31"
quality=best quality=best
video_link=$(printf '%s' "$video_links" | head -n 4 | tail -n 1 | cut -d'>' -f2) video_link=$(printf '%s' "$video_links" | head -n 4 | tail -n 1 | cut -d'>' -f2)
fi fi
;; ;;
esac esac
printf '%s' "$video_link"
}
###############
# TEXT OUTPUT #
###############
# display an error message to stderr (in red)
err () {
printf "\033[1;31m%s\033[0m\n" "$*" >&2
}
# display an informational message (first argument in green, second in magenta)
inf () {
printf "\033[1;35m%s \033[1;35m%s\033[0m\n" "$1" "$2"
}
# prompts the user with message in $1-2 ($1 in blue, $2 in magenta) and saves the input to the variables in $REPLY and $REPLY2
prompt () {
printf "\033[1;35m%s\033[1;35m%s\033[1;34m\033[0m" "$1" "$2"
read -r REPLY REPLY2
}
# displays an even (cyan) line of a menu line with $2 as an indicator in () and $1 as the option
menu_line_even () {
printf "\033[1;36m(\033[1;36m%s\033[1;36m) \033[1;36m%s\033[0m\n" "$2" "$1"
}
# displays an odd (yellow) line of a menu line with $2 as an indicator in () and $1 as the option
menu_line_odd() {
printf "\033[1;33m(\033[1;33m%s\033[1;33m) \033[1;33m%s\033[0m\n" "$2" "$1"
}
# display alternating menu lines (even and odd)
menu_line_alternate() {
menu_line_parity=${menu_line_parity:-0}
if [ "$menu_line_parity" -eq 0 ]; then
menu_line_odd "$1" "$2"
menu_line_parity=1
else
menu_line_even "$1" "$2"
menu_line_parity=0
fi
}
# displays a warning (red) line of a menu line with $2 as an indicator in [] and $1 as the option
menu_line_strong() {
printf "\033[1;31m(\033[1;31m%s\033[1;31m) \033[1;31m%s\033[0m\n" "$2" "$1"
}
#################
# INPUT PARSING #
#################
# only lets the user pass in case of a valid search
process_search () {
search_results=$(search_drama "$query")
while [ -z "$search_results" ]; do
err 'No search results found'
prompt 'Search Drama: '
query="$REPLY $REPLY2"
search_results=$(search_drama "$query")
done
drama_selection "$search_results"
episode_selection
}
# drama-selection menu handling function
drama_selection () {
count=1
while read -r drama_id; do
menu_line_alternate "$drama_id" "$count"
: $((count+=1))
done <<-EOF
$search_results
EOF
if [ -n "$select_first" ]; then
tput clear
choice=1
elif [ -z "$ep_choice_to_start" ] || { [ -n "$ep_choice_to_start" ] && [ -z "$select_first" ]; }; then
menu_line_strong "exit" "q"
prompt "> "
choice="$REPLY"
while ! [ "$choice" -eq "$choice" ] 2>/dev/null || [ "$choice" -lt 1 ] || [ "$choice" -ge "$count" ] || [ "$choice" = " " ]; do
[ "$choice" = "q" ] && exit 0
err "Invalid choice entered"
prompt "> "
choice="$REPLY"
done
fi
# Select respective drama_id
selection_id="$(printf "%s" "$search_results" | sed -n "${choice}p")"
temp_drama_id=$(printf "%s" "$selection_id" | sed 's/[0-9]*.$//')
select_ep_result=$(check_episode "$selection_id" "$temp_drama_id")
last_ep_number=$(printf "%s" "$select_ep_result" | head -n 1)
first_ep_number=$(printf "%s" "$select_ep_result" | tail -n 1)
selection_id=$temp_drama_id
}
# gets episode number from user, makes sure it's in range, skips input if only one episode exists
episode_selection () {
if [ "$last_ep_number" -gt "$first_ep_number" ]; then
if [ -z "$ep_choice_to_start" ]; then
# if branches, because order matters this time
while : ; do
inf "To specify a range, use: start_number end_number"
inf "Episodes:" "($first_ep_number-$last_ep_number)"
prompt "> "
ep_choice_start="$REPLY"
ep_choice_end="$REPLY2"
if [ "$REPLY" = q ]; then
exit 0
fi
[ "$ep_choice_end" = "-1" ] && ep_choice_end="$last_ep_number"
if ! [ "$ep_choice_start" -eq "$ep_choice_start" ] 2>/dev/null || { [ -n "$ep_choice_end" ] && ! [ "$ep_choice_end" -eq "$ep_choice_end" ] 2>/dev/null; }; then
err "Invalid number(s)"
continue
fi
if [ "$ep_choice_start" -gt "$last_ep_number" ] 2>/dev/null || [ "$ep_choice_end" -gt "$last_ep_number" ] 2>/dev/null || [ "$ep_choice_start" -lt "$first_ep_number" ] 2>/dev/null; then
err "Episode out of range"
continue
fi
if [ "$ep_choice_end" -le "$ep_choice_start" ]; then
err "Invalid range"
continue
fi
break
done
else
ep_choice_start="$ep_choice_to_start" && unset ep_choice_to_start
fi
else
# In case the drama contains only a single episode
ep_choice_start=1
fi
if [ -z "$ep_choice_end" ]; then
auto_play=0
else
auto_play=1
fi
}
# creates $episodes from $ep_choice_start and $ep_choice_end
generate_ep_list() {
episodes=$ep_choice_start
[ -n "$ep_choice_end" ] && episodes=$(seq "$ep_choice_start" "$ep_choice_end")
}
##################
# VIDEO PLAYBACK #
##################
append_history () { # todo: unite this with the temporary histfile writing
grep -q "${selection_id}" "$logfile" || printf "%s%s\n" "$selection_id" $((episode+1)) >> "$logfile"
}
# opens selected episodes one-by-one
open_selection() {
for ep in $episodes; do
open_episode "$selection_id" "$ep"
done
episode=${ep_choice_end:-$ep_choice_start}
}
open_episode () {
drama_id="$1"
episode="$2"
tput clear
inf "Loading episode $episode..."
# decrypting url
dpage_link=$(get_dpage_link "$drama_id" "$episode")
echo "$dpage_link"
video_url=$(get_video_quality "$dpage_link")
echo "$video_url"
if [ "$is_download" -eq 0 ]; then
# write drama and episode number and save to temporary history
sed -E "
s/^${selection_id}[0-9]*/${selection_id}$((episode+1))/
" "$logfile" > "${logfile}.new"
[ ! "$PID" = "0" ] && kill "$PID" >/dev/null 2>&1
[ -z "$video_url" ] && die "Video URL not found"
play_episode
# overwrite history with temporary history
mv "${logfile}.new" "$logfile"
else
mkdir -p "$download_dir"
inf "Downloading episode $episode ..."
episode=$(printf "%03d" "$episode")
{
if download "$dpage_link" "$video_url" "$drama_id" "$episode" ; then
inf "Downloaded episode: $episode"
else
err "Download failed episode: $episode , please retry or check your internet connection"
fi
}
fi
}
play_episode () {
# Build command
set -- "$player_fn" "$video_url"
case "$player_fn" in
vlc)
[ ! "$auto_play" -eq 0 ] && set -- "$@" "--play-and-exit"
set -- "$@" --http-referrer="$dpage_link"
;;
*)
set -- "$@" --referrer="$dpage_link" --force-media-title="${drama_id}${episode}"
;;
esac
# Run Command
if [ "$auto_play" -eq 0 ]; then
nohup "$@" > /dev/null 2>&1 &
else
inf "Currently playing $display_name episode" "$episode/$last_ep_number, Range: $ep_choice_start-$ep_choice_end"
"$@" > /dev/null 2>&1
sleep 2
fi
PID=$!
} }
############ ############
# START UP # # Main #
############ ############
# clears the colors and deletes temporary logfile when exited using SIGINT #create history file
trap 'printf "\033[0m";[ -f "$logfile".new ] && rm "$logfile".new;exit 1' INT HUP
# default options
player_fn="mpv" #video player needs to be able to play urls
is_download=0
PID=0
quality=best
scrape=query
download_dir="."
choice=
auto_play=0
# history file path
logfile="${XDG_CACHE_HOME:-$HOME/.cache}/dra-hsts"
logdir="${XDG_CACHE_HOME:-$HOME/.cache}"
# create history file and history dir if none found
[ -d "$logdir" ] || mkdir "$logdir" [ -d "$logdir" ] || mkdir "$logdir"
[ -f "$logfile" ] || : > "$logfile" [ -f "$logfile" ] || : >"$logfile"
# OS detection for player selection and default download location.
case "$(uname -o)" in
*ndroid*)
player_function="android_mpv"
download_dir="/sdcard"
alt_player="android_vlc"
;;
*)
player_function="mpv"
download_dir="."
alt_player="vlc"
command -v "doas" >/dev/null && sudo="doas " || sudo="sudo "
;;
esac
while getopts 'vq:dp:chDUVa:' OPT; do while getopts 'vq:dp:chDUVa:' OPT; do
case $OPT in case $OPT in
d) d)
is_download=1 player_function="download"
;; ;;
a) a)
ep_choice_to_start=$OPTARG ep_start=$OPTARG
;; ;;
D) D)
: > "$logfile" : >"$logfile"
exit 0 exit 0
;; ;;
p) p)
is_download=1 player_function="download"
download_dir=$OPTARG download_dir=$OPTARG
;; ;;
q) q)
@@ -435,15 +216,15 @@ while getopts 'vq:dp:chDUVa:' OPT; do
scrape=history scrape=history
;; ;;
v) v)
player_fn="vlc" player_function=$alt_player
;; ;;
U) U)
update_script update_script 1
exit 0
;; ;;
V) V)
version_text log "Version: $VERSION\n" >&2
exit 0 log "Channel: $CHANNEL\n" >&2
update_script 0
;; ;;
*) *)
help_text help_text
@@ -453,92 +234,71 @@ while getopts 'vq:dp:chDUVa:' OPT; do
done done
shift $((OPTIND - 1)) shift $((OPTIND - 1))
dep_ch "curl" "sed" "grep" "openssl" #dependency checking
if [ "$is_download" -eq 0 ]; then log "Checking Dependencies.."
dep_ch "$player_fn" dep_ch "curl sed grep openssl fzf"
else if [ "$player_function" = "download" ]; then
dep_ch "aria2c" "ffmpeg" dep_ch "aria2c ffmpeg"
elif ! printf "%s" "$player_function" | grep -q "android";then
dep_ch "$player_function"
fi fi
# Get the current working URL if [ "$scrape" = "query" ]; then
base_url=$(curl -Ls -o /dev/null -w %{url_effective} https://asianembed.io) [ -z "$*" ] && ask "Search Drama: " && read -r query || query=$*
log "Searching Drama.."
response=$(curl -A "$agent" -s "$base_url/search.html" -G --data-urlencode "keyword=$query" | sed -nE 's_^[[:space:]]*<a href="/videos/([^"]*)-episode-([0-9]*)">_\1 (\2 Episodes)_p')
[ -z "$response" ] && log "No Results Found" "31" && exit 0
log ""
id=$(printf "%s" "$response" | tr '-' ' ' | menu "Select Drama")
[ -z "$id" ] && log "No Drama Selected" "31" && exit 0
# sets $title and $total_eps variable
eval "$(printf %s "$id" | tr -s ' ' | sed -nE 's|(.*) \(([0-9]*) Episodes\)$|title="\1";total_eps="\2"|p')"
id=$(printf "%s" "$id" | sed 's| ([0-9]* Episodes)|-episode-|g' | tr ' ' '-')
case $scrape in else
query) log ""
if [ -z "$*" ]; then [ ! -s "$logfile" ] && log "History is empty" "31" && exit 0
prompt "Search Drama: " id=$(tr '-' ' ' <"$logfile" | menu "Continue" | tr ' ' '-')
query="$REPLY $REPLY2" [ -z "$id" ] && log "No Drama Selected" "31" && exit 0
else ep_start=$(printf "%s" "$id" | sed -nE 's|.*-episode-([0-9]*)|\1|p')
if [ -n "$ep_choice_to_start" ]; then log "Checking Episode $ep_start"
REPLY=1 response=$(curl -s "$base_url/videos/$id" -A "$agent" | sed '/Latest Episodes/,$d' | sed -nE 's_^[[:space:]]*<a href.*/videos/.*-episode-([0-9]*)">.*_\1_p;s_^[[:space:]]*<iframe src="([^"]*)".*_https:\1_p')
select_first=1 [ -z "$response" ] && log "Episode Not Released" "31" && exit 0
fi id=$(printf "%s" "$id" | sed 's|-episode-.*|-episode-|g')
query="$*" total_eps=$(printf "%s" "$response" | sed -n '2p')
fi title=$(printf "%s" "$id" | sed 's|-episode-.*||g' | tr '-' ' ' | tr -s ' ')
process_search dpage_link=$(printf "%s" "$response" | head -1)
;; fi
history)
search_history
[ "$REPLY" = "q" ] && exit 0
first_ep_number=$(check_episode "${selection_id}1" "$selection_id" | tail -1)
;;
*)
die "Unexpected scrape type"
esac
generate_ep_list #shows prompt if select episode is not specified via args
append_history if [ -z "$ep_start" ]; then
open_selection log "Selected: $title\n" "32"
printf "%s" "$player_function" | grep -q "android" && display="Range is broken for android." || display="To specify a range, use: start_number end_number"
log "$display\n"
ask "Episodes [1-$total_eps]: "
read -r ep_start ep_end
fi
######## [ -z "$ep_start" ] && log "No Episode Selected" "31" && exit 1
# LOOP # if [ -n "$ep_end" ]; then
######## for episode in $(seq "$ep_start" "$ep_end"); do
open_episode
done
else
nohup="setsid -f"
episode="${ep_start}"
open_episode
fi
episode="${ep_end:-$ep_start}"
while :; do while cmd=$(printf "next\nreplay\nprevious\nselect\nchange_quality\nquit" | menu "Select Option"); do
if [ -z "$select_first" ]; then case "$cmd" in
if [ "$auto_play" -eq 0 ]; then next) [ "$episode" -lt "$total_eps" ] && : $((episode+=1)) || flag=1 ;;
display_name=$(printf '%s' "$selection_id" | sed 's/-episode-//') replay) ;;
inf "Currently playing $display_name episode" "$episode/$last_ep_number" previous) [ "$episode" -gt 1 ] && : $((episode-=1)) || flag=1 ;;
else select) ask "Episodes [1-$total_eps]: " && read -r episode ;;
auto_play=0 *) exit 0 ;;
fi
[ "$episode" -ne "$last_ep_number" ] && menu_line_alternate 'next' 'n'
[ "$episode" -ne "$first_ep_number" ] && menu_line_alternate 'previous' 'p'
menu_line_alternate "replay" "r"
[ "$last_ep_number" -ne "$first_ep_number" ] && menu_line_alternate 'select' 's'
menu_line_strong "exit" "q"
prompt "> "
choice="$REPLY"
case $choice in
n)
ep_choice_start=$((episode + 1))
unset ep_choice_end
;;
p)
ep_choice_start=$((episode - 1))
unset ep_choice_end
;;
r)
ep_choice_start="$episode"
unset ep_choice_end
;;
s)
episode_selection
;;
q)
break
;;
*)
tput clear
err "Invalid choice"
continue
;;
esac esac
generate_ep_list [ -n "$flag" ] && log "Out of Range" "31" && flag="" && continue
append_history open_episode
open_selection
else
wait $!
exit
fi
done done