-
Notifications
You must be signed in to change notification settings - Fork 0
/
alldebrid
executable file
·90 lines (82 loc) · 1.98 KB
/
alldebrid
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh
#
# Debrid your link using Alldebrid
#
# Author: Hedi Nasr - [email protected]
ALLDEBRID_ROOT="https://alldebrid.com"
ALLDEBRID_LOGIN="register/?action=login&returnpage=%2Faccount%2F"
COOKIE_PATH="/tmp/cookie-jar"
### Connect to your Alldebrid account
### -> connect <login> <password>
connect() {
LOCATION="$(curl --silent -I "$ALLDEBRID_ROOT/$ALLDEBRID_LOGIN&login_login=$1&login_password=$2" \
-c "$COOKIE_PATH" | perl -n -e '/^Location: (.*)\r$/ && print "$1\n"')"
if [ "$LOCATION" != "https://alldebrid.com/account/" ]
then
echo 'Login failed'
exit 1
fi
}
### Debrid your url with Alldebrid
### -> debrid <url>
debrid() {
DEBRID="$(curl --silent -b "$COOKIE_PATH" "$ALLDEBRID_ROOT/service.php?link=$1&json=true")"
if (! echo "$DEBRID" | grep '"error":""') > /dev/null
then
# check error message
error=`echo "$DEBRID" | python -c "import sys, json; print(json.load(sys.stdin)['error'])"`
if [ $error = "premium" ]
then
echo "You're account is not a premium account!"
exit 1
else
echo "Bad link"
exit 1
fi
else
#echo "$DEBRID" | sed -e 's/^.*"link"[ ]*:[ ]*"//' -e 's/".*//' | sed 's/\\//g'
echo "$DEBRID" | python -c "import sys, json; print(json.load(sys.stdin)['link'])"
fi
}
### Usage info
print_help() {
cat <<EOF
Usage: ${0##*/} [-hv] <URL>
-h display this help and exit.
-v verbose mode.
EOF
}
while getopts ":hv" opt; do
case $opt in
h) ## Help
print_help
exit 0
;;
v) ## Verbose
verbose=1
;;
\?)
echo "Invalid option: -$OPTARG" >&2
print_help
exit 1
;;
esac
done
shift "$((OPTIND - 1))"
if [ "$#" -ne 1 ]
then
print_help
exit 1
else
if [ -e "$COOKIE_PATH" ]
then
debrid "$1"
exit 0
else
echo "Login: " && read login
echo "Password: " && read -s password
connect "$login" "$password"
debrid "$1"
exit 0
fi
fi