Skip to content

Commit

Permalink
Remove usage of cookie
Browse files Browse the repository at this point in the history
Server side changes... Browser cookie is not required now
  • Loading branch information
KevCui committed Apr 17, 2022
1 parent 8dcca21 commit a99f175
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 1,098 deletions.
11 changes: 0 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
## Table of Contents

- [Dependency](#dependency)
- [Installation](#installation)
- [How to use](#how-to-use)
- [Example](#example)
- [Disclaimer](#disclaimer)
Expand All @@ -20,16 +19,6 @@
- [Node.js](https://nodejs.org/en/download/)
- [ffmpeg](https://ffmpeg.org/download.html)
- [openssl](https://www.openssl.org/source/): optional, needed when using `-t <num>` for faster download
- Chrome / Chromium browser (:warning: _If you have Chrome/Chromium browser installed but the script cannot find the command, please check the system path `echo $PATH` and put the Chrome/Chromium binary into one of the paths._)

## Installation

- Install npm packages:

```
$ cd bin
$ npm i puppeteer-extra puppeteer-extra-plugin-stealth
```

## How to use

Expand Down
72 changes: 5 additions & 67 deletions animepahe-dl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ set_var() {
_FZF="$(command -v fzf)" || command_not_found "fzf"
_NODE="$(command -v node)" || command_not_found "node"
_FFMPEG="$(command -v ffmpeg)" || command_not_found "ffmpeg"
_CHROME="$(command -v chromium)" || _CHROME="$(command -v chrome)" || command_not_found "chrome"
if [[ ${_PARALLEL_JOBS:-} -gt 1 ]]; then
_OPENSSL="$(command -v openssl)" || command_not_found "openssl"
fi
Expand All @@ -47,17 +46,6 @@ set_var() {
_SCRIPT_PATH=$(dirname "$(realpath "$0")")
_ANIME_LIST_FILE="$_SCRIPT_PATH/anime.list"
_SOURCE_FILE=".source.json"

_COOKIE_FILE="${_SCRIPT_PATH}/cookie.json"
_USER_AGENT_FILE="${_SCRIPT_PATH}/user-agent"
_USER_AGENT_LIST_FILE="${_SCRIPT_PATH}/user-agent.list"
_GET_COOKIE_JS="${_SCRIPT_PATH}/bin/getCookie.js"
if [[ -s "$_USER_AGENT_FILE" ]]; then
_USER_AGENT="$(cat "$_USER_AGENT_FILE")"
else
_USER_AGENT="$(shuf -n1 "$_USER_AGENT_LIST_FILE")"
echo "$_USER_AGENT" > "$_USER_AGENT_FILE"
fi
}

set_args() {
Expand Down Expand Up @@ -126,47 +114,7 @@ command_not_found() {

get() {
# $1: url
local cookie
cookie="$(get_cookie)"
"$_CURL" -sS -L -A "$_USER_AGENT" -H "Cookie: $cookie" "$1" --compressed
}

get_cookie() {
if [[ "$(is_file_expired "$_COOKIE_FILE" "120")" == "yes" ]]; then
local cookie
print_info "Wait a few seconds for fetching cookie..."
cookie="$($_GET_COOKIE_JS "$_CHROME" "$_HOST" "$_USER_AGENT" 2>/dev/null)"
if [[ -z "${cookie:-}" ]]; then
get_cookie
else
echo "$cookie" > "$_COOKIE_FILE"
fi
fi
"$_JQ" -r '.[] | select(.name=="cf_clearance") | "\(.name)=\(.value)"' "$_COOKIE_FILE" | tr '\n' ';'
}

remove_temp_file() {
rm -f "$_COOKIE_FILE"
rm -f "$_USER_AGENT_FILE"
}

is_file_expired() {
# $1: file
# $2: n minutes
local o
o="yes"

if [[ -f "$1" && -s "$1" ]]; then
local d n
d=$(date -d "$(date -r "$1") +$2 minutes" +%s)
n=$(date +%s)

if [[ "$n" -lt "$d" ]]; then
o="no"
fi
fi

echo "$o"
"$_CURL" -sS -L "$1" --compressed
}

download_anime_list() {
Expand All @@ -188,30 +136,21 @@ search_anime_by_name() {
fi
}

get_anime_id() {
# $1: anime slug
get "$_ANIME_URL/$1" \
| grep getJSON \
| sed -E 's/.*id=//' \
| awk -F '&' '{print $1}'
}

get_episode_list() {
# $1: anime id
# $2: page number
get "${_API_URL}?m=release&id=${1}&sort=episode_asc&page=${2}"
}

download_source() {
local id d p n
local d p n
mkdir -p "$_SCRIPT_PATH/$_ANIME_NAME"
id="$(get_anime_id "$_ANIME_SLUG")"
d="$(get_episode_list "$id" "1")"
d="$(get_episode_list "$_ANIME_SLUG" "1")"
p="$("$_JQ" -r '.last_page' <<< "$d")"

if [[ "$p" -gt "1" ]]; then
for i in $(seq 2 "$p"); do
n="$(get_episode_list "$id" "$i")"
n="$(get_episode_list "$_ANIME_SLUG" "$i")"
d="$(echo "$d $n" | "$_JQ" -s '.[0].data + .[1].data | {data: .}')"
done
fi
Expand Down Expand Up @@ -442,14 +381,13 @@ main() {
fi
fi

[[ "$_ANIME_SLUG" == "" ]] && (remove_temp_file; print_error "Anime slug not found!")
[[ "$_ANIME_SLUG" == "" ]] && print_error "Anime slug not found!"
_ANIME_NAME=$(grep "$_ANIME_SLUG" "$_ANIME_LIST_FILE" \
| tail -1 \
| awk -F '] ' '{print $2}' \
| sed -E 's/[^[:alnum:] ,\+\-\)\(]/_/g')

if [[ "$_ANIME_NAME" == "" ]]; then
remove_temp_file
print_warn "Anime name not found! Try again."
download_anime_list
exit 1
Expand Down
20 changes: 0 additions & 20 deletions bin/getCookie.js

This file was deleted.

Loading

0 comments on commit a99f175

Please sign in to comment.