PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/scripts/feeds/xVoD/xVoD/php/scraper/kinoto/moviesPreLink.php

http://eboda-hd-for-all-500.googlecode.com/
PHP | 476 lines | 376 code | 41 blank | 59 comment | 24 complexity | 22d0f3d17f12213abc1206cbf9675cd3 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0
  1. <?php
  2. /*-------------------------
  3. * Developed by Maicros
  4. * GNU/GPL Licensed
  5. * ------------------------*/
  6. include_once '../../config/config.php';
  7. include_once 'KinotoTemplate.php';
  8. include_once "../../util/VideoUtil.php";
  9. include_once "../../util/RssScriptUtil.php";
  10. include_once '../../action/Action.php';
  11. include_once '../../action/rss/SaveBookmarkAction.php';
  12. include_once '../../action/rss/DeleteBookmarkAction.php';
  13. define("SCRAPER_URL", SERVER_HOST_AND_PATH . "php/scraper/kinoto/");
  14. if(isset ($_GET["params"])) {
  15. $title = base64_decode($_GET["title"]);
  16. $params = base64_decode($_GET["params"]);
  17. $host = base64_decode($_GET["host"]);
  18. $image = base64_decode($_GET["image"]);
  19. $template = new KinotoTemplate();
  20. $template->setMovieTitle($title);
  21. $template->setImage($image);
  22. $url = "http://kino.to/aGET/Mirror/" . str_replace("&amp;", "&", $params);
  23. switch($host) {
  24. case "Megavideo.com";
  25. addMegavideoLink($template,$url);
  26. break;
  27. case "Bitload.com (Flash)";
  28. addBitloadLink($template,$url);
  29. break;
  30. case "Bitload.com (DivX)";
  31. addBitloadDivxLink($template,$url);
  32. break;
  33. case "Various (Flash)":
  34. addNovamovLink($template,$url);
  35. break;
  36. case "Archiv.to (Flash)":
  37. addArchivToFlash($template,$url);
  38. break;
  39. case "Archiv.to (DivX)":
  40. addArchivToDivx($template,$url);
  41. break;
  42. }
  43. $template->generateView(KinotoTemplate::VIEW_PLAY);
  44. }
  45. function addMegavideoLink($template,$url) {
  46. // ADD &PartNo=1
  47. $content = file_get_contents($url,false,getExplorerContext( getSiteHash() ) );
  48. $content = str_replace( "\\", "", $content);
  49. //Get movie files
  50. preg_match_all("/PartNo=(.*)\"/U", $content, $parts, PREG_SET_ORDER);
  51. if($parts) {
  52. foreach ($parts as $part) {
  53. $content = file_get_contents($url."&PartNo=".$part[1],false,getExplorerContext(getSiteHash()));
  54. $content = str_replace( "\\", "", $content);
  55. preg_match("|www.megavideo.com\/v\/(.*)\"|U", $content, $links);
  56. if($links) {
  57. $megavideo_id = $links[1];
  58. if( COOKIE_STATE_ACTIVATED && $megavideo_id ) {
  59. $array = VideoUtil::generateMegavideoPremiumLink($megavideo_id);
  60. if($array) {
  61. $template->addMediaItem(
  62. $array[0],
  63. "",
  64. $array[1],
  65. "",
  66. $array[2]
  67. );
  68. }
  69. }
  70. }
  71. }
  72. }else {
  73. preg_match("|www.megavideo.com\/v\/(.*)\"|U", $content, $links);
  74. if($links) {
  75. $megavideo_id = $links[1];
  76. if( COOKIE_STATE_ACTIVATED && $megavideo_id ) {
  77. $array = VideoUtil::generateMegavideoPremiumLink($megavideo_id);
  78. if($array) {
  79. $template->addMediaItem(
  80. $array[0],
  81. "",
  82. $array[1],
  83. "",
  84. $array[2]
  85. );
  86. }
  87. }
  88. }
  89. }
  90. }
  91. function addNovamovLink($template,$url) {
  92. $content = file_get_contents($url,false,getExplorerContext(getSiteHash()));
  93. $content = str_replace( "\\", "", $content);
  94. //Get novamov mirror links
  95. preg_match_all("/http\:\/\/www\.novamov\.com\/video\/(.*)\"/U", $content, $parts, PREG_SET_ORDER);
  96. foreach ($parts as $part) {
  97. $content = file_get_contents("http://www.novamov.com/video/" . $part[1] );
  98. //Get final file link
  99. preg_match_all("|s1\.addVariable\(\"file\"\,\"(.*)\"|U", $content, $newLink);
  100. if($newLink) {
  101. $newLink = $newLink[1];
  102. $newLink = $newLink[0];
  103. $template->addMediaItem(
  104. substr($newLink, strrpos($newLink,"/")+1),
  105. "",
  106. $newLink,
  107. "",
  108. VideoUtil::getEnclosureMimetype($newLink)
  109. );
  110. }
  111. }
  112. }
  113. function addArchivToFlash($template,$url) {
  114. $content = file_get_contents($url,false,getExplorerContext(getSiteHash()));
  115. $content = str_replace( "\\", "", $content);
  116. //Get mirror links
  117. if (preg_match_all("/http\:\/\/archiv\.to\/GET\/(.*)\"/U", $content, $parts2, PREG_SET_ORDER)){
  118. foreach ($parts2 as $part2) {
  119. $content = file_get_contents("http://archiv.to/GET/".$part2[1]);
  120. //$content = strstr($content,"</object>");
  121. //Get final file link
  122. preg_match("/value=\"file=(.*)\&(.*)\"/U", $content, $link);
  123. if($link) {
  124. $link = $link[1];
  125. $template->addMediaItem(
  126. substr($link, strrpos($link,"/")+1),
  127. "",
  128. $link,
  129. "",
  130. VideoUtil::getEnclosureMimetype($link)
  131. );
  132. }
  133. }
  134. }
  135. else{
  136. preg_match_all("/http\:\/\/archiv\.to\/view\/flv\/(.*)\"/U", $content, $parts, PREG_SET_ORDER);
  137. foreach ($parts as $part) {
  138. $content = file_get_contents("http://archiv.to/view/flv/".$part[1]);
  139. //$content = strstr($content,"</object>");
  140. //Get final file link
  141. preg_match("/value=\"file=(.*)\&(.*)\"/U", $content, $link);
  142. if($link) {
  143. $link = $link[1];
  144. $template->addMediaItem(
  145. substr($link, strrpos($link,"/")+1),
  146. "",
  147. $link,
  148. "",
  149. VideoUtil::getEnclosureMimetype($link)
  150. );
  151. }
  152. }
  153. }
  154. }
  155. function addArchivToDivx($template,$url) {
  156. $content = file_get_contents($url,false,getExplorerContext(getSiteHash()));
  157. $content = str_replace( "\\", "", $content);
  158. if (preg_match_all("/http\:\/\/archiv\.to\/GET\/(.*)\"/U", $content, $parts2, PREG_SET_ORDER)){
  159. foreach ($parts2 as $part2) {
  160. $content = file_get_contents("http://archiv.to/GET/".$part2[1]);
  161. //$content = strstr($content,"</object>");
  162. //Get final file link
  163. preg_match("/value=\"(.*)\" name=\"src\"/U", $content, $link);
  164. if($link) {
  165. $link = $link[1];
  166. $template->addMediaItem(
  167. substr($link, strrpos($link,"/")+1),
  168. "",
  169. $link,
  170. "",
  171. VideoUtil::getEnclosureMimetype($link)
  172. );
  173. }
  174. }
  175. }
  176. else {
  177. //Get mirror links
  178. preg_match_all("/http\:\/\/archiv\.to\/view\/divx\/(.*)\"/U", $content, $parts, PREG_SET_ORDER);
  179. foreach ($parts as $part) {
  180. $content = file_get_contents("http://archiv.to/view/divx/".$part[1]);
  181. //$content = strstr($content,"</object>");
  182. //Get final file link
  183. preg_match("/value=\"(.*)\" name=\"src\"/U", $content, $link);
  184. if($link) {
  185. $link = $link[1];
  186. $template->addMediaItem(
  187. substr($link, strrpos($link,"/")+1),
  188. "",
  189. $link,
  190. "",
  191. VideoUtil::getEnclosureMimetype($link)
  192. );
  193. }
  194. }
  195. }
  196. }
  197. function addBitloadLink($template,$url) {
  198. $content = file_get_contents($url,false,getExplorerContext(getSiteHash()));
  199. $content = str_replace( "\\", "", $content);
  200. if (preg_match_all("/http\:\/\/www\.mystream\.to\/file-(.*)-(.*)-(.*)\"/U", $content, $parts2, PREG_SET_ORDER)){
  201. foreach ($parts2 as $part2) {
  202. $content = getHeadersFlash('http://www.bitload.com/f/'.$part2[1]."/".$part2[2].'?m=def&c=free');
  203. preg_match("/Set-Cookie: PHPSESSID=(.*); path=\//", $headers[4], $sessionid);
  204. $content = file_get_contents("http://www.bitload.com/f/".$part2[1]."/".$part2[2]."?m=def&c=free&PHPSESSID=".$sessionid);
  205. //Get final file link
  206. preg_match_all("/autoPlay\":false,\"url\"\:\"(.*)\"/U", $content, $newLink);
  207. if($newLink) {
  208. $newLink = $newLink[1];
  209. $newLink = $newLink[0];
  210. $template->addMediaItem(
  211. substr($newLink, strrpos($newLink,"/")+1),
  212. "",
  213. $newLink,
  214. "",
  215. VideoUtil::getEnclosureMimetype($newLink)
  216. );
  217. }
  218. }
  219. }
  220. else {
  221. preg_match_all("/http\:\/\/www\.bitload\.com\/f\/(.*)\"/U", $content, $parts, PREG_SET_ORDER);
  222. foreach ($parts as $part) {
  223. $content = getHeadersFlash('http://www.bitload.com/f/'.$part[1].'?m=def&c=free');
  224. preg_match("/Set-Cookie: PHPSESSID=(.*); path=\//", $headers[4], $sessionid);
  225. $content = file_get_contents("http://www.bitload.com/f/".$part[1]."?m=def&c=free&PHPSESSID=".$sessionid);
  226. //Get final file link
  227. preg_match_all("/autoPlay\":false,\"url\"\:\"(.*)\"/U", $content, $newLink);
  228. if($newLink) {
  229. $newLink = $newLink[1];
  230. $newLink = $newLink[0];
  231. $template->addMediaItem(
  232. substr($newLink, strrpos($newLink,"/")+1),
  233. "",
  234. $newLink,
  235. "",
  236. VideoUtil::getEnclosureMimetype($newLink)
  237. );
  238. }
  239. }
  240. }
  241. }
  242. function addBitloadDivxLink($template,$url) {
  243. $content = file_get_contents($url,false,getExplorerContext(getSiteHash()));
  244. $content = str_replace( "\\", "", $content);
  245. if (preg_match_all("/http\:\/\/www\.mystream\.to\/file-(.*)-(.*)-(.*)\"/U", $content, $parts2, PREG_SET_ORDER)){
  246. foreach ($parts2 as $part2) {
  247. $content = getHeadersDivx('http://www.bitload.com/d/'.$part2[1]."/".$part2[2].'?m=def&c=free');
  248. preg_match("/Set-Cookie: PHPSESSID=(.*); path=\//", $headers[4], $sessionid);
  249. $content = file_get_contents("http://www.bitload.com/d/".$part2[1]."/".$part2[2]."?m=def&c=free&PHPSESSID=".$sessionid);
  250. //Get final file link
  251. preg_match_all("/var url = \'(.*)\'/U", $content, $newLink);
  252. if($newLink) {
  253. $newLink = $newLink[1];
  254. $newLink = $newLink[0];
  255. $template->addMediaItem(
  256. substr($newLink, strrpos($newLink,"/")+1),
  257. "",
  258. $newLink,
  259. "",
  260. VideoUtil::getEnclosureMimetype($newLink)
  261. );
  262. }
  263. }
  264. }
  265. else {
  266. preg_match_all("/http\:\/\/www\.bitload\.com\/d\/(.*)\"/U", $content, $parts, PREG_SET_ORDER);
  267. foreach ($parts as $part) {
  268. $content = getHeadersDivx('http://www.bitload.com/d/'.$part[1].'?m=def&c=free');
  269. preg_match("/Set-Cookie: PHPSESSID=(.*); path=\//", $headers[4], $sessionid);
  270. $content = file_get_contents("http://www.bitload.com/d/".$part[1]."?m=def&c=free&PHPSESSID=".$sessionid);
  271. //var_dump($content);
  272. //Get final file link
  273. preg_match_all("/var url = \'(.*)\'/U", $content, $newLink);
  274. //var_dump($newLink);
  275. if($newLink) {
  276. $newLink = $newLink[1];
  277. $newLink = $newLink[0];
  278. $template->addMediaItem(
  279. substr($newLink, strrpos($newLink,"/")+1),
  280. "",
  281. $newLink,
  282. "",
  283. VideoUtil::getEnclosureMimetype($newLink)
  284. );
  285. }
  286. }
  287. }
  288. }
  289. /**
  290. * Create connection context to file_get_contents.
  291. */
  292. function getExplorerContext($hash) {
  293. $opts = array(
  294. 'http'=>array(
  295. 'method'=>"GET",
  296. 'header'=> "Host: kino.to\r\n".
  297. "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10 (.NET CLR 3.5.30729)\r\n".
  298. "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n".
  299. "Accept-Language: es-es,es;q=0.8,en-us;q=0.5,en;q=0.3\r\n".
  300. "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n".
  301. "Keep-Alive: 115\r\n".
  302. "Connection: keep-alive\r\n".
  303. "Cookie: AutoLangTry=Y; PageLang=2; sitechrx=" . $hash . "; NewsHideInfoMsg=0; NewsListMode=genre; NewsGroupLimit=100; ListDisplayYears=Never; ListRating=Off; DataTables_RsltTable_genre2=%7B%22iStart%22%3A%200%2C%22iEnd%22%3A%2025%2C%22iLength%22%3A%2025%2C%22sFilter%22%3A%20%22%22%2C%22sFilterEsc%22%3A%20true%2C%22aaSorting%22%3A%20%5B%5D%2C%22aaSearchCols%22%3A%20%5B%20%5B''%2Ctrue%5D%2C%5B''%2Ctrue%5D%2C%5B''%2Ctrue%5D%2C%5B''%2Ctrue%5D%2C%5B''%2Ctrue%5D%2C%5B''%2Ctrue%5D%2C%5B''%2Ctrue%5D%5D%2C%22abVisCols%22%3A%20%5B%20true%2Ctrue%2Ctrue%2Ctrue%2Ctrue%2Ctrue%2Ctrue%5D%7D\r\n"
  304. )
  305. );
  306. //"Cookie: sitechrx=" . $hash . ";Path=/;\r\n"
  307. $context = stream_context_create($opts);
  308. return $context;
  309. }
  310. function getSiteHash() {
  311. if( isset ($_SESSION["hash"])) {
  312. $hash = $_SESSION["hash"];
  313. }else {
  314. $content = file_get_contents("http://kino.to",false,hashContext(false));
  315. preg_match("/src=\"(.*)\"/U", $content, $js);
  316. preg_match("/scf\(\'(.*)\'\,\'\/\'\)/U", $content, $scf);
  317. $content = file_get_contents("http://kino.to".$js[1],false,hashContext(true));
  318. preg_match("/escape\(hsh \+ \"(.*)\"\)/U", $content, $hsh);
  319. $hash = $scf[1] . $hsh[1];
  320. }
  321. $_SESSION["hash"] = $hash;
  322. return $hash;
  323. }
  324. function hashContext($referer) {
  325. $opts = array(
  326. 'http'=>array(
  327. 'method'=>"GET",
  328. 'header'=> "Host: kino.to\r\n".
  329. "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; es-ES; rv:1.9.2.9) Gecko/20100824 Firefox/3.6.9\r\n".
  330. "Accept: */*\r\n".
  331. "Accept-Language: es-es,es;q=0.8,en-us;q=0.5,en;q=0.3\r\n".
  332. "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n".
  333. "Keep-Alive: 115\r\n".
  334. ( $referer ? "Referer: http://kino.to/Genre.html\r\n" : "" ).
  335. "Cookie: AutoLangTry=Y\r\n"
  336. )
  337. );
  338. $context = stream_context_create($opts);
  339. return $context;
  340. }
  341. function getHeadersFlash($url)
  342. {
  343. $path = parse_url($url);
  344. if (isset($path['query']))
  345. {
  346. $path['path'] .= '?' . $path['query'];
  347. }
  348. if (!isset($path['port']))
  349. {
  350. $path['port'] = 80;
  351. }
  352. $request = "HEAD " . $path['path']. " HTTP/1.1\r\n";
  353. $request .= "Host: " . $path['host'] . "\r\n";
  354. $request .= "Content-type: application/x-www-form-urlencoded\r\n";
  355. $request .= "Cache-Control: no-cache\r\n";
  356. $request .= "User-Agent: MSIE\r\n";
  357. $request .= "Connection: close\r\n";
  358. $request .= "\r\n";
  359. $f = fsockopen($path['host'], $path['port'], $errno, $errstr);
  360. if ($f)
  361. {
  362. fputs($f, $request);
  363. while (!feof($f))
  364. {
  365. $headers[] = fgets($f);
  366. }
  367. preg_match("/Set-Cookie: PHPSESSID=(.*); path=\//", $headers[4], $sessionid);
  368. //var_dump(headers[4]);
  369. $content = file_get_contents($url."&PHPSESSID=".$sessionid);
  370. //var_dump($content);
  371. fclose($f);
  372. }
  373. return $content;
  374. return $headers;
  375. }
  376. function getHeadersDivx($url)
  377. {
  378. $path = parse_url($url);
  379. if (isset($path['query']))
  380. {
  381. $path['path'] .= '?' . $path['query'];
  382. }
  383. if (!isset($path['port']))
  384. {
  385. $path['port'] = 80;
  386. }
  387. $request = "HEAD " . $path['path']. " HTTP/1.1\r\n";
  388. $request .= "Host: " . $path['host'] . "\r\n";
  389. $request .= "Content-type: application/x-www-form-urlencoded\r\n";
  390. $request .= "Cache-Control: no-cache\r\n";
  391. $request .= "User-Agent: MSIE\r\n";
  392. $request .= "Connection: close\r\n";
  393. $request .= "\r\n";
  394. $f = fsockopen($path['host'], $path['port'], $errno, $errstr);
  395. if ($f)
  396. {
  397. fputs($f, $request);
  398. while (!feof($f))
  399. {
  400. $headers[] = fgets($f);
  401. }
  402. preg_match("/Set-Cookie: PHPSESSID=(.*); path=\//", $headers[4], $sessionid);
  403. //var_dump(headers[4]);
  404. $content = file_get_contents($url."&PHPSESSID=".$sessionid);
  405. //var_dump($content);
  406. fclose($f);
  407. }
  408. return $content;
  409. return $headers;
  410. }
  411. ?>