PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/scripts/feeds/xVoD/xVoD/php/scraper/cinetube/anime.php

http://eboda-hd-for-all-500.googlecode.com/
PHP | 838 lines | 705 code | 62 blank | 71 comment | 62 complexity | 80d56b7b24c06d1f4b6e21a3f1e09d7c 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 'CinetubeAnimeTemplate.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/cinetube/");
  14. define("CINETUBE_URL", "http://www.cinetube.es/" );
  15. //Init session
  16. if(isset($_GET["PHPSESID"])) {
  17. session_id($_GET["PHPSESID"]);
  18. }
  19. session_start();
  20. //Parse user actions
  21. if(isset($_GET["search"])) { //Search view
  22. $type = $_GET["type"];
  23. $search = $_GET["search"];
  24. switch($type) {
  25. case "mov":
  26. fetchMovieSearch($type,$search);
  27. break;
  28. case "ser":
  29. fetchSerieSearch($type,$search);
  30. break;
  31. }
  32. }else if(isset($_GET["play"])) { // Show play links --------------------------
  33. $type = $_GET["type"];
  34. $play = base64_decode($_GET["play"]);
  35. //$title = base64_decode($_GET["title"]);
  36. fetchPlaySources($type,$play);
  37. }else if(isset($_GET["episode"])) { // Show serie season episode links -------
  38. $type = $_GET["type"];
  39. $episodeLink = base64_decode($_GET["episode"]);
  40. $episodeName = base64_decode($_GET["episodeName"]);
  41. fetchSerieSeasonEpisode($type, $episodeName,$episodeLink);
  42. }else if(isset($_GET["season"])) { // Show serie season episodes--------------
  43. $type = $_GET["type"];
  44. $season = base64_decode($_GET["season"]);
  45. fetchSerieSeason($type, $season);
  46. }else if(isset($_GET["item"])) { // Show items ------------------------------
  47. $type = $_GET["type"];
  48. $item = base64_decode($_GET["item"]);
  49. $title = base64_decode($_GET["title"]);
  50. switch($type) {
  51. case "mov":
  52. fetchMovie($type,$item,$title);
  53. break;
  54. case "ser":
  55. fetchSerie($type,$item,$title);
  56. break;
  57. }
  58. }else if(isset($_GET["cat"])) { //Category view ----------------------------
  59. $type = $_GET["type"];
  60. $category = base64_decode($_GET["cat"]);
  61. $title = base64_decode($_GET["title"]);
  62. switch($type) {
  63. case "mov":
  64. fetchMovieCategoryItems($type,$category,$title);
  65. break;
  66. case "ser":
  67. fetchSerieCategoryItems($type,$category,$title);
  68. break;
  69. }
  70. }else if(isset($_GET["type"])) { // Category list view ---------------------
  71. $type = $_GET["type"];
  72. fetchCategories($type);
  73. }else { // Show home principal view ---------------------------------------
  74. fetchHome();
  75. }
  76. //------------------------------------------------------------------------------
  77. //------------------------------------------------------------------------------
  78. //------------------------------------------------------------------------------
  79. function fetchHome() {
  80. $template = new CinetubeAnimeTemplate();
  81. $template->addItem(
  82. resourceString("movie")."s",
  83. resourceString("movie")."s",
  84. SCRAPER_URL . "anime.php?type=mov",
  85. ""
  86. );
  87. $template->addItem(
  88. resourceString("serie")."s",
  89. resourceString("serie")."s",
  90. SCRAPER_URL . "anime.php?type=ser",
  91. ""
  92. );
  93. $template->generateView(CinetubeAnimeTemplate::VIEW_HOME, "Cinetube - Anime");
  94. }
  95. //------------------------------------------------------------------------------
  96. //------------------------------------------------------------------------------
  97. function fetchCategories($type) {
  98. $template = new CinetubeAnimeTemplate();
  99. $template->setType($type);
  100. //Search link
  101. $template->setSearch( array(
  102. resourceString("search_by") . "...",
  103. resourceString("search_by") . "...",
  104. "rss_command://search",
  105. SCRAPER_URL . "anime.php?search=%s" . URL_AMP . "type=$type" . URL_AMP . "title=" . base64_encode("Search by"),
  106. ""
  107. )
  108. );
  109. //Category links
  110. if($type == "ser") {
  111. $url = "http://www.cinetube.es/series-anime/";
  112. }else {
  113. $url = "http://www.cinetube.es/peliculas-anime/";
  114. }
  115. $content = file_get_contents($url);
  116. $content = html_entity_decode($content);
  117. //Get categories block
  118. preg_match("/<ul class=\"categorias\">(.*)<\/ul>/siU", $content, $matches);
  119. if($matches) {
  120. //Get categories links
  121. preg_match_all("/<a href=\"(.*)\"><span>(.*)</siU", $matches[1], $links, PREG_SET_ORDER);
  122. foreach ($links as $link) {
  123. $template->addItem(
  124. $link[2],
  125. resourceString("category") . " " . $link[2],
  126. SCRAPER_URL . "anime.php?type=$type" . URL_AMP . "cat=" . base64_encode($link[1]) . URL_AMP . "title=" . base64_encode($link[2]) . URL_AMP . "PHPSESID=" . session_id(),
  127. ""
  128. );
  129. }
  130. }
  131. $template->generateView(CinetubeAnimeTemplate::VIEW_CATEGORY, "");
  132. }
  133. //------------------------------------------------------------------------------
  134. //------------------------------------------------------------------------------
  135. /**
  136. * Search movies that contents given word.
  137. */
  138. function fetchMovieSearch($type,$search) {
  139. $template = new CinetubeAnimeTemplate();
  140. $template->setType($type);
  141. $template->setSearchTerm($search);
  142. //If page equal "x" goto page number list, in other case process actual category page
  143. if( isset($_GET["page"]) && $_GET["page"] == "x" ) {
  144. $maxPages = $_GET["pages"];
  145. for($i=1;$i<=$maxPages;++$i) {
  146. $template->addItem(
  147. $i,
  148. resourceString("goto_page") . $i,
  149. SCRAPER_URL . "anime.php?type=" . $type . URL_AMP . "search=" . $search . URL_AMP . "page=" . $i . URL_AMP . "pages=" . $maxPages . URL_AMP . "PHPSESID=" . session_id(),
  150. ""
  151. );
  152. }
  153. $template->generateView(CinetubeAnimeTemplate::VIEW_PAGE_NUMBERS );
  154. }else {
  155. if(!isset($_GET["page"])) {
  156. $pages = getPages($type,$search);
  157. $template->setActualPage(1);
  158. $template->setMaxPages($pages[1]);
  159. $content = $pages[0];
  160. }else {
  161. $template->setActualPage($_GET["page"]);
  162. $template->setMaxPages($_GET["pages"]);
  163. $content = file_get_contents(CINETUBE_URL . $category . "buscar/peliculas-anime/?palabra=" . $search . "&pag=" . $_GET["page"]);
  164. }
  165. //Parse first page movies
  166. preg_match_all("/<div class\=\"peli_item textcenter\">(.*)<\/div>\s*<\/div>/siU", $content, $divs, PREG_SET_ORDER);
  167. if($divs) {
  168. //$divs = $divs[0];
  169. foreach ($divs as $movie) {
  170. $movie = $movie[0];
  171. preg_match_all("/(<a href=\"(.*)\">)*\s*<img\s*src=\"(.*)\" alt=\"(.*)\"\s(\/)*>\s*(<\/a>)*/siU", $movie, $info, PREG_SET_ORDER);
  172. //Get info
  173. parseCoverPageInfo($info,$type,$title,$template,true);
  174. }
  175. }
  176. $template->generateView(CinetubeAnimeTemplate::VIEW_MOVIE, $title);
  177. }
  178. }
  179. /**
  180. * Search series that contents given word.
  181. */
  182. function fetchSerieSearch($type,$search) {
  183. $template = new CinetubeAnimeTemplate();
  184. $template->setType($type);
  185. $template->setSearchTerm($search);
  186. //If page equal "x" goto page number list, in other case process actual category page
  187. if( isset($_GET["page"]) && $_GET["page"] == "x" ) {
  188. $maxPages = $_GET["pages"];
  189. for($i=1;$i<=$maxPages;++$i) {
  190. $template->addItem(
  191. $i,
  192. resourceString("goto_page") . $i,
  193. SCRAPER_URL . "index.php?type=" . $type . URL_AMP . "search=" . $search . URL_AMP . "page=" . $i . URL_AMP . "pages=" . $maxPages . URL_AMP . "PHPSESID=" . session_id(),
  194. ""
  195. );
  196. }
  197. $template->generateView(CinetubeAnimeTemplate::VIEW_PAGE_NUMBERS );
  198. }else {
  199. if(!isset($_GET["page"])) {
  200. $pages = getPages($type,$search);
  201. $template->setActualPage(1);
  202. $template->setMaxPages($pages[1]);
  203. $content = $pages[0];
  204. }else {
  205. $template->setActualPage($_GET["page"]);
  206. $template->setMaxPages($_GET["pages"]);
  207. $content = file_get_contents(CINETUBE_URL . $category . "buscar/series-anime/?palabra=" . $search . "&pag=" . $_GET["page"]);
  208. }
  209. //Parse first page series
  210. $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
  211. $input = str_replace($newlines, "", $content );
  212. preg_match("/<ul class\=\"ver_series_list\">(.*)<\/ul>/siU", $input, $divs);
  213. preg_match_all("/<li>(.*)<\/li>/siU", $divs[0], $divs, PREG_SET_ORDER);
  214. if($divs) {
  215. //$divs = $divs[0];
  216. foreach ($divs as $movie) {
  217. $movie = $movie[1];
  218. preg_match_all("/(<a href=\"(.*)\">)*\s*<img\s*src=\"(.*)\" alt=\"(.*)\"\s(\/)*>\s*(<\/a>)*|<p class\=\"tit_ficha\">(.*)<\/p>/siU", $movie, $info, PREG_SET_ORDER);
  219. //Get info
  220. $movieIcons = array();
  221. foreach( $info as $key => $detail ) {
  222. if( $key == 0 ) {
  223. if( strpos($detail[2],'"') ) {
  224. $movieLink = substr($detail[2], 0, strpos($detail[2],'"'));
  225. }else {
  226. $movieLink = $detail[2];
  227. }
  228. $movieThumbnail = html_entity_decode($detail[3]);
  229. }else if(count($detail) == 8) {
  230. $movieTitle = $detail[7];
  231. }else if($detail[4]) {
  232. if(!strpos($detail[4],"escarga")) {
  233. array_push( $movieIcons, html_entity_decode($detail[4]) );
  234. }
  235. }else {
  236. //megavideo, veoh, tutv, google
  237. array_push( $movieIcons, html_entity_decode(substr($detail[3], strrpos($detail[3], "/")+1, strrpos($detail[3], "\.")-4)) );
  238. }
  239. }
  240. //Add video
  241. $template->addItem(
  242. $movieTitle,
  243. strtoupper(getArrayString($movieIcons).""),
  244. SCRAPER_URL . "anime.php?type=ser" . URL_AMP . "item=" . base64_encode($movieLink) . URL_AMP . "title=" . base64_encode($title) . URL_AMP . "PHPSESID=" . session_id(),
  245. $movieThumbnail
  246. );
  247. }
  248. }
  249. $template->generateView(CinetubeAnimeTemplate::VIEW_SERIE, $title);
  250. }
  251. }
  252. //------------------------------------------------------------------------------
  253. //------------------------------------------------------------------------------
  254. /**
  255. * Get given movie category pages and first page items.
  256. */
  257. function fetchMovieCategoryItems($type,$category,$title) {
  258. $template = new CinetubeAnimeTemplate();
  259. $template->setCategory($category);
  260. $template->setType($type);
  261. //If page equal "x" goto page number list, in other case process actual category page
  262. if( isset($_GET["page"]) && $_GET["page"] == "x" ) {
  263. $maxPages = $_GET["pages"];
  264. for($i=1;$i<=$maxPages;++$i) {
  265. $template->addItem(
  266. $i,
  267. resourceString("goto_page") . $i,
  268. SCRAPER_URL . "anime.php?type=" . $type . URL_AMP . "cat=" . base64_encode($category) . URL_AMP . "page=" . $i . URL_AMP . "pages=" . $maxPages,
  269. ""
  270. );
  271. }
  272. $template->generateView(CinetubeAnimeTemplate::VIEW_PAGE_NUMBERS );
  273. }else {
  274. if(!isset($_GET["page"])) {
  275. $pages = getPages($category);
  276. $template->setActualPage(1);
  277. $template->setMaxPages($pages[1]);
  278. $content = $pages[0];
  279. }else {
  280. $template->setActualPage($_GET["page"]);
  281. $template->setMaxPages($_GET["pages"]);
  282. $content = file_get_contents(CINETUBE_URL . $category . $_GET["page"] . ".html");
  283. }
  284. //Parse first page movies
  285. preg_match_all("/<div class\=\"peli_item textcenter\">(.*)<\/div>\s*<\/div>/siU", $content, $divs, PREG_SET_ORDER);
  286. if($divs) {
  287. //$divs = $divs[0];
  288. foreach ($divs as $movie) {
  289. $movie = $movie[0];
  290. preg_match_all("/(<a href=\"(.*)\">)*\s*<img\s*src=\"(.*)\" alt=\"(.*)\"\s(\/)*>\s*(<\/a>)*/siU", $movie, $info, PREG_SET_ORDER);
  291. //Get info
  292. parseCoverPageInfo($info,$type,$title,$template,true);
  293. }
  294. }
  295. $template->generateView(CinetubeAnimeTemplate::VIEW_MOVIE, $title);
  296. }
  297. }
  298. /**
  299. * Get given serie category pages, first page items or page number list.
  300. */
  301. function fetchSerieCategoryItems($type,$category,$title) {
  302. //Init template
  303. $template = new CinetubeAnimeTemplate();
  304. $template->setCategory($category);
  305. $template->setType($type);
  306. //If page equal "x" goto page number list, in other case process actual category page
  307. if( isset($_GET["page"]) && $_GET["page"] == "x" ) {
  308. $maxPages = $_GET["pages"];
  309. for($i=1;$i<=$maxPages;++$i) {
  310. $template->addItem(
  311. $i,
  312. resourceString("goto_page") . $i,
  313. SCRAPER_URL . "anime.php?type=" . $type . URL_AMP . "cat=" . base64_encode($category) . URL_AMP . "page=" . $i . URL_AMP . "pages=" . $maxPages . URL_AMP . "PHPSESID=" . session_id(),
  314. ""
  315. );
  316. }
  317. $template->generateView(CinetubeAnimeTemplate::VIEW_PAGE_NUMBERS );
  318. }else {
  319. if(!isset($_GET["page"])) {
  320. $pages = getPages($category);
  321. $template->setActualPage(1);
  322. $template->setMaxPages($pages[1]);
  323. $content = $pages[0];
  324. }else {
  325. $template->setActualPage($_GET["page"]);
  326. $template->setMaxPages($_GET["pages"]);
  327. $content = file_get_contents(CINETUBE_URL . $category . $_GET["page"] . ".html");
  328. }
  329. //Parse first page series
  330. $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
  331. $input = str_replace($newlines, "", $content );
  332. preg_match("/<ul class\=\"ver_series_list\">(.*)<\/ul>/siU", $input, $divs);
  333. preg_match_all("/<li>(.*)<\/li>/siU", $divs[0], $divs, PREG_SET_ORDER);
  334. //For new serie releases dont works
  335. if($category != "series/") {
  336. if($divs) {
  337. //$divs = $divs[0];
  338. foreach ($divs as $movie) {
  339. $movie = $movie[1];
  340. preg_match_all("/(<a href=\"(.*)\">)*\s*<img\s*src=\"(.*)\" alt=\"(.*)\"\s(\/)*>\s*(<\/a>)*|<p class\=\"tit_ficha\">(.*)<\/p>/siU", $movie, $info, PREG_SET_ORDER);
  341. //Get info
  342. $movieIcons = array();
  343. foreach( $info as $key => $detail ) {
  344. if( $key == 0 ) {
  345. if( strpos($detail[2],'"') ) {
  346. $movieLink = substr($detail[2], 0, strpos($detail[2],'"'));
  347. }else {
  348. $movieLink = $detail[2];
  349. }
  350. $movieThumbnail = html_entity_decode($detail[3]);
  351. }else if(count($detail) == 8) {
  352. $movieTitle = $detail[7];
  353. }else if($detail[4]) {
  354. if(!strpos($detail[4],"escarga")) {
  355. array_push( $movieIcons, html_entity_decode($detail[4]) );
  356. }
  357. }else {
  358. //megavideo, veoh, tutv, google
  359. array_push( $movieIcons, html_entity_decode(substr($detail[3], strrpos($detail[3], "/")+1, strrpos($detail[3], "\.")-4)) );
  360. }
  361. }
  362. //Add video
  363. $template->addItem(
  364. $movieTitle,
  365. strtoupper(getArrayString($movieIcons).""),
  366. SCRAPER_URL . "anime.php?type=ser" . URL_AMP . "item=" . base64_encode($movieLink) . URL_AMP . "title=" . base64_encode($title) . URL_AMP . "PHPSESID=" . session_id(),
  367. $movieThumbnail
  368. );
  369. }
  370. }
  371. $template->generateView(CinetubeAnimeTemplate::VIEW_SERIE, $title);
  372. }else {
  373. if($divs) {
  374. //$divs = $divs[0];
  375. foreach ($divs as $movie) {
  376. $movie = $movie[1];
  377. preg_match_all("/<img src\=\"(.*)\"(.*)<a class\=\"tit_ficha\"(.*)href\=\"(.*)\">(.*)<\/a>(.*)<p class\=\"tem_fich\">(.*)<\/p>/siU", $movie, $info, PREG_SET_ORDER);
  378. $info = $info[0];
  379. if( strpos($info[7],"Cap") ) {
  380. $template->addItem(
  381. html_entity_decode($info[5]),
  382. $info[7],
  383. SCRAPER_URL . "anime.php?type=" . $type . URL_AMP . "episodeName=" . base64_encode($info[7]) . URL_AMP . "episode=" . base64_encode($info[4]) . URL_AMP . "seasonNum=" . URL_AMP . "image=" . base64_encode($info[1]) . URL_AMP . "serieTitle=" . base64_encode($info[5]) . URL_AMP . "PHPSESID=" . session_id(),
  384. $info[1]
  385. );
  386. }else {
  387. }
  388. }
  389. }
  390. $template->generateView(CinetubeAnimeTemplate::VIEW_SERIE, $title);
  391. }
  392. }
  393. }
  394. //------------------------------------------------------------------------------
  395. //------------------------------------------------------------------------------
  396. /**
  397. * Get movie links.
  398. */
  399. function fetchMovie($type,$item,$title) {
  400. $template = new CinetubeAnimeTemplate();
  401. $template->setType($type);
  402. $content = file_get_contents( CINETUBE_URL . substr($item,1) );
  403. $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
  404. $content = str_replace($newlines, "", html_entity_decode($content));
  405. preg_match("/<div class\=\"ficha_img pelicula_img\"><img src\=\"(.*)\"(.*)<div class\=\"ficha_des\">(.*)<h1 class\=\"bold\">(.*)<\/h1>(.*)<p>(.*)<\/p>/U",$content,$description);
  406. $thumbnail = $description[1];
  407. $movieTitle = $description[4];
  408. $template->setMovieTitle($movieTitle);
  409. $description = $description[6];
  410. $template->setImage($thumbnail);
  411. //Get mirrors
  412. preg_match_all("/<div class\=\"tit_opts\"><a(.*)href\=\"(.*)\"(.*)><p\>(.*)<\/p><p\><span\>(.*)<\/span><\/p>(.*)<\/div>/siU", $content, $divs, PREG_SET_ORDER);
  413. if($divs) {
  414. foreach ($divs as $value) {
  415. //Add video
  416. if(!strpos($value[4],"rar")) {
  417. $template->addItem(
  418. $value[4] . "\n" . str_replace("| ", "\n", $value[5]),
  419. strtoupper($description),
  420. SCRAPER_URL . "anime.php?type=" . $type . URL_AMP . "play=" . base64_encode( $value[2] ),
  421. $thumnail
  422. );
  423. }
  424. }
  425. }
  426. $template->generateView(CinetubeAnimeTemplate::VIEW_MOVIE_DETAIL,$title);
  427. }
  428. //------------------------------------------------------------------------------
  429. //------------------------------------------------------------------------------
  430. /**
  431. * Get serie links.
  432. */
  433. function fetchSerie($type,$item,$title) {
  434. $template = new CinetubeAnimeTemplate();
  435. $template->setType($type);
  436. if( isset($_SESSION["seasons"]) && array_key_exists($item, unserialize($_SESSION["seasons"]))) {
  437. $seasons = unserialize( $_SESSION["seasons"] );
  438. $seasons = $seasons[$item];
  439. $serieTitle = $_SESSION["serieTitle"];
  440. $serieDescription = $_SESSION["serieDescription"];
  441. $serieCover = $_SESSION["serieCover"];
  442. }else {
  443. //Get serie seasons and info, save to session
  444. $content = file_get_contents("http://www.cinetube.es" . $item);
  445. $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
  446. $content = str_replace($newlines, "", $content );
  447. //Get serie info
  448. preg_match("/<div class\=\"ficha_des des_move\">(.*)<a(.*)>(.*)<\/a><span>(.*)<\/span><\/h1><p>(.*)<\/p>(.*)caratulas.cinetube.es\/seriesa\/(.*)\"/U",$content,$divs);
  449. $serieTitle = html_entity_decode( $divs[3] );
  450. $serieCategory = html_entity_decode( $divs[4] );
  451. $serieDescription = html_entity_decode( $divs[5] );
  452. $serieCover = "http://caratulas.cinetube.es/seriesa/" . $divs[7];
  453. //Get serie seasons
  454. preg_match_all("/<a href\=\"(.*)\">(.*)<\/a>(.*)<a class\=\"caps\"(.*)>(.*)<\/a>/siU", $divs[6], $divs, PREG_SET_ORDER);
  455. $seasons = array();
  456. foreach ($divs as $season) {
  457. $episodeNumber = explode(" ",$season[5]);
  458. $seasons[$season[2]] = array($season[1],$episodeNumber[0]);
  459. }
  460. //Save data to session
  461. $_SESSION["serieTitle"] = $serieTitle;
  462. $_SESSION["serieCategory"] = $serieCategory;
  463. $_SESSION["serieDescription"] = $serieDescription;
  464. $_SESSION["serieCover"] = $serieCover;
  465. $_SESSION["seasons"] = serialize( array( $item => $seasons ) );
  466. }
  467. $template->setSerie($seasons);
  468. $template->setMovieTitle($serieTitle);
  469. $template->setDescription($serieDescription);
  470. $template->setImage($serieCover);
  471. $template->generateView(CinetubeAnimeTemplate::VIEW_SERIE_SEASON, $title);
  472. }
  473. /**
  474. * Get serie season links
  475. */
  476. function fetchSerieSeason($type,$seasonTitle,$title=null) {
  477. $template = new CinetubeAnimeTemplate();
  478. $template->setType($type);
  479. //Recover session info
  480. $serieTitle = $_SESSION["serieTitle"];
  481. $serieCategory = $_SESSION["serieCategory"];
  482. $serieDescription = $_SESSION["serieDescription"];
  483. $serieCover = $_SESSION["serieCover"];
  484. $seasons = unserialize( $_SESSION["seasons"] );
  485. $_SESSION["seasonTitle"] = $seasonTitle;
  486. $seasonKey = array_keys($seasons);
  487. $seasonKey = $seasonKey[0];
  488. $seasonLink = $seasons[$seasonKey];
  489. $seasonLink = $seasonLink[$seasonTitle];
  490. //If array count isn't 3 load data from page
  491. if( count($seasonLink) == 3 ) {
  492. $episodes = $seasonLink[2];
  493. }else {
  494. $seasonLink = $seasonLink[0];
  495. //Get season episodes and save to sesion array
  496. $content = file_get_contents("http://www.cinetube.es" . $seasonLink);
  497. $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
  498. $content = str_replace($newlines, "", $content );
  499. preg_match_all("/<div class\=\"title\"> <a class\=\"bold\" href\=\"(.*)\">(.*)<\/a>/siU", $content, $divs, PREG_SET_ORDER);
  500. //Create episode array and save in session
  501. if($divs) {
  502. $episodes = array();
  503. foreach ($divs as $episode) {
  504. $episodes[$episode[2]] = $episode[1];
  505. }
  506. $arraySeasons = $seasons[$seasonKey];
  507. array_push( $arraySeasons[$seasonTitle], $episodes );
  508. $_SESSION["seasons"] = serialize( array( $seasonKey => $arraySeasons ) );
  509. }
  510. }
  511. //Set data to template
  512. $template->setSerie($seasons[$seasonKey]);
  513. $template->setSeason($episodes);
  514. $template->setSeasonTitle($seasonTitle);
  515. $template->setMovieTitle($serieTitle);
  516. $template->setDescription($serieDescription);
  517. $template->setImage($serieCover);
  518. $template->generateView(CinetubeAnimeTemplate::VIEW_SERIE_EPISODE, $title);
  519. }
  520. /**
  521. * Get serie season episode links
  522. */
  523. function fetchSerieSeasonEpisode($type, $episodeTitle, $episodeLink, $title=null) {
  524. $template = new CinetubeAnimeTemplate();
  525. $template->setType($type);
  526. //Recover session info
  527. $seasonTitle = $_SESSION["seasonTitle"];
  528. if(isset($_GET["serieTitle"])) {
  529. $serieTitle = base64_decode($_GET["serieTitle"]);
  530. }else {
  531. $serieTitle = $_SESSION["serieTitle"];
  532. }
  533. $serieCategory = $_SESSION["serieCategory"];
  534. $serieDescription = $_SESSION["serieDescription"];
  535. if( isset($_GET["image"])) {
  536. $serieCover = base64_decode($_GET["image"]);
  537. }else {
  538. $serieCover = $_SESSION["serieCover"];
  539. }
  540. $seasons = unserialize( $_SESSION["seasons"] );
  541. //Set data to template
  542. //$template->setSerie($seasons[$seasonKey]);
  543. $template->setEpisodeTitle($episodeTitle);
  544. $template->setSeasonTitle($seasonTitle);
  545. $template->setSerieTitle($serieTitle);
  546. $template->setDescription($serieDescription);
  547. $template->setImage($serieCover);
  548. //Get page content
  549. $content = file_get_contents( CINETUBE_URL . substr($episodeLink,1) );
  550. $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
  551. $content = str_replace($newlines, "", html_entity_decode($content));
  552. //Get links
  553. preg_match_all("/<div class\=\"tit_opts\"><a(.*)href\=\"(.*)\"(.*)><p>(.*)<span(.*)span><\/p><p><span\>(.*)<\/span><\/p>(.*)<\/div>/siU", $content, $divs, PREG_SET_ORDER);
  554. //Get mirrors
  555. if($divs) {
  556. foreach ($divs as $value) {
  557. //Add video
  558. $template->addItem(
  559. html_entity_decode($value[4] . "\n" . str_replace("| ", "\n", $value[6])),
  560. $serieDescription,
  561. SCRAPER_URL . "anime.php?type=" . $type . URL_AMP . "play=" . base64_encode( $value[2] ),
  562. $serieCover
  563. );
  564. }
  565. }
  566. $template->generateView(CinetubeAnimeTemplate::VIEW_SERIE_EPISODE_LINK);
  567. }
  568. //------------------------------------------------------------------------------
  569. //------------------------------------------------------------------------------
  570. function fetchPlaySources($type,$play) {
  571. $template = new CinetubeAnimeTemplate();
  572. $template->setType($type);
  573. $content = file_get_contents("http://www.cinetube.es" . $play);
  574. //Get megavideo links
  575. if( strpos($content, "www.megavideo.com/?v=" ) ) {
  576. preg_match_all("|www\.megavideo\.com\/\?v\=(.*)\"|U", $content, $links);
  577. if($links && $links[1]) {
  578. $links = $links[1];
  579. $links = array_unique( $links );
  580. foreach($links as $megavideo_id ) {
  581. if( COOKIE_STATE_ACTIVATED ) {
  582. $array = VideoUtil::generateMegavideoPremiumLink($megavideo_id);
  583. if($array) {
  584. //echo $megavideo_id;
  585. $template->addMediaItem(
  586. $array[0],
  587. "",
  588. $array[1],
  589. "",
  590. $array[2]
  591. );
  592. }
  593. }
  594. }
  595. }
  596. }
  597. //Get megaupload links
  598. if( strpos($content, "www.megaupload.com/?d=" ) ) {
  599. preg_match_all("|www\.megaupload\.com\/\?d\=(.*)\"|U", $content, $links);
  600. if($links && $links[1]) {
  601. $links = $links[1];
  602. $links = array_unique( $links );
  603. foreach($links as $megaupload_id ) {
  604. if( COOKIE_STATE_ACTIVATED ) {
  605. $array = VideoUtil::generateMegauploadPremiumLink($megaupload_id);
  606. if($array) {
  607. //echo $megavideo_id;
  608. $template->addMediaItem(
  609. $array[0],
  610. "",
  611. $array[1],
  612. "",
  613. $array[2]
  614. );
  615. }
  616. }
  617. }
  618. }
  619. }
  620. $template->generateView(CinetubeAnimeTemplate::VIEW_PLAY, "");
  621. }
  622. //------------------------------------------------------------------------------
  623. //------------------------------------------------------------------------------
  624. /**
  625. * -----------------------------------------------------------------------------
  626. * Get category page count and first page content
  627. */
  628. function getPages($category,$search=null) {
  629. $readAgain = true;
  630. if($search) {
  631. switch($category) {
  632. case "mov":
  633. $word = "peliculas";
  634. break;
  635. case "ser":
  636. $word = "series";
  637. break;
  638. }
  639. $foundPages = array("/buscar/$word/?palabra=".$search."&pag=1" => "1");
  640. $initPage = "buscar/$word/?palabra=" . $search;
  641. }else {
  642. $foundPages = array("/".$category."1.html" => "1");
  643. $initPage = $category;
  644. }
  645. //Add pages
  646. while( $readAgain == true ) {
  647. $url = CINETUBE_URL . $initPage;
  648. $content = file_get_contents($url);
  649. if(!$initContentPage) {
  650. $initContentPage = $content;
  651. }
  652. $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
  653. $content = str_replace($newlines, "", html_entity_decode($content));
  654. if(strpos($content, '<li class="pagina">') ) {
  655. //Get pages links
  656. preg_match_all("/<li class\=\"pagina\"><a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a><\/li>/siU", $content, $pages, PREG_SET_ORDER);
  657. if($pages) {
  658. $addedPages = 0;
  659. foreach ($pages as $page) {
  660. if(!array_key_exists($page[2], $foundPages)) {
  661. $foundPages[$page[2]] = $page[3];
  662. $initPage = substr($page[2],1);
  663. ++$addedPages;
  664. }
  665. }
  666. //If read less than 4 pages is the last page list
  667. if($addedPages < 4) {
  668. $readAgain = false;
  669. }
  670. }else {
  671. $readAgain = false;
  672. }
  673. }else {
  674. $readAgain = false;
  675. }
  676. }
  677. return array($initContentPage,count($foundPages));
  678. }
  679. /**
  680. * Parse cinetube cover info and add rss item to template.
  681. * @param $info
  682. * @param $type Movie, documentary or serie (mov, doc, ser)
  683. * @param $title
  684. * @param $template
  685. * @param $showRipType True to parse rip type.
  686. */
  687. function parseCoverPageInfo($info,$type,$title,$template,$showRipType) {
  688. //Get info
  689. $movieIcons = array();
  690. foreach( $info as $key => $detail ) {
  691. if($key == 1 ) {
  692. preg_match_all("/<span class\=\"rosa\">(.*)<\/span>/siU", $detail[0], $rips);
  693. if($rips && (count($rips) > 1) ) {
  694. $movieRipType = getArrayString($rips[1]);
  695. }
  696. }
  697. //
  698. if( $key == 0 ) {
  699. if( strpos($detail[2],'"') ) {
  700. $movieLink = substr($detail[2], 0, strpos($detail[2],'"'));
  701. }else {
  702. $movieLink = $detail[2];
  703. }
  704. $movieTitle = html_entity_decode($detail[4]);
  705. $movieThumbnail = html_entity_decode($detail[3]);
  706. }else if($detail[4]) {
  707. if(!strpos($detail[4],"escarga")) {
  708. array_push( $movieIcons, html_entity_decode($detail[4]) );
  709. }else {
  710. array_push( $movieIcons, "MEGAUPLOAD" );
  711. }
  712. }else {
  713. //megavideo, veoh, tutv, google
  714. array_push( $movieIcons, html_entity_decode(substr($detail[3], strrpos($detail[3], "/")+1, strrpos($detail[3], "\.")-4)) );
  715. }
  716. }
  717. //Add video
  718. if($showRipType) {
  719. $movieDescription = strtoupper($movieRipType . " | " . getArrayString($movieIcons) . "" );
  720. }else {
  721. $movieDescription = strtoupper( getArrayString($movieIcons) . "" );
  722. }
  723. $template->addItem(
  724. $movieTitle,
  725. $movieDescription,
  726. SCRAPER_URL . "anime.php?type=$type" . URL_AMP . "item=" . base64_encode($movieLink) . URL_AMP . "title=" . base64_encode($title),
  727. $movieThumbnail
  728. );
  729. }
  730. /**
  731. * -----------------------------------------------------------------------------
  732. * Get a comma separeted string from array.
  733. */
  734. function getArrayString(array $array) {
  735. $result = "";
  736. for ($i=0; $i<count($array); ++$i) {
  737. $result .= $array[$i];
  738. if( $i<count($array)-1) {
  739. $result .= ", ";
  740. }
  741. }
  742. return $result;
  743. }
  744. ?>