From 72151fa6c84f9df2d9b3eb284b0b28f3dbfd308e Mon Sep 17 00:00:00 2001 From: kidburglar Date: Sat, 18 Feb 2017 10:48:30 +0100 Subject: [PATCH] Openload: Implement download file for free user through the API --- openload.sh | 80 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 25 deletions(-) diff --git a/openload.sh b/openload.sh index e4ad620a..2f0e43eb 100644 --- a/openload.sh +++ b/openload.sh @@ -75,40 +75,70 @@ openload_login() { # stdout: real file download link openload_download() { local -r URL=$2 - local PAGE WAIT FILE_URL JS + local API_URL='https://api.openload.co/1/file/' + local PAGE WAIT + local FILE_ID FILE_NAME FILE_URL + local DL_TICKET CAPTCHA_URL PAGE=$(curl -L "$URL") || return + FILE_ID=$(parse 'fid=' '"\(.*\)"' <<< "$PAGE") || return + log_debug "FILE_ID: $FILE_ID" - if match "

We can't find the file you are looking for" "$PAGE"; then - return $ERR_LINK_DEAD - fi + # Request a download ticket + JSON=$(curl "$API_URL/dlticket?file=$FILE_ID") || return + + # {"status":200,"msg":"OK","result":{"ticket": ...}} + openload_status "$JSON" || return - detect_javascript || return + # Grab the download ticket + DL_TICKET=$(parse_json 'ticket' <<< "$JSON") || return + log_debug "DL_TICKET: $DL_TICKET" - WAIT=$(parse_tag 'id="secondsleft"' span <<< "$PAGE") || return + # Waiting + WAIT=$(parse_json 'wait_time' <<< "$JSON") || return wait $(($WAIT)) seconds || return - # Obfuscated code with utf-8 variable names - JS=$(parse 'id="realdl"' '^\(.*\)$' 1 <<< "$PAGE") || return - JS=${JS#} - - FILE_URL=$(echo " -attr = function(name,value) { - if (typeof console === 'object' && typeof console.log === 'function') { - console.log(value); - } else { - print(value); - } -} -\$ = function(obj) { - return { - attr: attr - }; -} -$JS" | javascript) || return + # Get captcha + CAPTCHA_URL=$(parse_json 'captcha_url' <<< "$JSON") + log_debug "CAPTCHA_URL: $CAPTCHA_URL" + if [[ "$CAPTCHA_URL" != 'false' ]] ; then + CAPTCHA_IMG=$(create_tempfile '.gif') || return + curl -o "$CAPTCHA_IMG" "$CAPTCHA_URL" || return + + local WI WORD ID + WI=$(captcha_process "$CAPTCHA_IMG") || return + { read WORD; read ID; } <<< "$WI" + rm -f "$CAPTCHA_IMG" + + # Request download link + JSON=$(curl "$API_URL/dl?file=$FILE_ID&ticket=$DL_TICKET&captcha_response=$WORD") || return + + # {"status":200,"msg":"OK","result":{"url": ...}} + if ! openload_status "$JSON" ; then + captcha_nack $ID + log_error 'Wrong captcha' + return $ERR_CAPTCHA + fi + + captcha_ack $ID + else + # Request download link + JSON=$(curl "$API_URL/dl?file=$FILE_ID&ticket=$DL_TICKET") || return + + # {"status":200,"msg":"OK","result":{"url": ...}} + openload_status "$JSON" || return + fi + + # Get FILE_URL + FILE_URL=$(parse_json 'url' <<< "$JSON") || return + log_debug "FILE_URL: $FILE_URL" + + # Get FILE_NAME + FILE_NAME=$(parse_json 'name' <<< "$JSON") || return + log_debug "FILE_NAME: $FILE_NAME" echo "$FILE_URL" + echo "$FILE_NAME" } # Static function. Check if specified folder name is valid.