Last active
July 4, 2017 11:54
-
-
Save cubny/9a814e91767955a6583b0f7184912369 to your computer and use it in GitHub Desktop.
Scrapes the links of all episodes in a TV Show from Tinymoviez url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
fetchall=true | |
fetchlast=false | |
download=false | |
configfile=~/.tv.cfg | |
trim() { | |
local var="$*" | |
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters | |
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters | |
echo -n "$var" | |
} | |
usage() { | |
cat <<EOF | |
SYNOPSIS | |
tv.sh [-hl] [-u username] [-p password] [-u url] [-b base-url] | |
DESCRIPTION | |
This script will fetch all show links in a Tinymoviez series page. | |
it saves url, your username and password in ~/.tv.cfg so you don't | |
have to enter it in second run. | |
-h| --help shows this help. | |
-u|--username username your tinymoviez username | |
-p|--password your tinymoviez password | |
-r|--url series url, it can only contain partial url like | |
dl36929. if this is the case you need to enter | |
--base-url option too. otherwise in case of entering | |
the full url like http://3tinyz.com/dl36929 | |
--base-url is optional | |
-b|--base-url tinymoviez base url e.g.:http://3tinyz.com. read | |
--url option for more info | |
-l|--fetch-last show the last episode only | |
EXAMPLE | |
tv.sh -u alireza -p closeyoureyes -r http://3tinyz.com/dl36929 | |
EOF | |
} | |
### read config file | |
if [[ -f $configfile ]]; then | |
variables=("user base_url pass") | |
while read line; do | |
if [[ "$line" =~ ^[^#]*= ]]; then | |
name=$(trim ${line%%=*}) | |
if [[ " ${variables[@]} " =~ " ${name} " ]]; then | |
declare ${name}=$(trim ${line#*=}) | |
fi | |
fi | |
done < "$configfile" | |
fi | |
### read args | |
while [[ $# > 0 ]] | |
do | |
key="$1" | |
case $key in | |
-u|--username) | |
user="$2" | |
shift | |
;; | |
-p|--password) | |
pass="$2" | |
shift | |
;; | |
-r|--url) | |
url="$2" | |
shift | |
;; | |
-b|--base-url) | |
base_url="$2" | |
shift | |
;; | |
-l|--fetch-last) | |
fetchlast=true | |
;; | |
-d|--download) | |
download=true | |
;; | |
-h|--help) | |
usage | |
exit | |
;; | |
*) | |
# unknown option | |
;; | |
esac | |
shift | |
done | |
fullurl="${base_url}/${url}" | |
### check args | |
if [ -z ${user+x} ]; then | |
echo "username is not specified."; | |
exit | |
fi | |
if [ -z ${pass+x} ]; then | |
echo "password is not specified."; | |
exit | |
else | |
md5_pass=$(md5 -q -s $pass) | |
fi | |
if [[ "$url" == http* ]]; then | |
base_url=$(echo $url | cut -d "/" -f1,2,3) | |
url=$(echo $url | cut -d "/" -f4) | |
fullurl="${base_url}/${url}" | |
fi | |
if [ -z ${base_url+x} ]; then | |
echo "base_url is not specified."; | |
exit | |
fi | |
regex='https?://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]' | |
if ! [[ "$fullurl" =~ $regex ]]; then | |
echo "url is not correct" | |
exit | |
fi | |
if [[ "$fullurl" == "${base_url}/" ]]; then | |
echo "url does not point to series" | |
exit | |
fi | |
### write config to be used later | |
cat <<EOF > $configfile | |
user=$user | |
pass=$pass | |
base_url=$base_url | |
EOF | |
### make request | |
cookie="Cookie: tinymoviez_username=$user; tinymoviez_pass=$md5_pass;" | |
show_page=$(curl -s "$fullurl" -H 'User-Agent: tv' -H "${cookie}") | |
links=$(echo $show_page | grep -o -E 'href="(dl[^"#]+)"' | cut -d'"' -f2 | awk -v base_url="$base_url/" '{print base_url $1}') | |
if [ "$fetchlast" = true ]; then | |
links=$(echo "$links" | tail -1) | |
fi | |
echo "$links" |
@raminious you can use md5_pass=$(echo -n $pass | md5sum | cut -d' ' -f1)
instead
Hi, Sorry This Source is PHP Or Not?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On fedora it says: line 100: md5: command not found
I change line100 to md5_pass=$(printf '%s' $pass | md5sum | cut -d ' ' -f 1) and solved
but still return empty string