Th3-822

[rapidleech][d][freedl] baidu_com

Aug 26th, 2016
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.68 KB | None | 0 0
  1. <?php
  2.  
  3. if (!defined('RAPIDLEECH')) {
  4.     require_once('index.html');
  5.     exit;
  6. }
  7.  
  8. class baidu_com extends DownloadClass {
  9.     private $userAgent = 'netdisk;5.7.2.3;PC;PC-Windows;6.1.7601;WindowsBaiduYunGuanJia';
  10.     public function Download($link) {
  11.         if (!preg_match('@(https?://(?:pan|yun)\.baidu\.com)/(?:s/\w+|(?:(?:wap/)?share|wap)/link\?\w+=\w+(?:&\w+=\w+)*)@i', $link, $_link)) html_error('Invalid link?.');
  12.         $link = $GLOBALS['Referer'] = str_ireplace(array('http://', '/wap/link', '/wap/'), array('https://', '/share/link', '/'), $_link[0]);
  13.         $host = $_link[1];
  14.         $cookie = isset($_POST['step']) && !empty($_POST['cookie']) ? StrToCookies(decrypt(urldecode($_POST['cookie']))) : array();
  15.  
  16.         if (empty($_POST['step']) || $_POST['step'] != '1') {
  17.             $bduss = $this->getLoginCookie();
  18.  
  19.             $page = $this->GetPage($link);
  20.             $cookie = GetCookiesArr($page);
  21.  
  22.             // Baidu doesn't reply /s/ links without a valid BAIDUID cookie :S
  23.             if (substr($page, 9, 3) == '403') {
  24.                 $page = $this->GetPage($link, $cookie);
  25.                 $cookie = GetCookiesArr($page, $cookie);
  26.             }
  27.  
  28.             is_present($page, '啊哦,你所访问的页面不存在了', 'File Doesn\'t Exist');
  29.  
  30.             if (!preg_match('@yunData\.setData\((\{.+?\})\);@s', $page, $data)) html_error('yunData.setData Not Found.');
  31.             $rawYunData = preg_replace('@([:,\[\]{}])(\d{11,})([:,\[\]{}])@', '$1"$2"$3', $data[1]); // Avoid Issues With Long IDs
  32.             $yunData = $this->json2array($rawYunData, 'Error while parsing yunData');
  33.             if (empty($yunData['bdstoken'])) $yunData['bdstoken'] = 'null';
  34.         } else {
  35.             $cookie = StrToCookies(decrypt(urldecode($_POST['cookie'])));
  36.             $_POST['step'] = false;
  37.             if (empty($_POST['captcha'])) html_error('You didn\'t enter the image verification code.');
  38.             if (empty($_POST['vcode_str'])) html_error('Empty Captcha Challenge.');
  39.             if (empty($_POST['yunData'])) html_error('[Post] Empty yunData.');
  40.             if (empty($_POST['bduss'])) html_error('[Post] Empty bduss cookie.');
  41.             $captcha = array('vcode_input' => urlencode($_POST['captcha']), 'vcode_str' => urlencode($_POST['vcode_str']));
  42.             $rawYunData = decrypt(base64_decode($_POST['yunData']));
  43.             $yunData = $this->json2array($rawYunData, '[Post] Error while parsing yunData');
  44.             $bduss = decrypt(base64_decode($_POST['bduss']));
  45.         }
  46.  
  47.         $post = array('encrypt' => 0, 'product' => 'share', 'uk' => $yunData['uk'], 'primaryid' => $yunData['shareid'], 'fid_list' => "%5B{$yunData['file_list']['list'][0]['fs_id']}%5D");
  48.         if (!empty($captcha)) $post = array_merge($post, $captcha);
  49.  
  50.         $json = $this->GetPage("$host/api/sharedownload?app_id={$yunData['file_list']['list'][0]['app_id']}&bdstoken={$yunData['bdstoken']}&channel=chunlei&clienttype=0&sign={$yunData['sign']}&timestamp={$yunData['timestamp']}&web=1", $cookie, $post, $GLOBALS['Referer'] . "\r\nX-Requested-With: XMLHttpRequest");
  51.         $data = $this->json2array($json, 'Error getting download info');
  52.  
  53.         if (!empty($data['errno'])) {
  54.             if ($data['errno'] == -20) {
  55.                 $captcha = $this->json2array($this->GetPage("{$host}/api/getvcode?app_id={$yunData['file_list']['list'][0]['app_id']}&bdstoken={$yunData['bdstoken']}&channel=chunlei&clienttype=0&prod=share&web=1", $cookie, $post, $GLOBALS['Referer'] . "\r\nX-Requested-With: XMLHttpRequest"), 'Error getting captcha data');
  56.                 if (!empty($captcha['errno'])) html_error("Unknown captcha error [{$captcha['errno']}]");
  57.  
  58.                 $data = $this->DefaultParamArr($link, $cookie, 1, 1);
  59.                 $data['step'] = 1;
  60.                 $data['yunData'] = base64_encode(encrypt($rawYunData));
  61.                 $data['bduss'] = base64_encode(encrypt($bduss));
  62.                 $data['vcode_str'] = $captcha['vcode'];
  63.  
  64.                 list($headers, $imgBody) = explode("\r\n\r\n", $this->GetPage($captcha['img']), 2);
  65.                 if (substr($headers, 9, 3) != '200') html_error('Error downloading CAPTCHA img.');
  66.                 $mimetype = (preg_match('@image/[\w+]+@', $headers, $mimetype) ? $mimetype[0] : 'image/jpg');
  67.                 return $this->EnterCaptcha("data:$mimetype;base64,".base64_encode($imgBody), $data);
  68.             } else if ($data['errno'] == 112) html_error('Expired Download Token');
  69.             html_error("Unknown download-info error [{$data['errno']}]");
  70.         }
  71.  
  72.         if (empty($data['list'][0]['dlink'])) html_error('Redirect-Link Not Found.');
  73.         if (function_exists('headers2request')) $GLOBALS['Referer'] .= "\r\nUser-Agent: {$this->userAgent}"; // Changed User-Agent to "increase" download speed
  74.  
  75.         $cookie['BDUSS'] = $bduss; // Extra Cookie (Needed to Download)
  76.         $page = $this->GetPage($data['list'][0]['dlink'], $cookie);
  77.         if (substr($page, 9, 3) == '403') html_error('Invalid BDUSS Cookie');
  78.         if (!preg_match('@https?://(?:[\w\-]+\.)+baidupcs(?:\.[\w\-]+)*\.com/file/[^\s\"\'<>]+@i', $page, $DL)) html_error('Download-Link Not Found.');
  79.  
  80.         return $this->RedirectDownload($DL[0], 'pan_baidu_com_placeholder');
  81.     }
  82.  
  83.     private function getLoginCookie() {
  84.         if (!empty($_POST['cookie'])) {
  85.             if (!empty($_POST['cookie_encrypted'])) {
  86.                 $_POST['cookie'] = decrypt(urldecode($_POST['cookie']));
  87.                 unset($_POST['cookie_encrypted']);
  88.             }
  89.             $cookie = StrToCookies($_POST['cookie']);
  90.             $_POST['cookie'] = false;
  91.         } else if (!empty($GLOBALS['premium_acc']['baidu_com']['cookie'])) {
  92.             $cookie = $GLOBALS['premium_acc']['baidu_com']['cookie'];
  93.             $cookie = (is_array($cookie) ? $cookie : StrToCookies($cookie));
  94.         }
  95.         if (empty($cookie['BDUSS'])) html_error('Needs a Valid "BDUSS" Cookie for Download');
  96.         return $cookie['BDUSS'];
  97.     }
  98. }
  99.  
  100. // [26-8-2016] Written by Th3-822.
  101. // [30-8-2016] Switched links to http to help decrease connection errors & Changed User-Agent for "better" download speed. - Th3-822
  102. // [18-4-2017] Fixed. - Th3-822
  103. // [26-1-2018] Switched to https as there is now a forced redirect & fixed download (now it does require a login cookie for download). - Th3-822
Add Comment
Please, Sign In to add comment