#!/bin/sh #shellcheck disable=SC2154 # most important variables. VERSION="3.0.1" CHANNEL="main" base_url="https://streamcool.pro" 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 # ############ 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 | -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 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 When selecting non-interactively (eg: -a ), the first result will be selected, if drama is passed as Args EOF } ############ # Update # ############ 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 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 log "Can't update for some reason!\n" "31" >&2 exit 1 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 "$1" in *m3u8*) log "Fetching Metadata" data=$(curl -s -A "$agent" "$1" | sed '/#/d') printf '%s' "$data" | nl -n'rz' | sed -E "s|^([0-9]*)[[:space:]]*(.*)|${3}\2\n\tout=\1.ts|g" | aria2c -x16 -s16 -j50 -d "$logdir/dra-hls" -i - --download-result=hide --summary-interval=0 --allow-overwrite=true log "\nConcatenating Pieces..\n" cat "$logdir/dra-hls"/* | ffmpeg -loglevel error -stats -i - -c copy "$download_dir/$2.mp4" -y rm -f "$logdir/dra-hls"/* ;; *) aria2c --enable-rpc=false --check-certificate=false --continue --summary-interval=0 -x16 -s16 "$1" --dir="$download_dir" -o "$2.mp4" --download-result=hide ;; esac tput clear log "Downloaded $2/$4" } open_episode() { tput clear log "Fetching $title Episode $episode.." [ -z "$dpage_link" ] && dpage_link=$(curl -s -A "$agent" "$base_url/videos/${id}${episode}" | sed -nE 's_^[[:space:]]*