From 91a014e9ea1db9079f9bcb857cb3521637803c4c Mon Sep 17 00:00:00 2001
From: CoolnsX
Date: Tue, 5 Apr 2022 06:24:21 +0530
Subject: [PATCH] chore: optimizations, version bump
---
README.md | 6 +-
dra-cla | 320 ++++++++++++++++++++----------------------------------
2 files changed, 123 insertions(+), 203 deletions(-)
diff --git a/README.md b/README.md
index 79daa66..da09e0b 100644
--- a/README.md
+++ b/README.md
@@ -11,7 +11,7 @@
-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.
@@ -41,7 +41,8 @@ sudo cp dra-cla /usr/local/bin/dra-cla
Install termux [(Guide)](https://termux.com/)
```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
cp dra-cla $PREFIX/bin/dra-cla
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
- mpv - Video Player
- aria2 - Download manager
+- ffmpeg - m3u8 Downloader
diff --git a/dra-cla b/dra-cla
index 25a092e..ab28613 100755
--- a/dra-cla
+++ b/dra-cla
@@ -1,25 +1,6 @@
#!/bin/sh
-# dra-cla
-#
-# 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 .
-#
-# Project repository: https://github.com/CoolnsX/dra-cla
-
-# Version number
-VERSION="2.0.0"
-
+VERSION="2.1.0"
#######################
# AUXILIARY FUNCTIONS #
@@ -48,7 +29,6 @@ help_text () {
-V print version number and exit
Episode selection:
- Add 'h' on beginning for episodes like '6.5' -> 'h6'
Multiple episodes can be chosen given a range
Choose episode [1-13]: 1 6
This would choose episodes 1 2 3 4 5 6
@@ -94,6 +74,14 @@ dep_ch () {
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 #
@@ -107,27 +95,27 @@ search_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
+ data=$(curl -s "$base_url/videos/$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:]]*_\1_p"
+ fi
}
-search_for_unwatched () { # todo: merge into search_history
- search_results="$*"
- while read -r drama_id; do
- 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
+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 gogoplay, only shows unfinished drama
+# compares history with asianembed, only shows unfinished drama
search_history () {
tput clear
- search_results=$(cat "$logfile")
- [ -z "$search_results" ] && die "History is empty"
- search_results=$(search_for_unwatched "$search_results")
+ [ ! -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
@@ -146,22 +134,15 @@ get_dpage_link() {
curl -s "$base_url/videos/${drama_id}${ep_no}" | sed -nE 's_^[[:space:]]*