chore: optimizations, version bump

This commit is contained in:
CoolnsX
2022-04-05 06:24:21 +05:30
parent c0b35bba31
commit 91a014e9ea
2 changed files with 123 additions and 203 deletions

View File

@@ -11,7 +11,7 @@
</p> </p>
A cli to browse and watch Korean Drama, Chinese drama. This tool scrapes the site [dramacool](https://dramacool.fo). A cli to browse and watch Korean Drama, Chinese drama. This tool scrapes the site [asianembed](https://asianembed.io) which is the site dramacool scrapes from.
This tool is modified version of [ani-cli](https://github.com/pystardust/ani-cli) which is anime scraping tool. Feel free to check it out if you need to watch anime. This tool is modified version of [ani-cli](https://github.com/pystardust/ani-cli) which is anime scraping tool. Feel free to check it out if you need to watch anime.
@@ -41,7 +41,8 @@ sudo cp dra-cla /usr/local/bin/dra-cla
Install termux [(Guide)](https://termux.com/) Install termux [(Guide)](https://termux.com/)
```sh ```sh
pkg install git termux-tools ncurses-utils openssl-tool -y pkg update
pkg install git termux-tools ncurses-utils openssl-tool ffmpeg -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 "$2"' > $PREFIX/bin/mpv echo 'am start -n is.xyz.mpv/.MPVActivity "$2"' > $PREFIX/bin/mpv
@@ -67,3 +68,4 @@ Install mpv-android [(Link)](https://play.google.com/store/apps/details?id=is.xy
- openssl - openssl
- mpv - Video Player - mpv - Video Player
- aria2 - Download manager - aria2 - Download manager
- ffmpeg - m3u8 Downloader

320
dra-cla
View File

@@ -1,25 +1,6 @@
#!/bin/sh #!/bin/sh
# dra-cla VERSION="2.1.0"
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Project repository: https://github.com/CoolnsX/dra-cla
# Version number
VERSION="2.0.0"
####################### #######################
# AUXILIARY FUNCTIONS # # AUXILIARY FUNCTIONS #
@@ -48,7 +29,6 @@ help_text () {
-V print version number and exit -V print version number and exit
Episode selection: Episode selection:
Add 'h' on beginning for episodes like '6.5' -> 'h6'
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
@@ -94,6 +74,14 @@ dep_ch () {
done done
} }
download () {
case $2 in
*mp4*)
aria2c --summary-interval=0 -x 16 -s 16 --referer="$1" "$2" --dir="$download_dir" -o "${3}${4}.mp4" --download-result=hide ;;
*)
ffmpeg -loglevel error -stats -referer "$1" -i "$2" -c copy "$download_dir/${3}${4}.mp4" ;;
esac
}
############# #############
# SEARCHING # # SEARCHING #
@@ -107,27 +95,27 @@ search_drama () {
} }
check_episode () { check_episode () {
tmp=$(printf "%s" "$1" | sed 's/[0-9]*.$//') data=$(curl -s "$base_url/videos/$1")
curl -s "$base_url/videos/$1" | sed -nE "s_^[[:space:]]*<a href.*videos/${tmp}(.*)\">_\1_p" | head -n 1 if [ "$data" != "404" ]; then
del=$(printf "%s" "$data" | grep -n "Latest Episodes" | cut -d ":" -f1)
printf "%s" "$data" | sed "$del,$ d" | sed -nE "s_^[[:space:]]*<a href.*videos/${2}(.*)\">_\1_p"
fi
} }
search_for_unwatched () { # todo: merge into search_history process_hist_entry () {
search_results="$*" temp_drama_id=$(printf "%s" "$drama_id" | sed 's/[0-9]*.$//')
while read -r drama_id; do latest_ep=$(printf "%s" "$drama_id" | sed "s/$temp_drama_id//g")
current_ep_number=$(check_episode "$drama_id") current_ep=$(check_episode "$drama_id" "$temp_drama_id" | head -n 1)
history_ep_number=$(printf "%s" "$drama_id" | grep -Po '\K\d+' | tail -n 1) if [ -n "$current_ep" ] && [ "$current_ep" -ge "$latest_ep" ]; then
[ -n "$current_ep_number" ] && [ "$current_ep_number" -ge "$history_ep_number" ] && printf '%s\n' "$drama_id" printf "%s\n" "$drama_id"
done <<-EOF fi
$search_results
EOF
} }
# compares history with gogoplay, only shows unfinished drama # compares history with asianembed, only shows unfinished drama
search_history () { search_history () {
tput clear tput clear
search_results=$(cat "$logfile") [ ! -s "$logfile" ] && die "History is empty"
[ -z "$search_results" ] && die "History is empty" search_results=$(while read -r drama_id; do process_hist_entry & done < "$logfile"; wait)
search_results=$(search_for_unwatched "$search_results")
[ -z "$search_results" ] && die "No unwatched episodes" [ -z "$search_results" ] && die "No unwatched episodes"
one_hist=$(printf '%s\n' "$search_results" | grep -e "$" -c) one_hist=$(printf '%s\n' "$search_results" | grep -e "$" -c)
[ "$one_hist" = 1 ] && select_first=1 [ "$one_hist" = 1 ] && select_first=1
@@ -146,22 +134,15 @@ get_dpage_link() {
curl -s "$base_url/videos/${drama_id}${ep_no}" | sed -nE 's_^[[:space:]]*<iframe src="([^"]*)".*_\1_p' | curl -s "$base_url/videos/${drama_id}${ep_no}" | sed -nE 's_^[[:space:]]*<iframe src="([^"]*)".*_\1_p' |
sed 's/^/https:/g' sed 's/^/https:/g'
} }
decrypt_link() { decrypt_link() {
secret_key='3933343232313932343333393532343839373532333432393038353835373532' secret_key='3933343232313932343333393532343839373532333432393038353835373532'
iv='39323632383539323332343335383235' iv='39323632383539323332343335383235'
ajax_url="$base_url/encrypt-ajax.php" ajax_url="$base_url/encrypt-ajax.php"
id=$(printf "%s" "$1" | sed -nE 's/.*id=(.*)&title.*/\1/p') ajax=$(printf "%s" "$1" | sed -nE 's/.*id=(.*)&title.*/\1/p' | openssl enc -e -aes256 -K "$secret_key" -iv "$iv" | base64)
# encrypt new_id using iv and secret_key
ajax=$(printf "%s\010\016\003\010\t\003\004\t" "$id" | openssl enc -aes256 -K "$secret_key" -iv "$iv" -a)
#send request and get the data(most lamest way)
data=$(curl -s -H "X-Requested-With:XMLHttpRequest" "$ajax_url" -d "id=$ajax" | sed -e 's/{"data":"//' -e 's/"}/\n/' -e 's/\\//g') data=$(curl -s -H "X-Requested-With:XMLHttpRequest" "$ajax_url" -d "id=$ajax" | sed -e 's/{"data":"//' -e 's/"}/\n/' -e 's/\\//g')
#decrypt the data to get final links printf '%s' "$data" | 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'
printf '%s' "$data" | base64 -d | openssl enc -d -aes256 -K "$secret_key" -iv "$iv" | sed -e 's/\].*/\]/' -e 's/\\//g' |
grep -Eo 'https:\/\/[-a-zA-Z0-9@:%._\+~#=][a-zA-Z0-9][-a-zA-Z0-9@:%_\+.~#?&\/\/=]*'
} }
# chooses the link for the set quality # chooses the link for the set quality
@@ -199,23 +180,23 @@ err () {
# display an informational message (first argument in green, second in magenta) # display an informational message (first argument in green, second in magenta)
inf () { inf () {
printf "\033[1;32m%s \033[1;35m%s\033[0m\n" "$1" "$2" 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 # 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 () { prompt () {
printf "\033[1;34m%s\033[1;35m%s\033[1;34m: \033[0m" "$1" "$2" printf "\033[1;35m%s\033[1;35m%s\033[1;34m\033[0m" "$1" "$2"
read -r REPLY REPLY2 read -r REPLY REPLY2
} }
# displays an even (cyan) line of a menu line with $2 as an indicator in [] and $1 as the option # displays an even (cyan) line of a menu line with $2 as an indicator in () and $1 as the option
menu_line_even () { menu_line_even () {
printf "\033[1;34m[\033[1;36m%s\033[1;34m] \033[1;36m%s\033[0m\n" "$2" "$1" 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 # displays an odd (yellow) line of a menu line with $2 as an indicator in () and $1 as the option
menu_line_odd() { menu_line_odd() {
printf "\033[1;34m[\033[1;33m%s\033[1;34m] \033[1;33m%s\033[0m\n" "$2" "$1" 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) # display alternating menu lines (even and odd)
@@ -232,7 +213,7 @@ menu_line_alternate() {
# displays a warning (red) line of a menu line with $2 as an indicator in [] and $1 as the option # displays a warning (red) line of a menu line with $2 as an indicator in [] and $1 as the option
menu_line_strong() { menu_line_strong() {
printf "\033[1;34m[\033[1;31m%s\033[1;34m] \033[1;31m%s\033[0m\n" "$2" "$1" printf "\033[1;31m(\033[1;31m%s\033[1;31m) \033[1;31m%s\033[0m\n" "$2" "$1"
} }
@@ -240,16 +221,12 @@ menu_line_strong() {
# INPUT PARSING # # INPUT PARSING #
################# #################
is_number () { # todo make this better, or make this inline
[ "$1" -eq "$1" ] 2>/dev/null || die 'Invalid number entered'
}
# only lets the user pass in case of a valid search # only lets the user pass in case of a valid search
process_search () { process_search () {
search_results=$(search_drama "$query") search_results=$(search_drama "$query")
while [ -z "$search_results" ]; do while [ -z "$search_results" ]; do
err 'No search results found' err 'No search results found'
prompt 'Search Drama' prompt 'Search Drama: '
query="$REPLY $REPLY2" query="$REPLY $REPLY2"
search_results=$(search_drama "$query") search_results=$(search_drama "$query")
done done
@@ -271,69 +248,56 @@ drama_selection () {
choice=1 choice=1
elif [ -z "$ep_choice_to_start" ] || { [ -n "$ep_choice_to_start" ] && [ -z "$select_first" ]; }; then elif [ -z "$ep_choice_to_start" ] || { [ -n "$ep_choice_to_start" ] && [ -z "$select_first" ]; }; then
menu_line_strong "exit" "q" menu_line_strong "exit" "q"
prompt "Enter choice" prompt "> "
choice="$REPLY" choice="$REPLY"
while ! [ "$choice" -eq "$choice" ] 2>/dev/null || [ "$choice" -lt 1 ] || [ "$choice" -ge "$count" ] || [ "$choice" = " " ]; do while ! [ "$choice" -eq "$choice" ] 2>/dev/null || [ "$choice" -lt 1 ] || [ "$choice" -ge "$count" ] || [ "$choice" = " " ]; do
[ "$choice" = "q" ] && exit 0 [ "$choice" = "q" ] && exit 0
err "Invalid choice entered" err "Invalid choice entered"
prompt "Enter choice" prompt "> "
choice="$REPLY" choice="$REPLY"
done done
fi fi
# Select respective drama_id # Select respective drama_id
count=1 selection_id="$(printf "%s" "$search_results" | sed -n "${choice}p")"
while read -r drama_id; do temp_drama_id=$(printf "%s" "$selection_id" | sed 's/[0-9]*.$//')
if [ "$count" -eq "$choice" ]; then select_ep_result=$(check_episode "$selection_id" "$temp_drama_id")
selection_id="$drama_id" last_ep_number=$(printf "%s" "$select_ep_result" | head -n 1)
break first_ep_number=$(printf "%s" "$select_ep_result" | tail -n 1)
fi selection_id=$temp_drama_id
count=$((count+1))
done <<-EOF
$search_results
EOF
case $scrape in
query)
select_ep_result=$(printf "%s" "$selection_id" | grep -Po '\K\d+' | tail -1);;
history)
select_ep_result=$(check_episode "$selection_id");;
*)
die "Unexpected scrape type";;
esac
read -r last_ep_number <<-EOF
$select_ep_result
EOF
selection_id=$(printf "%s" "$selection_id" | sed 's/[0-9]*.$//')
} }
# gets episode number from user, makes sure it's in range, skips input if only one episode exists # gets episode number from user, makes sure it's in range, skips input if only one episode exists
episode_selection () { episode_selection () {
# using get_dpage_link to get confirmation from episode 0 if it exists,else first_ep_number becomes "1"
first_ep_number=0
result=$(get_dpage_link "$selection_id" "$first_ep_number")
[ -z "$result" ] && first_ep_number=1
if [ "$last_ep_number" -gt "$first_ep_number" ]; then if [ "$last_ep_number" -gt "$first_ep_number" ]; then
inf "Range of episodes can be specified: start_number end_number"
if [ -z "$ep_choice_to_start" ]; then if [ -z "$ep_choice_to_start" ]; then
prompt "Choose episode" "[$first_ep_number-$last_ep_number]" # if branches, because order matters this time
ep_choice_start="$REPLY" while : ; do
ep_choice_end="$REPLY2" inf "To specify a range, use: start_number end_number"
while [ "$ep_choice_start" -lt "$first_ep_number" ] 2> /dev/null || [ "$ep_choice_end" -gt "$last_ep_number" ] 2> /dev/null || [ "$ep_choice_start" -gt "$last_ep_number" ] 2> /dev/null || [ -z "$ep_choice_start" ] 2> /dev/null; do inf "Episodes:" "($first_ep_number-$last_ep_number)"
if [ "$ep_choice_end" != -1 ]; then prompt "> "
err "Invalid number chosen" ep_choice_start="$REPLY"
prompt "Choose episode" "[$first_ep_number-$last_ep_number]" ep_choice_end="$REPLY2"
ep_choice_start="$REPLY" if [ "$REPLY" = q ]; then
ep_choice_end="$REPLY2" exit 0
fi 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 done
else else
ep_choice_start="$ep_choice_to_start" && unset ep_choice_to_start ep_choice_start="$ep_choice_to_start" && unset ep_choice_to_start
fi fi
whether_half="$(printf '%s' "$ep_choice_start" | cut -c1-1)"
if [ "$whether_half" = "h" ]; then
half_ep=1
ep_choice_start="$(printf '%s' "$ep_choice_start" | cut -c2-)"
fi
else else
# In case the drama contains only a single episode # In case the drama contains only a single episode
ep_choice_start=1 ep_choice_start=1
@@ -342,19 +306,13 @@ episode_selection () {
auto_play=0 auto_play=0
else else
auto_play=1 auto_play=1
[ "$ep_choice_end" = "-1" ] && ep_choice_end="$last_ep_number"
fi fi
} }
# checks if input is number, creates $episodes from $ep_choice_start and $ep_choice_end # creates $episodes from $ep_choice_start and $ep_choice_end
check_input() { generate_ep_list() {
is_number "$ep_choice_start"
episodes=$ep_choice_start episodes=$ep_choice_start
if [ -n "$ep_choice_end" ]; then [ -n "$ep_choice_end" ] && episodes=$(seq "$ep_choice_start" "$ep_choice_end")
is_number "$ep_choice_end"
# create list of episodes to download/watch
episodes=$(seq "$ep_choice_start" "$ep_choice_end")
fi
} }
@@ -374,64 +332,25 @@ open_selection() {
episode=${ep_choice_end:-$ep_choice_start} episode=${ep_choice_end:-$ep_choice_start}
} }
open_episode () { # todo move input checking open_episode () {
drama_id="$1" drama_id="$1"
episode="$2" episode="$2"
#tput clear tput clear
# checking if episode is in range inf "Loading episode $episode..."
while [ "$episode" -gt "$last_ep_number" ] || [ -z "$episode" ]; do
is_number "$ep_choice_start"
if [ "$last_ep_number" -eq 0 ]; then
die "Episodes not released yet!"
else
err "Episode out of range"
fi
prompt "Choose episode" "[$first_ep_number-$last_ep_number]"
episode="$REPLY $REPLY2"
done
if [ "$half_ep" -eq 1 ]; then
temp_ep="$episode"
episode="${episode}-5"
fi
inf "Getting data for episode $episode"
# decrypting url # decrypting url
dpage_link=$(get_dpage_link "$drama_id" "$episode") dpage_link=$(get_dpage_link "$drama_id" "$episode")
printf "%s\n" "$dpage_link" echo "$dpage_link"
video_url=$(get_video_quality "$dpage_link") video_url=$(get_video_quality "$dpage_link")
printf "%s\n" "$video_url" echo "$video_url"
if [ "$half_ep" -eq 1 ]; then
episode="$temp_ep"
half_ep=0
fi
if [ "$is_download" -eq 0 ]; then if [ "$is_download" -eq 0 ]; then
# write drama and episode number and save to temporary history # write drama and episode number and save to temporary history
sed -E " sed -E "
s/^${selection_id}[0-9]*/${selection_id}$((episode+1))/ s/^${selection_id}[0-9]*/${selection_id}$((episode+1))/
" "$logfile" > "${logfile}.new" " "$logfile" > "${logfile}.new"
[ "$PID" -ne 0 ] && kill "$PID" >/dev/null 2>&1 [ ! "$PID" = "0" ] && kill "$PID" >/dev/null 2>&1
[ -z "$video_url" ] && die "Video URL not found" [ -z "$video_url" ] && die "Video URL not found"
case "$player_fn" in play_episode
vlc)
if [ "$auto_play" -eq 0 ]; then
nohup "$player_fn" --http-referrer="$dpage_link" "$video_url" > /dev/null 2>&1 &
else
inf "Currently playing $selection_id episode" "$episode/$last_ep_number, Range: $ep_choice_start-$ep_choice_end"
"$player_fn" --play-and-exit --http-referrer="$dpage_link" "$video_url" > /dev/null 2>&1
sleep 2
fi
;;
*)
if [ "$auto_play" -eq 0 ]; then
nohup "$player_fn" --referrer="$dpage_link" "$video_url" --force-media-title="dra-cla: $drama_id ep $episode" > /dev/null 2>&1 &
else
inf "Currently playing $selection_id episode" "$episode/$last_ep_number, Range: $ep_choice_start-$ep_choice_end"
"$player_fn" --referrer="$dpage_link" "$video_url" --force-media-title="dra-cla: $drama_id ep $episode" > /dev/null 2>&1
sleep 2
fi
;;
esac
PID=$!
# overwrite history with temporary history # overwrite history with temporary history
mv "${logfile}.new" "$logfile" mv "${logfile}.new" "$logfile"
else else
@@ -439,7 +358,7 @@ open_episode () { # todo move input checking
inf "Downloading episode $episode ..." inf "Downloading episode $episode ..."
episode=$(printf "%03d" "$episode") episode=$(printf "%03d" "$episode")
{ {
if aria2c -x 16 -s 16 --referer="$dpage_link" "$video_url" --dir="$download_dir" -o "${drama_id}-${episode}.mp4" --download-result=hide ; then if download "$dpage_link" "$video_url" "$drama_id" "$episode" ; then
inf "Downloaded episode: $episode" inf "Downloaded episode: $episode"
else else
err "Download failed episode: $episode , please retry or check your internet connection" err "Download failed episode: $episode , please retry or check your internet connection"
@@ -448,6 +367,29 @@ open_episode () { # todo move input checking
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 # # START UP #
############ ############
@@ -458,7 +400,6 @@ trap 'printf "\033[0m";[ -f "$logfile".new ] && rm "$logfile".new;exit 1' INT HU
# default options # default options
player_fn="mpv" #video player needs to be able to play urls player_fn="mpv" #video player needs to be able to play urls
is_download=0 is_download=0
half_ep=0
PID=0 PID=0
quality=best quality=best
scrape=query scrape=query
@@ -475,13 +416,8 @@ logdir="${XDG_CACHE_HOME:-$HOME/.cache}"
while getopts 'vq:dp:chDUVa:' OPT; do while getopts 'vq:dp:chDUVa:' OPT; do
case $OPT in case $OPT in
h)
help_text
exit 0
;;
d) d)
is_download=1 is_download=1
select_first=1
;; ;;
a) a)
ep_choice_to_start=$OPTARG ep_choice_to_start=$OPTARG
@@ -493,7 +429,6 @@ while getopts 'vq:dp:chDUVa:' OPT; do
p) p)
is_download=1 is_download=1
download_dir=$OPTARG download_dir=$OPTARG
select_first=1
;; ;;
q) q)
quality=$OPTARG quality=$OPTARG
@@ -520,18 +455,18 @@ while getopts 'vq:dp:chDUVa:' OPT; do
done done
shift $((OPTIND - 1)) shift $((OPTIND - 1))
dep_ch "curl" "sed" "grep" "git" "openssl" dep_ch "curl" "sed" "grep" "openssl"
if [ "$is_download" -eq 0 ]; then if [ "$is_download" -eq 0 ]; then
dep_ch "$player_fn" dep_ch "$player_fn"
else else
dep_ch "aria2c" dep_ch "aria2c" "ffmpeg"
fi fi
base_url="https://asianembed.io" base_url="https://asianembed.io"
case $scrape in case $scrape in
query) query)
if [ -z "$*" ]; then if [ -z "$*" ]; then
prompt "Search Drama" prompt "Search Drama: "
query="$REPLY $REPLY2" query="$REPLY $REPLY2"
else else
if [ -n "$ep_choice_to_start" ]; then if [ -n "$ep_choice_to_start" ]; then
@@ -545,15 +480,13 @@ case $scrape in
history) history)
search_history search_history
[ "$REPLY" = "q" ] && exit 0 [ "$REPLY" = "q" ] && exit 0
first_ep_number=0 first_ep_number=$(check_episode "${selection_id}1" "$selection_id" | tail -1)
result=$(get_dpage_link "$selection_id" "$first_ep_number")
[ -z "$result" ] && first_ep_number=1
;; ;;
*) *)
die "Unexpected scrape type" die "Unexpected scrape type"
esac esac
check_input generate_ep_list
append_history append_history
open_selection open_selection
@@ -564,49 +497,34 @@ open_selection
while :; do while :; do
if [ -z "$select_first" ]; then if [ -z "$select_first" ]; then
if [ "$auto_play" -eq 0 ]; then if [ "$auto_play" -eq 0 ]; then
inf "Currently playing $selection_id episode" "$episode/$last_ep_number" display_name=$(printf '%s' "$selection_id" | sed 's/-episode-//')
inf "Currently playing $display_name episode" "$episode/$last_ep_number"
else else
auto_play=0 auto_play=0
fi fi
[ "$episode" -ne "$last_ep_number" ] && menu_line_alternate 'next episode' 'n' [ "$episode" -ne "$last_ep_number" ] && menu_line_alternate 'next' 'n'
[ "$episode" -ne "$first_ep_number" ] && menu_line_alternate 'previous episode' 'p' [ "$episode" -ne "$first_ep_number" ] && menu_line_alternate 'previous' 'p'
[ "$last_ep_number" -ne "$first_ep_number" ] && menu_line_alternate 'select episode' 's' menu_line_alternate "replay" "r"
menu_line_alternate "replay current episode" "r" [ "$last_ep_number" -ne "$first_ep_number" ] && menu_line_alternate 'select' 's'
menu_line_alternate "search for another drama" "a"
menu_line_alternate "search history" "h"
menu_line_alternate "select quality (current: $quality)" "b"
menu_line_strong "exit" "q" menu_line_strong "exit" "q"
prompt "Enter choice" prompt "> "
choice="$REPLY" choice="$REPLY"
case $choice in case $choice in
n) n)
ep_choice_start=$((episode + 1)) ep_choice_start=$((episode + 1))
ep_choice_end= unset ep_choice_end
;;
b)
prompt "Select quality. Options (best|worst|360|480|720|1080)"
quality="$REPLY"
;; ;;
p) p)
ep_choice_start=$((episode - 1)) ep_choice_start=$((episode - 1))
ep_choice_end= unset ep_choice_end
;;
r)
ep_choice_start="$episode"
unset ep_choice_end
;; ;;
s) s)
episode_selection episode_selection
;; ;;
r)
ep_choice_start=$((episode))
ep_choice_end=
;;
a)
tput clear
prompt "Search Drama"
query="$REPLY $REPLY2"
process_search
;;
h)
search_history
;;
q) q)
break break
;; ;;
@@ -616,7 +534,7 @@ if [ -z "$select_first" ]; then
continue continue
;; ;;
esac esac
check_input generate_ep_list
append_history append_history
open_selection open_selection
else else