diff --git a/README.md b/README.md index e2d9abd..7505853 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -

Refactoring the script and using fzf for UI. WIP

+### 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.


@@ -50,18 +50,14 @@ Install termux [(Guide)](https://termux.com/) ```sh 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 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) -*Add ```referrer="https://asianembed.io"``` to mpv.conf (Open mpv app, goto three dots top right->Settings->Advanced-->Edit mpv.conf)* - -*Note: VLC android doesn't support referrer option. So it will not work* +For VLC: pass ``` dra-cla -v ``` ## Uninstall @@ -70,6 +66,7 @@ Install mpv-android [(Link)](https://play.google.com/store/apps/details?id=is.xy ## Dependencies +- fzf (new) - grep - sed - curl diff --git a/dra-cla b/dra-cla index 6e4c486..6657256 100755 --- a/dra-cla +++ b/dra-cla @@ -1,152 +1,157 @@ #!/bin/sh -VERSION="2.2.2" +#shellcheck disable=SC2154 -####################### -# AUXILIARY FUNCTIONS # -####################### +# most important variables. +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 printf "%s\n" "$line" done <<-EOF - Usage: - ${0##*/} [-v] [-q ] [-a ] [-d | -p ] [] - ${0##*/} [-v] [-q ] -c - ${0##*/} -h | -D | -U | -V + Usage: + ${0##*/} [-v] [-q ] [-a ] [-d | -p ] [] + ${0##*/} [-v] [-q ] -c + ${0##*/} -h | -D | -U | -V - Options: - -c continue watching drama from history - -a specify episode to watch - -h show helptext - -d download episode - -p download episode to specified directory - -q set video quality (best|worst|360|480|720|1080) - -v use VLC as the media player - -D delete history - -U fetch update from github - -V print version number and exit + Options: + -c continue watching drama from history + -a specify episode to watch + -h show helptext + -d download episode + -p download episode to specified directory + -q set video quality (best|worst|360|480|720|1080) + -v use VLC as the media player + -D delete Entire history + -U fetch update from github + -V print version number and exit - Episode selection: - Multiple episodes can be chosen given a range - Choose episode [1-13]: 1 6 - This would choose episodes 1 2 3 4 5 6 - To select the last episode use -1 + Episode selection: + Multiple episodes can be chosen given a range + Choose episode [1-13]: 1 6 + This would choose episodes 1 2 3 4 5 6 - When selecting non-interactively, the first result will be - selected, if drama is passed + When selecting non-interactively (eg: -a ), the first result will be + selected, if drama is passed as Args EOF } -version_text () { - inf "Version: $VERSION" >&2 -} +############ +# Update # +############ -die () { - err "$*" - exit 1 -} - -# 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" -)" +update_script() { + log "Checking For Updates.." >&2 + update="$(curl -A "$agent" -s "https://raw.githubusercontent.com/CoolnsX/dra-cla/$CHANNEL/dra-cla" | diff -u "$0" -)" 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 - if printf '%s\n' "$update" | patch "$0" - ; then - inf "Script has been updated" - else - die "Can't update for some reason!" - fi + log "Can't update for some reason!\n" "31" >&2 + exit 1 fi } -# checks if dependencies are present -dep_ch () { - for dep; do - if ! command -v "$dep" >/dev/null ; then - err "Program \"$dep\" not found. Please install it." - #aria2c is in the package aria2 - [ "$dep" = "aria2c" ] && err "To install aria2c, Type aria2" - die - fi +############ +# UI # +############ + +log() { + #shellcheck disable=SC2059 + printf "\033[2K\r\033[1;${2:-36}m${1}\033[0m" +} + +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 aria2" "32" + exit 1 + } done } -download () { -case $2 in - *m3u8*) - ffmpeg -loglevel error -stats -referer "$1" -i "$2" -c copy "$download_dir/${3}${4}.mp4" ;; - *) - aria2c --summary-interval=0 -x 16 -s 16 --referer="$1" "$2" --dir="$download_dir" -o "${3}${4}.mp4" --download-result=hide ;; -esac +download() { + case "$1" in + *m3u8*) ;; + *) aria2c --enable-rpc=false --check-certificate=false --continue --summary-interval=0 -x16 -s16 "$1" --dir="$download_dir" -o "$2.mp4" --download-result=hide ;; + esac } -############# -# 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:]]*_\1_p' -} - -check_episode () { - curl -s "$base_url/videos/$1" | sed '/Latest Episodes/,$d' | sed -nE "s_^[[:space:]]*_\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 () { +open_episode() { tput clear - [ ! -s "$logfile" ] && die "History is empty" - search_results=$(while read -r drama_id; do process_hist_entry & done < "$logfile"; wait) - [ -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}(.*)/\1/p" "$logfile") -} + log "Fetching $title Episode $episode.." + [ -z "$dpage_link" ] && dpage_link=$(curl -s -A "$agent" "$base_url/videos/${id}${episode}" | sed -nE 's_^[[:space:]]*