SHOW:
|
|
- or go back to the newest paste.
1 | #!/bin/sh | |
2 | ||
3 | # Problem? => [email protected] | |
4 | ||
5 | unrestrictli() { | |
6 | local f=$tmp/dl.response.htm | |
7 | local c=$tmp/unrestrict.cookie | |
8 | ||
9 | - | local try=0 finalurl filename invalid |
9 | + | local try=0 finalurl filename invalid responsedata |
10 | ||
11 | # Check if no cookies or expired cookies | |
12 | if ! unrestrictli_account_info; then | |
13 | # Sign in if account is set | |
14 | if [ -n "$ACCOUNT_USER" ]; then | |
15 | unrestrictli_login "$ACCOUNT_USER" "$ACCOUNT_PASS" | |
16 | else | |
17 | log "Unrestrict.li VIP account is required." | |
18 | errmsg "Unrestrict.li VIP account is required." | |
19 | return 1 | |
20 | fi | |
21 | fi | |
22 | ||
23 | while [ $try -lt $retries ]; do | |
24 | try=$(($try+1)) | |
25 | ||
26 | GET "http://unrestrict.li/unrestrict.php" $f "--cookie $c -d jdownloader=1&domain=long&link=$link" "UNRESTRICT" | |
27 | ||
28 | finalurl=$(cat "$f" | sed 's/{"\([^"]\+\)":.*/\1/' | sed 's/\\//g') | |
29 | invalid=$(cat "$f" | sed 's/.*"invalid":"\([^"]\+\)".*/\1/') | |
30 | filename=$(cat "$f" | parse_json_string name) | |
31 | responsedata=$(<$f) | |
32 | - | if [ "$invalid" != "$f" ]; then |
32 | + | |
33 | if [ "$invalid" != "$responsedata" ]; then | |
34 | log "Failed to unrestrict link. (Errormessage: $invalid)" | |
35 | errmsg "Failed to unrestrict link. (Errormessage: $invalid)" | |
36 | waiting ${slot_waittime:-60} | |
37 | continue | |
38 | fi | |
39 | [ -z "$filename" ] && filename=${finalurl##*/} | |
40 | ||
41 | log "Starting download of $finalurl." | |
42 | if download "$finalurl" "$filename" "--retry 3 -C -"; then | |
43 | return 0 | |
44 | fi | |
45 | done | |
46 | log "Download failed." | |
47 | errmsg "Download failed." | |
48 | return 1 | |
49 | } | |
50 | ||
51 | # Check account info | |
52 | unrestrictli_account_info() { | |
53 | local traffic expires timestamp | |
54 | GET "http://unrestrict.li/api/jdownloader/user.php?format=json" $f "--cookie $c" "TRAFFIC" | |
55 | traffic=$(cat "$f" | parse_json_number traffic) | |
56 | expires=$(cat "$f" | parse_json_number expires) | |
57 | timestamp=$(date +%s) | |
58 | if [ $expires -lt $timestamp ]; then | |
59 | log "No VIP!" | |
60 | errmsg "No VIP!" | |
61 | return 1 | |
62 | fi | |
63 | expires=$(date -d @$expires +%c) | |
64 | log "VIP expires: $expires." | |
65 | if [ $traffic -le 0 ]; then | |
66 | log "No traffic!" | |
67 | errmsg "No traffic!" | |
68 | return 1 | |
69 | fi | |
70 | log "$traffic bytes left." | |
71 | return 0 | |
72 | } | |
73 | ||
74 | # Check hosts | |
75 | unrestrictli_check() { | |
76 | local result | |
77 | GET "http://unrestrict.li/api/jdownloader/hosts.php?format=json" $f "--cookie $c" "HOSTERLIST" | |
78 | result=$(cat "$f" | parse_json_array result) | |
79 | echo "$result" | grep -q "$hosterdomain" || return 1 | |
80 | return 0 | |
81 | } | |
82 | ||
83 | # Sign in | |
84 | unrestrictli_login() { | |
85 | local username=$1 | |
86 | local password=$2 | |
87 | local cookiefile=$c | |
88 | local name | |
89 | ||
90 | GET "http://unrestrict.li/sign_in" $f "--cookie-jar $cookiefile -d return=home&username=$username&password=$password&signin=Log%20in&remember_me=remember" "LOGIN" | |
91 | name=$(<$cookiefile parse_cookie 'unrestrict_user') | |
92 | if [ -n "$name" ]; then | |
93 | log "Signed in as $user." | |
94 | return 0 | |
95 | fi | |
96 | log "Failed to sign in. Check username and/or password. Complete captcha in browser before trying again." | |
97 | errmsg "Failed to sign in. Check username and/or password. Complete captcha in browser before trying again." | |
98 | return 1 | |
99 | # TODO: Captcha (Solvemedia) processing | |
100 | } |