PageRenderTime 54ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/hosts/download/putlocker_com.php

http://rapidleech.googlecode.com/
PHP | 302 lines | 266 code | 33 blank | 3 comment | 103 complexity | 62fb114ec447831c2731060ab84189e4 MD5 | raw file
  1. <?php
  2. if (!defined('RAPIDLEECH')) {
  3. require_once('index.html');
  4. exit;
  5. }
  6. class putlocker_com extends DownloadClass {
  7. private $link, $page, $cookie, $pA, $Getregexp, $DLregexp;
  8. public function Download($link) {
  9. global $premium_acc;
  10. $this->link = str_ireplace(array('://putlocker.com/', '/mobile/file/'), array('://www.putlocker.com', '/file/'), $link);
  11. $this->Getregexp = '@(https?://(?:[^/\r\n\t\s\'\"<>]+\.)?putlocker\.com)?/get_file\.php\?(?:(?:id)|(?:file)|(stream))=[^\r\n\t\s\'\"<>]+@i';
  12. $this->DLregexp = '@Location: (https?://(?:(?:[^/\r\n]+/(?:(?:download)|(?:premium)))|(?:cdn\.[^/\r\n]+))/[^\r\n]*)@i';
  13. $this->pA = (empty($_REQUEST['premium_user']) || empty($_REQUEST['premium_pass']) ? false : true);
  14. if (empty($_REQUEST['step'])) {
  15. $this->page = $this->GetPage($this->link);
  16. is_present($this->page, '/?404', 'The requested file is not found');
  17. $this->cookie = GetCookiesArr($this->page);
  18. } else $this->cookie = array();
  19. $_REQUEST['cookieuse'] = (isset($_REQUEST['cookieuse']) && $_REQUEST['cookieuse'] == 'on' && !empty($_REQUEST['cookie'])) ? 'on' : false;
  20. if ($_REQUEST['cookieuse'] == 'on' && !empty($_POST['cookie_encrypted'])) {
  21. $_REQUEST['cookie'] = decrypt(urldecode($_REQUEST['cookie']));
  22. unset($_POST['cookie_encrypted']);
  23. }
  24. if (($_REQUEST['cookieuse'] == 'on' && preg_match('@auth[\s\t]*=[\s\t]*([\w\%\-]+);?@i', $_REQUEST['cookie'], $c)) || ($_REQUEST['premium_acc'] == 'on' && !empty($premium_acc['putlocker_com']['cookie']))) {
  25. $cookie = (empty($c[1]) ? urldecode($premium_acc['putlocker_com']['cookie']) : urldecode($c[1]));
  26. if (strpos($cookie, '%')) $cookie = urldecode($cookie);
  27. $this->cookie = array('auth' => urlencode($cookie));
  28. $page = $this->GetPage('http://www.putlocker.com/', $this->cookie);
  29. is_notpresent($page, '>Sign Out</a>', 'Cookie Error: Invalid Cookie?.');
  30. is_present($page, '>( Free )<', 'Cookie Error: Account isn\'t premium');
  31. $this->cookie = GetCookiesArr($page, $this->cookie);
  32. return $this->PremiumDL(!empty($c[1]));
  33. } elseif (($_REQUEST['premium_acc'] == 'on' && ($this->pA || (!empty($premium_acc['putlocker_com']['user']) && !empty($premium_acc['putlocker_com']['pass']))))) {
  34. $user = ($this->pA ? $_REQUEST['premium_user'] : $premium_acc['putlocker_com']['user']);
  35. $pass = ($this->pA ? $_REQUEST['premium_pass'] : $premium_acc['putlocker_com']['pass']);
  36. if ($this->pA && !empty($_POST['pA_encrypted'])) {
  37. $user = decrypt(urldecode($user));
  38. $pass = decrypt(urldecode($pass));
  39. unset($_POST['pA_encrypted']);
  40. }
  41. return $this->CookieLogin($user, $pass);
  42. } else {
  43. return $this->FreeDL();
  44. }
  45. }
  46. private function FreeDL() {
  47. if (!preg_match($this->Getregexp, $this->page, $DL)) {
  48. if (!preg_match('@var\scountdownNum\s?=\s?(\d+);@i', $this->page, $wait)) html_error('Countdown not found.');
  49. elseif ($wait[1] > 0) $this->CountDown($wait[1]);
  50. if (!preg_match('@<input type="hidden" value="(\w+)" name="hash"@i', $this->page, $hash)) html_error('Filehash not found.');
  51. $post = array();
  52. $post['hash'] = $hash[1];
  53. $post['confirm'] = cut_str($this->page, 'name="confirm" type="submit" value="', '"');
  54. $page = $this->GetPage($this->link, $this->cookie, $post);
  55. if (stripos($page, "\r\nLocation: ") !== false && preg_match('@Location: ((https?://[^/\r\n]+)?/[^\r\n]*)@i', $page, $redir)) {
  56. $redir = (empty($redir[2])) ? 'http://www.putlocker.com'.$redir[1] : $redir[1];
  57. $page = $this->GetPage($redir, $this->cookie);
  58. }
  59. if (!preg_match($this->Getregexp, $page, $DL)) html_error('Download-Link Not Found.');
  60. }
  61. $DL[0] = (empty($DL[1])) ? 'http://www.putlocker.com'.$DL[0] : $DL[0];
  62. $page = $this->GetPage($DL[0], $this->cookie);
  63. if (empty($DL[2])) { // File
  64. if (!preg_match($this->DLregexp, $page, $dlink)) html_error('Direct-Link Not Found.');
  65. if (stripos($page, 'Content-Disposition: attachment;') !== false) {
  66. $fname = cut_str($page, 'Content-Disposition: attachment; filename=', "\r\n");
  67. if (!empty($fname)) {
  68. $fname = trim(str_replace(str_split('\\:*?"<>|=;'."\t\r\n"), '', $fname));
  69. if(strpos($fname, '/') !== false) $fname = basename($fname);
  70. }
  71. }
  72. if (empty($fname)) {
  73. if (preg_match('@<title>([^<>\r\n\t\"]+)\s\|\sPutLocker@i', $this->page, $title)) {
  74. $title = trim(html_entity_decode($title[1]));
  75. $fname = str_replace(str_split('\\:*?"<>|=;'."\t\r\n"), '', $title);
  76. } else $fname = urldecode(basename(parse_url($dlink[1], PHP_URL_PATH)));
  77. }
  78. } else { // Stream
  79. if (!preg_match('@<media:content url="(https?://[^\r\n\"\t\s<>]+)"@i', $page, $dlink)) html_error('Stream-Link Not Found.');
  80. $dlink[1] = html_entity_decode($dlink[1]);
  81. $fname = urldecode(basename(parse_url($dlink[1], PHP_URL_PATH)));
  82. if (preg_match('@<title>([^<>\r\n\t\"]+)\s\|\sPutLocker@i', $this->page, $title)) {
  83. $title = trim(html_entity_decode($title[1]));
  84. if (strrpos($title, '.') !== false) $title = substr($title, 0, strrpos($title, '.'));
  85. $title .= strtolower(strrchr($fname, '.'));
  86. } else $title = $fname;
  87. $fname = substr($title, 0, strrpos($title, '.')) . '-[S]' . substr($title, strrpos($title, '.'));
  88. $fname = str_replace(str_split('\\:*?"<>|=;'."\t\r\n"), '', $fname);
  89. }
  90. $this->RedirectDownload($dlink[1], $fname, $this->cookie, 0, 0, $fname);
  91. }
  92. private function PremiumDL($usercookie = false) {
  93. $page = $this->GetPage($this->link, $this->cookie);
  94. $Mob = stripos($page, '>Download for Mobile</a>') !== false;
  95. if (!empty($_REQUEST['dltype']) && $_REQUEST['dltype'] == '3' && $Mob) {
  96. $this->link = str_ireplace('/file/', '/mobile/file/', $this->link);
  97. $page = $this->GetPage($this->link, $this->cookie);
  98. }
  99. preg_match(str_replace('|(stream)', '', $this->Getregexp), $page, $DLf); //File
  100. preg_match(str_replace('(?:id)|(?:file)|', '', $this->Getregexp), $page, $DLs); //Stream
  101. if (empty($DLf) && empty($DLs)) html_error('Download Link Not Found.');
  102. elseif (empty($DLf) xor empty($DLs)) $DL = empty($DLf) ? $DLs : $DLf;
  103. elseif (!empty($_GET['audl']) || (!empty($_REQUEST['dltype']) && $_REQUEST['dltype'] == '1')) $DL = $DLf;
  104. elseif (!empty($_REQUEST['dltype']) && $_REQUEST['dltype'] == '2') $DL = $DLs;
  105. else {
  106. global $PHP_SELF;
  107. echo "\n<br /><br /><h3 style='text-align: center;'>Select Download Option:</h3>";
  108. echo "\n<br /><center><form name='Pdl' action='$PHP_SELF' method='POST'>\n";
  109. echo "<select name='dltype' id='dltype'>\n<option value='1' selected='selected'>Original File</option>\n<option value='2'>Video Stream</option>\n";
  110. if ($Mob) echo "<option value='3'>Mobile</option>\n";
  111. echo "</select>\n";
  112. $data = $this->DefaultParamArr($this->link);
  113. $data['premium_acc'] = 'on'; // I should add 'premium_acc' to DefaultParamArr()
  114. if ($this->pA) {
  115. $data['pA_encrypted'] = 'true';
  116. $data['premium_user'] = urlencode(encrypt($_REQUEST['premium_user']));
  117. $data['premium_pass'] = urlencode(encrypt($_REQUEST['premium_pass']));
  118. } elseif ($usercookie) {
  119. $data['cookieuse'] = 'on';
  120. $data['cookie_encrypted'] = 'true';
  121. $data['cookie'] = urlencode(encrypt('auth='.$this->cookie['auth']));
  122. }
  123. foreach ($data as $n => $v) echo("<input type='hidden' name='$n' id='$n' value='$v' />\n");
  124. echo "<input type='submit' name='submit' value='Download' />\n";
  125. echo "</form></center>\n</body>\n</html>";
  126. exit;
  127. }
  128. unset($DLf, $DLs);
  129. $DL[0] = (empty($DL[1])) ? 'http://www.putlocker.com'.$DL[0] : $DL[0];
  130. $page = $this->GetPage($DL[0], $this->cookie);
  131. if (empty($DL[2])) { // File
  132. if (!preg_match($this->DLregexp, $page, $dlink)) html_error('Direct Link Not Found.');
  133. if (stripos($page, 'Content-Disposition: attachment;') !== false) {
  134. $fname = cut_str($page, 'Content-Disposition: attachment; filename=', "\r\n");
  135. if (!empty($fname)) {
  136. $fname = trim(str_replace(str_split('\\:*?"<>|=;'."\t\r\n"), '', $fname));
  137. if(strpos($fname, '/') !== false) $fname = basename($fname);
  138. }
  139. }
  140. if (empty($fname)) {
  141. if (preg_match('@<title>([^<>\r\n\t\"]+)\s\|\sPutLocker@i', $this->page, $title)) {
  142. $title = trim(html_entity_decode($title[1]));
  143. $fname = str_replace(str_split('\\:*?"<>|=;'."\t\r\n"), '', $title);
  144. } else $fname = urldecode(basename(parse_url($dlink[1], PHP_URL_PATH)));
  145. }
  146. if (stripos($DL[0], '&mobile=1')) { // Add a -[M] and correct the fileext on mobile videos.
  147. if (strrpos($fname, '.') !== false) $fname = substr($fname, 0, strrpos($fname, '.'));
  148. $fname .= '-[M].mp4';
  149. }
  150. } else { // Stream
  151. if (!preg_match('@<media:content url="(https?://[^\r\n\"\t\s<>]+)"@i', $page, $dlink)) html_error('Stream Link Not Found.');
  152. $dlink[1] = html_entity_decode($dlink[1]);
  153. $fname = urldecode(basename(parse_url($dlink[1], PHP_URL_PATH)));
  154. if (preg_match('@<title>([^<>\r\n\t\"]+)\s\|\sPutLocker@i', $this->page, $title)) {
  155. $title = trim(html_entity_decode($title[1]));
  156. if (strrpos($title, '.') !== false) $title = substr($title, 0, strrpos($title, '.'));
  157. $title .= strtolower(strrchr($fname, '.'));
  158. } else $title = $fname;
  159. $fname = substr($title, 0, strrpos($title, '.')) . '-[PS]' . substr($title, strrpos($title, '.'));
  160. $fname = str_replace(str_split('\\:*?"<>|=;'."\t\r\n"), '', $fname);
  161. }
  162. $this->RedirectDownload($dlink[1], $fname, $this->cookie, 0, 0, $fname);
  163. }
  164. private function Login($user, $pass) {
  165. $purl = 'http://www.putlocker.com/';
  166. if (!empty($_POST['step']) && $_POST['step'] == '1') {
  167. if (empty($_POST['captcha'])) html_error('You didn\'t enter the image verification code.');
  168. $this->cookie = StrToCookies(decrypt(urldecode($_POST['cookie'])));
  169. $post = array();
  170. $post['user'] = urlencode($user);
  171. $post['pass'] = urlencode($pass);
  172. $post['captcha_code'] = urlencode($_POST['captcha']);
  173. $post['remember'] = 1;
  174. $post['login_submit'] = 'Login';
  175. $page = $this->GetPage($purl.'authenticate.php?login', $this->cookie, $post, $purl.'authenticate.php?login');
  176. $this->cookie = GetCookiesArr($page, $this->cookie);
  177. if (stripos($page, "\r\nLocation: ") !== false && preg_match('@Location: ((https?://[^/\r\n]+)?/authenticate\.php[^\r\n]*)@i', $page, $redir)) {
  178. $redir = (empty($redir[2])) ? 'http://www.putlocker.com'.$redir[1] : $redir[1];
  179. $page = $this->GetPage($redir, $this->cookie);
  180. $this->cookie = GetCookiesArr($page, $this->cookie);
  181. }
  182. is_present($page, 'No such username or wrong password', 'Login Failed: Email/Password incorrect.');
  183. is_present($page, 'Please re-enter the captcha code', 'Login Failed: Wrong CAPTCHA entered.');
  184. if (empty($this->cookie['auth'])) html_error('Login Error: Cannot find "auth" cookie.');
  185. $page = $this->GetPage($purl, $this->cookie, 0, $purl.'authenticate.php?login');
  186. is_present($page, '>( Free )<', 'Account isn\'t premium');
  187. $this->SaveCookies($user, $pass); // Update cookies file
  188. return $this->PremiumDL();
  189. } else {
  190. $page = $this->GetPage($purl.'authenticate.php?login', $this->cookie, 0, $purl);
  191. $this->cookie = GetCookiesArr($page, $this->cookie);
  192. if (!preg_match('@(https?://[^/\r\n\t\s\'\"<>]+)?/include/captcha\.php\?[^/\r\n\t\s\'\"<>]+@i', $page, $imgurl)) html_error('CAPTCHA not found.');
  193. $imgurl = (empty($imgurl[1])) ? 'http://www.putlocker.com'.$imgurl[0] : $imgurl[0];
  194. $imgurl = html_entity_decode($imgurl);
  195. //Download captcha img.
  196. $page = $this->GetPage($imgurl, $this->cookie);
  197. $capt_img = substr($page, strpos($page, "\r\n\r\n") + 4);
  198. $imgfile = DOWNLOAD_DIR . 'putlocker_captcha.png';
  199. if (file_exists($imgfile)) unlink($imgfile);
  200. if (!write_file($imgfile, $capt_img)) html_error('Error getting CAPTCHA image.');
  201. $data = $this->DefaultParamArr($this->link, encrypt(CookiesToStr($this->cookie)));
  202. $data['step'] = 1;
  203. $data['premium_acc'] = 'on'; // I should add 'premium_acc' to DefaultParamArr()
  204. if ($this->pA) {
  205. $data['pA_encrypted'] = 'true';
  206. $data['premium_user'] = urlencode(encrypt($user)); // encrypt() will keep this safe.
  207. $data['premium_pass'] = urlencode(encrypt($pass)); // And this too.
  208. }
  209. $this->EnterCaptcha($imgfile.'?'.time(), $data);
  210. exit;
  211. }
  212. }
  213. private function IWillNameItLater($cookie, $decrypt=true) {
  214. if (!is_array($cookie)) {
  215. if (!empty($cookie)) return $decrypt ? decrypt(urldecode($cookie)) : urlencode(encrypt($cookie));
  216. return '';
  217. }
  218. if (count($cookie) < 1) return $cookie;
  219. $keys = array_keys($cookie);
  220. $values = array_values($cookie);
  221. $keys = $decrypt ? array_map('decrypt', array_map('urldecode', $keys)) : array_map('urlencode', array_map('encrypt', $keys));
  222. $values = $decrypt ? array_map('decrypt', array_map('urldecode', $values)) : array_map('urlencode', array_map('encrypt', $values));
  223. return array_combine($keys, $values);
  224. }
  225. private function CookieLogin($user, $pass, $filename = 'putlocker_dl.php') {
  226. global $maxdays, $secretkey;
  227. $maxdays = 3; // Max days to keep cookies saved
  228. if (empty($user) || empty($pass)) html_error('Login Failed: User or Password is empty.');
  229. $filename = DOWNLOAD_DIR . basename($filename);
  230. if (!file_exists($filename) || (!empty($_POST['step']) && $_POST['step'] == '1')) return $this->Login($user, $pass);
  231. $file = file($filename);
  232. $savedcookies = unserialize($file[1]);
  233. unset($file);
  234. $hash = hash('crc32b', $user.':'.$pass);
  235. if (array_key_exists($hash, $savedcookies)) {
  236. if (time() - $savedcookies[$hash]['time'] >= ($maxdays * 24 * 60 * 60)) return $this->Login($user, $pass); // Ignore old cookies
  237. $_secretkey = $secretkey;
  238. $secretkey = sha1($user.':'.$pass);
  239. $this->cookie = (decrypt(urldecode($savedcookies[$hash]['enc'])) == 'OK') ? $this->IWillNameItLater($savedcookies[$hash]['cookie']) : '';
  240. $secretkey = $_secretkey;
  241. if (empty($this->cookie) || (is_array($this->cookie) && count($this->cookie) < 1)) return $this->Login($user, $pass);
  242. $page = $this->GetPage('http://www.putlocker.com/', $this->cookie);
  243. if (stripos($page, '>Sign Out</a>') === false) return $this->Login($user, $pass);
  244. is_present($page, '>( Free )<', 'Account isn\'t premium');
  245. $this->SaveCookies($user, $pass); // Update cookies file
  246. return $this->PremiumDL();
  247. }
  248. return $this->Login($user, $pass);
  249. }
  250. private function SaveCookies($user, $pass, $filename = 'putlocker_dl.php') {
  251. global $maxdays, $secretkey;
  252. $filename = DOWNLOAD_DIR . basename($filename);
  253. if (file_exists($filename)) {
  254. $file = file($filename);
  255. $savedcookies = unserialize($file[1]);
  256. unset($file);
  257. // Remove old cookies
  258. foreach ($savedcookies as $k => $v) if (time() - $v['time'] >= ($maxdays * 24 * 60 * 60)) unset($savedcookies[$k]);
  259. } else $savedcookies = array();
  260. $hash = hash('crc32b', $user.':'.$pass);
  261. $_secretkey = $secretkey;
  262. $secretkey = sha1($user.':'.$pass);
  263. $savedcookies[$hash] = array('time' => time(), 'enc' => urlencode(encrypt('OK')), 'cookie' => $this->IWillNameItLater($this->cookie, false));
  264. $secretkey = $_secretkey;
  265. file_put_contents($filename, "<?php exit(); ?>\r\n" . serialize($savedcookies), LOCK_EX);
  266. }
  267. }
  268. //[16-9-2012] Written by Th3-822.
  269. ?>