Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # Problem? => [email protected]
- unrestrictli() {
- local f=$tmp/dl.response.htm
- local c=$tmp/unrestrict.cookie
- local try=0 finalurl filename invalid
- # Check if no cookies or expired cookies
- if ! unrestrictli_account_info; then
- # Sign in if account is set
- if [ -n "$ACCOUNT_USER" ]; then
- unrestrictli_login "$ACCOUNT_USER" "$ACCOUNT_PASS"
- else
- log "Unrestrict.li VIP account is required."
- errmsg "Unrestrict.li VIP account is required."
- return 1
- fi
- fi
- while [ $try -lt $retries ]; do
- try=$(($try+1))
- GET "http://unrestrict.li/unrestrict.php" $f "--cookie $c -d jdownloader=1&domain=long&link=$link" "UNRESTRICT"
- finalurl=$(cat "$f" | sed 's/{"\([^"]\+\)":.*/\1/' | sed 's/\\//g')
- invalid=$(cat "$f" | sed 's/.*"invalid":"\([^"]\+\)".*/\1/')
- filename=$(cat "$f" | parse_json_string name)
- if [ "$invalid" != "$f" ]; then
- log "Failed to unrestrict link. (Errormessage: $invalid)"
- errmsg "Failed to unrestrict link. (Errormessage: $invalid)"
- waiting ${slot_waittime:-60}
- continue
- fi
- [ -z "$filename" ] && filename=${finalurl##*/}
- log "Starting download of $finalurl."
- if download "$finalurl" "$filename" "--retry 3 -C -"; then
- return 0
- fi
- done
- log "Download failed."
- errmsg "Download failed."
- return 1
- }
- # Check account info
- unrestrictli_account_info() {
- local traffic expires timestamp
- GET "http://unrestrict.li/api/jdownloader/user.php?format=json" $f "--cookie $c" "TRAFFIC"
- traffic=$(cat "$f" | parse_json_number traffic)
- expires=$(cat "$f" | parse_json_number expires)
- timestamp=$(date +%s)
- if [ $expires -lt $timestamp ]; then
- log "No VIP!"
- errmsg "No VIP!"
- return 1
- fi
- expires=$(date -d @$expires +%c)
- log "VIP expires: $expires."
- if [ $traffic -le 0 ]; then
- log "No traffic!"
- errmsg "No traffic!"
- return 1
- fi
- log "$traffic bytes left."
- return 0
- }
- # Check hosts
- unrestrictli_check() {
- local result
- GET "http://unrestrict.li/api/jdownloader/hosts.php?format=json" $f "--cookie $c" "HOSTERLIST"
- result=$(cat "$f" | parse_json_array result)
- echo "$result" | grep -q "$hosterdomain" || return 1
- return 0
- }
- # Sign in
- unrestrictli_login() {
- local username=$1
- local password=$2
- local cookiefile=$c
- local name
- GET "http://unrestrict.li/sign_in" $f "--cookie-jar $cookiefile -d return=home&username=$username&password=$password&signin=Log%20in&remember_me=remember" "LOGIN"
- name=$(<$cookiefile parse_cookie 'unrestrict_user')
- if [ -n "$name" ]; then
- log "Signed in as $user."
- return 0
- fi
- log "Failed to sign in. Check username and/or password. Complete captcha in browser before trying again."
- errmsg "Failed to sign in. Check username and/or password. Complete captcha in browser before trying again."
- return 1
- # TODO: Captcha (Solvemedia) processing
- }
Advertisement
Add Comment
Please, Sign In to add comment