PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://eboda-hd-for-all-500.googlecode.com/
PHP | 469 lines | 365 code | 49 blank | 55 comment | 33 complexity | fddd7d58b373524d73f73e28ed6b8b01 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 'KinoToUtil.php';
  9. include_once "../../util/VideoUtil.php";
  10. include_once "../../util/RssScriptUtil.php";
  11. include_once '../../action/Action.php';
  12. include_once '../../action/rss/SaveBookmarkAction.php';
  13. include_once '../../action/rss/DeleteBookmarkAction.php';
  14. define("SCRAPER_URL", SERVER_HOST_AND_PATH . "php/scraper/kinoto/");
  15. //Start session
  16. if(isset($_GET["PHPSESID"])) {
  17. session_id($_GET["PHPSESID"]);
  18. }
  19. session_start();
  20. //Filter user action and redirect to scrap function
  21. if( isset($_GET["search"]) ) {
  22. $type = $_GET["search"];
  23. $pageTitle = base64_decode($_GET["title"]);
  24. fetchSearch($type,$pageTitle);
  25. }else if( isset($_GET["letter"]) ) {
  26. $type = base64_decode($_GET["type"]);
  27. $letter = $_GET["letter"];
  28. $pageTitle = base64_decode($_GET["title"]);
  29. fetchCategoryItems($type,$letter,$pageTitle);
  30. }else if( isset($_GET["type"]) ) {
  31. $type = base64_decode($_GET["type"]);
  32. $pageTitle = base64_decode($_GET["title"]);
  33. if($type == "nov") {
  34. fetchCategoryNewest();
  35. }else if($type == "pop") {
  36. fetchCategoryPopular();
  37. }else if($type == "est") {
  38. fetchCategoryFirstRun();
  39. }else if($type == "doc") {
  40. fetchCategoryFirstRun();
  41. }else {
  42. fetchCategoryLetters($type,$pageTitle);
  43. }
  44. }else if(isset($_GET["item"])) {
  45. $item = base64_decode($_GET["item"]);
  46. $title = base64_decode($_GET["title"]);
  47. fetchMovie($item,$title);
  48. }else {
  49. fetchCategories();
  50. }
  51. //------------------------------------------------------------------------------
  52. //------------------------------------------------------------------------------
  53. /**
  54. * Show category list.
  55. */
  56. function fetchCategories() {
  57. $template = new KinotoTemplate();
  58. //Get site cookie hash
  59. $hash = getSiteHash();
  60. //Get principal page and parse categories side bar
  61. $content = file_get_contents("http://kino.to/Genre.html",false,getExplorerContext($hash));
  62. //$newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
  63. //$content = str_replace($newlines, "", utf8_decode( $content) );
  64. preg_match_all("/<td class\=\"Title\"><a href\=\"(.*)\">(.*)<\/a><\/td>/U", $content, $div, PREG_SET_ORDER);
  65. $template->setSearch( array(
  66. resourceString("search_by") . "...",
  67. resourceString("search_by") . "...",
  68. "rss_command://search",
  69. SCRAPER_URL . "movies.php?search=%s" . URL_AMP . "title=" . base64_encode(resourceString("search_by") . "...") . URL_AMP . "PHPSESID=" . session_id(),
  70. ""
  71. )
  72. );
  73. $template->addItem(
  74. "Kinofilme",
  75. "",
  76. SCRAPER_URL . "movies.php?type=" . base64_encode("est") . URL_AMP . "title=" . base64_encode($link[2]) . URL_AMP . "PHPSESID=" . session_id(),
  77. ""
  78. );
  79. $template->addItem(
  80. "Popular",
  81. "",
  82. SCRAPER_URL . "movies.php?type=" . base64_encode("pop") . URL_AMP . "title=" . base64_encode($link[2]) . URL_AMP . "PHPSESID=" . session_id(),
  83. ""
  84. );
  85. $template->addItem(
  86. "Neuste Filme",
  87. "",
  88. SCRAPER_URL . "movies.php?type=" . base64_encode("nov") . URL_AMP . "title=" . base64_encode($link[2]) . URL_AMP . "PHPSESID=" . session_id(),
  89. ""
  90. );
  91. foreach ($div as $link) {
  92. $template->addItem(
  93. utf8_decode($link[2]),
  94. "",
  95. SCRAPER_URL . "movies.php?type=" . base64_encode("http://kino.to".$link[1]) . URL_AMP . "title=" . base64_encode($link[2]) . URL_AMP . "PHPSESID=" . session_id(),
  96. ""
  97. );
  98. }
  99. $template->generateView(KinotoTemplate::VIEW_CATEGORY, "kino.to" );
  100. }
  101. /**
  102. * Show newest category movies.
  103. */
  104. function fetchCategoryNewest() {
  105. $template = new KinotoTemplate();
  106. $content = file_get_contents("http://kino.to/Movies.rss",false,getExplorerContext(getSiteHash()));
  107. $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
  108. $content = str_replace($newlines, "", html_entity_decode($content));
  109. preg_match_all("/<title><\!\[CDATA\[(.*)\]\]><\/title>(.*)<link>(.*)<\/link>(.*)src=\"(.*)\"/siU", $content, $links, PREG_SET_ORDER);
  110. foreach ($links as $link) {
  111. $template->addItem(
  112. utf8_decode(html_entity_decode($link[1], ENT_COMPAT, "UTF-8")),
  113. "",
  114. SCRAPER_URL . "movies.php?item=" . base64_encode($link[3]) . URL_AMP . "title=" . base64_encode($link[1]) . URL_AMP . "PHPSESID=" . session_id(),
  115. $link[5]
  116. );
  117. }
  118. $template->generateView(KinotoTemplate::VIEW_MOVIE, "");
  119. }
  120. /**
  121. * Show popular category movies.
  122. */
  123. function fetchCategoryPopular() {
  124. $template = new KinotoTemplate();
  125. $content = file_get_contents("http://kino.to/Popular-Movies.html",false,getExplorerContext(getSiteHash()));
  126. preg_match_all("/<a onclick\=\"return false;\" href\=\"(.*)\">(.*)<\/a>/U", $content, $links, PREG_SET_ORDER);
  127. if($links) {
  128. foreach ($links as $value) {
  129. $template->addItem(
  130. utf8_decode($value[2]),
  131. "",
  132. SCRAPER_URL . "movies.php?item=" . base64_encode($value[1]) . URL_AMP . "title=" . base64_encode($value[2]) . URL_AMP . "PHPSESID=" . session_id(),
  133. ""
  134. );
  135. }
  136. }
  137. $template->generateView(KinotoTemplate::VIEW_MOVIE, "");
  138. }
  139. /**
  140. * Show first run category movies.
  141. */
  142. function fetchCategoryFirstRun() {
  143. $template = new KinotoTemplate();
  144. $content = file_get_contents("http://kino.to/Cine-Films.rss",false,getExplorerContext(getSiteHash()));
  145. $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
  146. $content = str_replace($newlines, "", html_entity_decode($content));
  147. preg_match_all("/<title><\!\[CDATA\[(.*)\]\]><\/title>(.*)<link>(.*)<\/link>(.*)src=\"(.*)\"/siU", $content, $links, PREG_SET_ORDER);
  148. foreach ($links as $link) {
  149. $template->addItem(
  150. utf8_decode($link[1]),
  151. "",
  152. SCRAPER_URL . "movies.php?item=" . base64_encode($link[3]) . URL_AMP . "title=" . base64_encode($link[1]) . URL_AMP . "PHPSESID=" . session_id(),
  153. $link[5]
  154. );
  155. }
  156. $template->generateView(KinotoTemplate::VIEW_MOVIE, "");
  157. }
  158. /**
  159. * Get search found items.
  160. */
  161. function fetchSearch($type,$title) {
  162. $template = new KinotoTemplate();
  163. $content = file_get_contents("http://kino.to/Search.html?q=".$type,false,getExplorerContext(getSiteHash()));
  164. preg_match_all("/(.*).png(.*)<a onclick\=\"return false;\" href\=\"(.*)\">(.*)<\/a>/U", $content, $links, PREG_SET_ORDER);
  165. if($links) {
  166. foreach ($links as $value) {
  167. $template->addItem(
  168. html_entity_decode(utf8_decode($value[4])),
  169. "",
  170. SCRAPER_URL . "movies.php?item=" . base64_encode($value[3]) . URL_AMP . "title=" . base64_encode($value[4]) . URL_AMP . "PHPSESID=" . session_id(),
  171. ""
  172. );
  173. }
  174. }
  175. $template->generateView(KinotoTemplate::VIEW_MOVIE, "");
  176. }
  177. /**
  178. * Print category letter list on screen.
  179. */
  180. function fetchCategoryLetters($type,$title) {
  181. $template = new KinotoTemplate();
  182. $letters = array(
  183. "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","0"
  184. );
  185. foreach ($letters as $letter) {
  186. $template->addItem(
  187. $letter,
  188. resourceString("goto_letter") . $letter,
  189. SCRAPER_URL . "movies.php?type=" . base64_encode($type) . URL_AMP . "letter=" . $letter . URL_AMP . "title=" . base64_encode($title) . URL_AMP . "PHPSESID=" . session_id(),
  190. ""
  191. );
  192. }
  193. $template->generateView(KinotoTemplate::VIEW_PAGE_NUMBERS );
  194. }
  195. /**
  196. * Get category movies and pages.
  197. */
  198. function fetchCategoryItems($type,$letter,$title) {
  199. $template = new KinotoTemplate();
  200. $template->setType($type);
  201. $template->setLetter($letter);
  202. //If page equal "x" goto page number list, in other case process actual category page
  203. if( isset($_GET["page"]) && $_GET["page"] == "x" ) {
  204. $maxPages = $_GET["pages"];
  205. for($i=1;$i<=$maxPages;++$i) {
  206. $template->addItem(
  207. $i,
  208. resourceString("goto_page") . $i,
  209. SCRAPER_URL . "movies.php?type=" . base64_encode($type) . URL_AMP . "letter=" . $letter . URL_AMP . "title=" . base64_encode($title) . URL_AMP . "page=" . $i . URL_AMP . "pages=" . $maxPages . URL_AMP . "PHPSESID=" . session_id(),
  210. ""
  211. );
  212. }
  213. $template->generateView(KinotoTemplate::VIEW_PAGE_NUMBERS );
  214. }else {
  215. if(!isset($_GET["page"])) {
  216. $pages = getPages($type,$letter);
  217. $template->setActualPage(1);
  218. $template->setMaxPages($pages[1]);
  219. $content = $pages[0];
  220. }else {
  221. $page = $_GET["page"];
  222. $template->setActualPage($_GET["page"]);
  223. $template->setMaxPages($_GET["pages"]);
  224. $content = file_get_contents(getMovieListLink($type,$letter,$page),false,getExplorerContext(getSiteHash()));
  225. }
  226. //Remove backslashes
  227. $content = str_replace( "\\", "", $content);
  228. //var_dump($content);
  229. preg_match_all("/(movie|documentation)\",\"<a href=\"\/(.*)\" title=\"(.*)\" onclick=\"return false;\">(.*)<\/a>/U", $content, $links, PREG_SET_ORDER);
  230. //var_dump($links);
  231. if($links) {
  232. foreach ($links as $value) {
  233. $itemUrl = "/".$value[2];
  234. if( strpos($itemUrl, '"')){
  235. $itemUrl = substr($itemUrl, 0, strpos($itemUrl, '"'));
  236. }
  237. $template->addItem(
  238. html_entity_decode($value[3],ENT_QUOTES,"UTF-8"),
  239. "",
  240. SCRAPER_URL . "movies.php?title=" . base64_encode($value[3]) . URL_AMP . "item=" . base64_encode($itemUrl) . URL_AMP . "PHPSESID=" . session_id(),
  241. ""
  242. );
  243. }
  244. $template->generateView(KinotoTemplate::VIEW_MOVIE, "");
  245. }
  246. }
  247. }
  248. /**
  249. * Get movie host mirrors.
  250. */
  251. function fetchMovie($item,$title) {
  252. $template = new KinotoTemplate();
  253. $template->setMovieTitle($title);
  254. //Parse movie page
  255. if(!strpos($item,"//kino.to")) {
  256. $item = "http://kino.to" . $item;
  257. }
  258. $content = file_get_contents($item,false,getExplorerContext(getSiteHash()));
  259. //Get image
  260. preg_match("/<div class=\"Grahpics\">(.*)src=\"(.*)\"/U", $content, $image);
  261. $image = $image[2];
  262. $template->setImage($image);
  263. //Get description
  264. $description = strstr($content,"Descriptore");
  265. $description = strstr($description,">");
  266. $description = substr($description, 1, strpos($description, "<")-1);
  267. $template->setDescription(html_entity_decode($description,ENT_QUOTES));
  268. //Get Mirror list
  269. $mirrorList = strstr($content,"HosterList");
  270. $mirrorList = substr($mirrorList, 0, strpos($mirrorList, "</ul>"));
  271. preg_match_all("|rel\=\"(.*)\"(.*)<div class\=\"Named\">(.*)<\/div>|U", $mirrorList, $mirrors, PREG_SET_ORDER);
  272. foreach ($mirrors as $mirror) {
  273. if( ($mirror[3] == "Megavideo.com") ||
  274. ($mirror[3] == "Bitload.com (Flash)") ||
  275. ($mirror[3] == "Bitload.com (DivX)") ||
  276. ($mirror[3] == "Various (Flash)") ||
  277. ($mirror[3] == "Archiv.to (DivX)") ||
  278. ($mirror[3] == "Archiv.to (Flash)")
  279. ) {
  280. $template->addItem(
  281. $mirror[3],
  282. "",
  283. SCRAPER_URL . "moviesPreLink.php?params=" . base64_encode($mirror[1]) . URL_AMP . "host=" . base64_encode($mirror[3]) . URL_AMP .
  284. "title=" . base64_encode($title) . URL_AMP . "image=" . base64_encode($image) . URL_AMP . "PHPSESID=" . session_id(),
  285. ""
  286. );
  287. }
  288. }
  289. $template->generateView(KinotoTemplate::VIEW_MOVIE_DETAIL);
  290. }
  291. //------------------------------------------------------------------------------
  292. //------------------------------------------------------------------------------
  293. /**
  294. * Get number of pages and retrieve first page content.
  295. */
  296. function getPages($url,$letter) {
  297. $content = file_get_contents(getMovieListLink($url,$letter),false,getExplorerContext(getSiteHash()));
  298. //Get letter number of entries
  299. preg_match("/\"iTotalDisplayRecords\":\"(.*)\"/U", $content, $numberEntries);
  300. if($numberEntries) {
  301. $numPages = ceil($numberEntries[1] / 25);
  302. }else {
  303. $numPages = 0;
  304. }
  305. $content = str_replace(
  306. array("\\u00e4","\\u00eb","\\u00ef","\\u00f6","\\u00fc","\\u00c4","\\u00cb","\\u00cf","\\u00d6","\\u00dc","\\u00df"),
  307. array("ä","ë","ï","ö","ü","Ä","Ë","Ï","Ö","Ü","ß"),
  308. $content);
  309. return array(utf8_decode($content),$numPages);
  310. }
  311. /**
  312. * Generate link to get movie list content.
  313. */
  314. function getMovieListLink($url,$letter,$page=null) {
  315. $genreId = substr($url, strrpos($url,"/")+1);
  316. //var_dump($genreId);
  317. switch ($genreId) {
  318. case "Action":
  319. $genreId = "2";
  320. break;
  321. case "Adventure":
  322. $genreId = "12";
  323. break;
  324. case "Animation":
  325. $genreId = "13";
  326. break;
  327. case "Anime":
  328. $genreId = "21";
  329. break;
  330. case "Comedy":
  331. $genreId = "16";
  332. break;
  333. case "Crime":
  334. $genreId = "14";
  335. break;
  336. case "Documentation":
  337. $genreId = "9";
  338. break;
  339. case "Drama":
  340. $genreId = "7";
  341. break;
  342. case "Family":
  343. $genreId = "24";
  344. break;
  345. case "Fantasy":
  346. $genreId = "11";
  347. break;
  348. case "History":
  349. $genreId = "15";
  350. break;
  351. case "Horror":
  352. $genreId = "6";
  353. break;
  354. case "Kids":
  355. $genreId = "19";
  356. break;
  357. case "Martial+Arts":
  358. $genreId = "26";
  359. break;
  360. case "Music":
  361. $genreId = "17";
  362. break;
  363. case "Mystery":
  364. $genreId = "23";
  365. break;
  366. case "Romance":
  367. $genreId = "20";
  368. break;
  369. case "Satire":
  370. $genreId = "1";
  371. break;
  372. case "Science+Fiction":
  373. $genreId = "10";
  374. break;
  375. case "Short-Film":
  376. $genreId = "27";
  377. break;
  378. case "Sport":
  379. $genreId = "22";
  380. break;
  381. case "StandUp":
  382. $genreId = "4";
  383. break;
  384. case "Thriller":
  385. $genreId = "8";
  386. break;
  387. case "War":
  388. $genreId = "18";
  389. break;
  390. case "Western":
  391. $genreId = "5";
  392. break;
  393. }
  394. if(!$page) {
  395. $page = 0;
  396. }
  397. //Create url to get data
  398. return "http://kino.to/aGET/List/?".
  399. "sEcho=1" .
  400. "&iColumns=7" .
  401. "&sColumns=".
  402. "&iDisplayStart=" . ($page-1)*25 .
  403. "&iDisplayLength=25".
  404. "&iSortingCols=1" .
  405. "&iSortCol_0=2" .
  406. "&sSortDir_0=asc" .
  407. "&bSortable_0=true" .
  408. "&bSortable_1=true" .
  409. "&bSortable_2=true" .
  410. "&bSortable_3=false".
  411. "&bSortable_4=false" .
  412. "&bSortable_5=false" .
  413. "&bSortable_6=true" .
  414. "&additional=%7B%22foo%22%3A%22bar%22%2C%22fGenre%22%3A" .
  415. $genreId .
  416. "%2C%22fType%22%3A%22%22%2C%22fLetter%22%3A%22" .
  417. $letter .
  418. "%22%7D";
  419. }
  420. ?>