diff --git a/dra-cla b/dra-cla index d5ac88b..25a092e 100755 --- a/dra-cla +++ b/dra-cla @@ -18,7 +18,7 @@ # Project repository: https://github.com/CoolnsX/dra-cla # Version number -VERSION="1.1.0" +VERSION="2.0.0" ####################### @@ -68,8 +68,8 @@ die () { exit 1 } +# get the newest version of this script from github and replace it update_script () { - # get the newest version of this script from github and replace it update="$(curl -s "https://raw.githubusercontent.com/CoolnsX/dra-cla/main/dra-cla" | diff -u "$0" -)" if [ -z "$update" ]; then inf "Script is up to date :)" @@ -82,8 +82,8 @@ update_script () { fi } +# checks if dependencies are present dep_ch () { - # checks if dependencies are present for dep; do if ! command -v "$dep" >/dev/null ; then err "Program \"$dep\" not found. Please install it." @@ -99,78 +99,73 @@ dep_ch () { # SEARCHING # ############# +# gets drama names along with its id for search term search_drama () { - # get drama name along with its id for search term - search=$(printf '%s' "$1" | tr ' ' '+' ) - curl -s "$base_url/search?type=movies&keyword=$search" | - sed -n -E 's_^[[:space:]]*_\1_p' } -search_for_unwatched () { - # compares history with dramacool, only shows unfinished drama +check_episode () { + tmp=$(printf "%s" "$1" | sed 's/[0-9]*.$//') + curl -s "$base_url/videos/$1" | sed -nE "s_^[[:space:]]*_\1_p" | head -n 1 +} + +search_for_unwatched () { # todo: merge into search_history search_results="$*" while read -r drama_id; do - temp=$(curl -s "$base_url/drama-detail/$drama_id") - current_ep_number=$(printf "%s" "$temp" | sed -nE "s/.*href.*episode-(.*).html.*class.*img.*/\1/p" | head -1) - drama_id=$(printf "%s" "$temp" | sed -nE "s/.*href=\"\/(.*)-episode-${current_ep_number}.html.*class.*img.*/\1/p" | head -1) - history_ep_number=$(sed -n -E "s/${drama_id}\t//p" "$logfile") - [ "$current_ep_number" -ge "$history_ep_number" ] && printf '%s\n' "$drama_id" + current_ep_number=$(check_episode "$drama_id") + history_ep_number=$(printf "%s" "$drama_id" | grep -Po '\K\d+' | tail -n 1) + [ -n "$current_ep_number" ] && [ "$current_ep_number" -ge "$history_ep_number" ] && printf '%s\n' "$drama_id" done <<-EOF $search_results EOF } -search_another_drama () { - tput clear - prompt "Search Drama" - query="$REPLY $REPLY2" - process_search -} - +# compares history with gogoplay, only shows unfinished drama search_history () { tput clear - search_results=$(sed -n -E 's/\t[0-9]*//p' "$logfile") + search_results=$(cat "$logfile") [ -z "$search_results" ] && die "History is empty" search_results=$(search_for_unwatched "$search_results") [ -z "$search_results" ] && die "No unwatched episodes" + one_hist=$(printf '%s\n' "$search_results" | grep -e "$" -c) + [ "$one_hist" = 1 ] && select_first=1 drama_selection "$search_results" - ep_choice_start=$(sed -n -E "s/${selection_id}\t//p" "$logfile") + ep_choice_start=$(sed -n -E "s/${selection_id}(.*)/\1/p" "$logfile") } ################## # URL PROCESSING # ################## +# get the download page url get_dpage_link() { - # get the download page url drama_id="$1" ep_no="$2" - for params in "-episode-$ep_no.html" "-$ep_no.html" "-episode-$ep_no-1.html" "-camrip-episode-$ep_no.html"; do - drama_page=$(curl -s "$base_url/$drama_id$params") - printf '%s' "$drama_page" | grep -q '

404

' || break - done - printf '%s' "$drama_page" | - sed -n -E 's/.*class="Standard Server selected" rel="1" data-video="([^"]*)".*/\1/p' | sed 's/^/https:/g' + + curl -s "$base_url/videos/${drama_id}${ep_no}" | sed -nE 's_^[[:space:]]*