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

/scripts/feeds/xVoD/xVoD/php/scraper/anivide/series.php

http://eboda-hd-for-all-500.googlecode.com/
PHP | 469 lines | 389 code | 44 blank | 36 comment | 26 complexity | 79a6e46064ab8db978568336e1252571 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 'AnivideSeriesTemplate.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/anivide/");
  14. //Start session
  15. if(isset($_GET["PHPSESID"])) {
  16. session_id($_GET["PHPSESID"]);
  17. }
  18. session_start();
  19. //Filter user action and redirect to scrap function
  20. if( isset($_GET["search"]) ) {
  21. $type = $_GET["search"];
  22. $pageTitle = base64_decode($_GET["title"]);
  23. fetchSearch($type,$pageTitle);
  24. }else if( isset($_GET["letter"]) ) {
  25. $letter = $_GET["letter"];
  26. $type = "http://kino.to/Series.html";
  27. fetchLetterItems($type,$letter,"Series: " . $letter);
  28. }else if( isset($_GET["serie"]) ) {
  29. $serie = base64_decode($_GET["serie"]);
  30. $title = base64_decode($_GET["title"]);
  31. fetchSerieEpisodes($serie,$title);
  32. }else if( isset($_GET["episode"]) ) {
  33. $episode = base64_decode($_GET["episode"]);
  34. $title = base64_decode($_GET["title"]);
  35. fetchSerieSeasonEpisodeLinks($episode,$title);
  36. }else if( isset ($_GET["host"])) {
  37. $host = base64_decode($_GET["host"]);
  38. $link = base64_decode($_GET["link"]);
  39. fetchPlayEpisode($host,$link);
  40. }else {
  41. fetchCategories();
  42. }
  43. //------------------------------------------------------------------------------
  44. //------------------------------------------------------------------------------
  45. //------------------------------------------------------------------------------
  46. /**
  47. * Show initial categories.
  48. */
  49. function fetchCategories() {
  50. $template = new AnivideSeriesTemplate();
  51. $letters = array(
  52. "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","~"
  53. );
  54. $template->setSearch( array(
  55. resourceString("search_by") . "...",
  56. resourceString("search_by") . "...",
  57. "rss_command://search",
  58. SCRAPER_URL . "series.php?search=%s" . URL_AMP . "title=" . base64_encode(resourceString("search_by") . "...") . URL_AMP . "PHPSESID=" . session_id(),
  59. ""
  60. )
  61. );
  62. $template->addItem(
  63. "NEWEST",
  64. resourceString("goto_letter") . " NEWEST",
  65. SCRAPER_URL . "series.php?letter=new" . URL_AMP . "title=" . base64_encode($title) . URL_AMP . "PHPSESID=" . session_id(),
  66. ""
  67. );
  68. $template->addItem(
  69. "ALL",
  70. resourceString("goto_letter") . " ALL",
  71. SCRAPER_URL . "series.php?letter=all" . URL_AMP . "title=" . base64_encode($title) . URL_AMP . "PHPSESID=" . session_id(),
  72. ""
  73. );
  74. foreach ($letters as $letter) {
  75. $template->addItem(
  76. $letter,
  77. resourceString("goto_letter") . $letter,
  78. SCRAPER_URL . "series.php?letter=" . $letter . URL_AMP . "title=" . base64_encode($title) . URL_AMP . "PHPSESID=" . session_id(),
  79. ""
  80. );
  81. }
  82. $template->generateView(AnivideSeriesTemplate::VIEW_CATEGORY );
  83. }
  84. /**
  85. * Fetch search result items.
  86. */
  87. function fetchSearch($type,$pageTitle) {
  88. $template = new AnivideSeriesTemplate();
  89. $content = file_get_contents("http://www.anivide.com/searchmore.html?q=".$type);
  90. preg_match_all("/series.png(.*)<a onclick\=\"return false;\" href\=\"(.*)\">(.*)<\/a>/U", $content, $links, PREG_SET_ORDER);
  91. if($links) {
  92. foreach ($links as $value) {
  93. $template->addItem(
  94. html_entity_decode(utf8_decode($value[3])),
  95. "",
  96. SCRAPER_URL . "series.php?serie=" . base64_encode($value[2]) . URL_AMP . "title=" . base64_encode($value[3]) . URL_AMP . "PHPSESID=" . session_id(),
  97. ""
  98. );
  99. }
  100. }
  101. $template->generateView(AnivideSeriesTemplate::VIEW_SERIE, "");
  102. }
  103. /**
  104. * Get category movies and pages.
  105. */
  106. function fetchLetterItems($type,$letter,$title) {
  107. $template = new AnivideSeriesTemplate();
  108. $template->setType($type);
  109. $template->setLetter($letter);
  110. //If page equal "x" goto page number list, in other case process actual category page
  111. if( isset($_GET["page"]) && $_GET["page"] == "x" ) {
  112. $maxPages = $_GET["pages"];
  113. for($i=1;$i<=$maxPages;++$i) {
  114. $template->addItem(
  115. $i,
  116. resourceString("goto_page") . $i,
  117. SCRAPER_URL . "series.php?letter=" . $letter . URL_AMP . "title=" . base64_encode($title) . URL_AMP . "page=" . $i . URL_AMP . "pages=" . $maxPages . URL_AMP . "PHPSESID=" . session_id(),
  118. ""
  119. );
  120. }
  121. $template->generateView(AnivideSeriesTemplate::VIEW_PAGE_NUMBERS );
  122. }else {
  123. if(!isset($_GET["page"])) {
  124. $pages = getPages($type,$letter);
  125. $template->setActualPage(1);
  126. $template->setMaxPages($pages[1]);
  127. $content = $pages[0];
  128. }else {
  129. $page = $_GET["page"];
  130. $template->setActualPage($_GET["page"]);
  131. $template->setMaxPages($_GET["pages"]);
  132. if($letter == "all") {
  133. $url = "http://www.anivide.com/index.html?list=anime&type=series&page=".$page;
  134. }else if($letter == "new") {
  135. $url = "http://www.anivide.com/index.html?list=anime&view=new&page=".$page;
  136. }else {
  137. $url = "http://www.anivide.com/index.html?list=anime&type=series&letter=".$letter."&page=".$page;
  138. }
  139. $content = file_get_contents($url);
  140. }
  141. //Remove backslashes
  142. $content = html_entity_decode($content);
  143. preg_match_all("/<div class=\"animelist\"><a href=\"(.*)\"><img src=\"(.*)\" border=\"0\"><br><br><b>(.*)<\/b><br>(.*)</U", $content, $links, PREG_SET_ORDER);
  144. if($links) {
  145. foreach ($links as $value) {
  146. $title = html_entity_decode(utf8_decode($value[2]));
  147. $template->addItem(
  148. $value[3],
  149. $value[4],
  150. SCRAPER_URL . "series.php?serie=" . base64_encode($value[1]) . URL_AMP . "title=" . base64_encode($value[3]) . URL_AMP . "PHPSESID=" . session_id(),
  151. $value[2]
  152. );
  153. }
  154. }
  155. $template->generateView(AnivideSeriesTemplate::VIEW_SERIE, "");
  156. }
  157. }
  158. /**
  159. * Show selected serie season episodes.
  160. */
  161. function fetchSerieEpisodes($serie,$title) {
  162. //This anime has been removed as requested
  163. $template = new AnivideSeriesTemplate();
  164. //Parse serie page
  165. $content = file_get_contents("http://www.anivide.com/" . $serie);
  166. $content = html_entity_decode($content);
  167. //Get image
  168. preg_match("/<img src=\"http:\/\/www\.anivide\.com\/thumb\/(.*)\"/U", $content, $image);
  169. $image = $image[1];
  170. $template->setImage("http://www.anivide.com/thumb/".$image);
  171. //Get description
  172. preg_match("/Plot Summary: <\/b>(.*)</siU", $content, $description);
  173. $description = $description[1];
  174. $template->setDescription($description);
  175. if(!strpos($content,"his anime has been removed as requested by")) {
  176. $episodes = getPagesEpisodes("http://www.anivide.com/" . $serie,$content);
  177. //preg_match_all("/<div class=\"episode\"><a href=\"(.*)\"><b>(.*)</siU", $content, $episodes, PREG_SET_ORDER)
  178. $episodesArray = array();
  179. foreach ($episodes as $item) {
  180. $episodesArray["$item[2]"] = $item[1];
  181. //Add links
  182. $template->addItem(
  183. $item[2],
  184. "",
  185. SCRAPER_URL . "series.php?episode=" . base64_encode($item[1]) . URL_AMP . "PHPSESID=" . session_id(),
  186. ""
  187. );
  188. }
  189. $_SESSION["anivideSerieEpisodes"] = serialize($episodesArray);
  190. $_SESSION["anivideSerieTitle"] = $title;
  191. $_SESSION["anivideSerieImage"] = "http://www.anivide.com/thumb/".$image;
  192. $_SESSION["anivideSerieDescription"] = $description;
  193. $template->setRemoved(false);
  194. }else {
  195. $template->setRemoved(true);
  196. }
  197. $template->generateView(AnivideSeriesTemplate::VIEW_EPISODES, $title);
  198. }
  199. /**
  200. * Get season episode available mirrors.
  201. * @var $episode Full episode page link.
  202. */
  203. function fetchSerieSeasonEpisodeLinks($episode,$title) {
  204. $template = new AnivideSeriesTemplate();
  205. //Recover info and set to template
  206. $template->setMovieTitle($_SESSION["anivideSerieTitle"]);
  207. $template->setImage($_SESSION["anivideSerieImage"]);
  208. $template->setDescription($_SESSION["anivideSerieDescription"]);
  209. $content = file_get_contents( "http://www.anivide.com/" . $episode );
  210. $content = html_entity_decode($content);
  211. //Check for part list or single link
  212. if( strpos($content,'<div class="videoparts">') ) {
  213. preg_match("/<div class=\"videoparts\">(.*)<\/div>/siU", $content, $content);
  214. preg_match_all("/<img src=\"(.*)\" alt=\"(.*)\" title=\"(.*)\"> <a href=(.*)>(.*)<\/a>/siU", $content[1], $parts, PREG_SET_ORDER);
  215. foreach ($parts as $link) {
  216. if( (strtolower($link[2]) == "megavideo") || (strtolower($link[2]) == "myspace") ) {
  217. $template->addItem(
  218. $link[2],
  219. "",
  220. SCRAPER_URL . "series.php?host=" . base64_encode($link[2]) . URL_AMP . "link=" . base64_encode($link[4]) . URL_AMP . "PHPSESID=" . session_id(),
  221. ""
  222. );
  223. }
  224. }
  225. }else {
  226. $url = strstr($episode,"?") . "&part=1";
  227. $content = file_get_contents( "http://www.anivide.com/vidplayer.php?test=1&sid35=1285540124047", false, getLinkContext($url) );
  228. if(strpos($content,"megavideo")) {
  229. $host = "Megavideo";
  230. }else if(strpos($content,"myspace")) {
  231. $host = "MySpace";
  232. }else if(strpos($content,"guba.com")) {
  233. $host = "Guba.com";
  234. }
  235. $template->addItem(
  236. $host,
  237. "",
  238. SCRAPER_URL . "series.php?host=" . base64_encode($host) . URL_AMP . "link=" . base64_encode($url) . URL_AMP . "PHPSESID=" . session_id(),
  239. ""
  240. );
  241. }
  242. $template->generateView(AnivideSeriesTemplate::VIEW_EPISODE_DETAIL, $_SESSION["anivideSerieTitle"]);
  243. }
  244. function fetchPlayEpisode($host,$link) {
  245. $template = new AnivideSeriesTemplate();
  246. //Recover info and set to template
  247. $template->setMovieTitle($_SESSION["anivideSerieTitle"]);
  248. $template->setImage($_SESSION["anivideSerieImage"]);
  249. $template->setDescription($_SESSION["anivideSerieDescription"]);
  250. $content = file_get_contents( "http://www.anivide.com/vidplayer.php?test=1&sid35=1285540124047" . $link, false, getLinkContext($link) );
  251. switch(strtolower($host)) {
  252. case "megavideo";
  253. addMegavideoLink($template,$content);
  254. break;
  255. case "myspace";
  256. addMySpaceLink($template,$content);
  257. break;
  258. case "guba.com";
  259. addGubaComFlash($template,$content);
  260. break;
  261. }
  262. $template->generateView(AnivideSeriesTemplate::VIEW_PLAY, $_SESSION["anivideSerieTitle"]);
  263. }
  264. function addMegavideoLink($template,$content) {
  265. preg_match_all("|www.megavideo.com\/v\/(.*)\"|U", $content, $links);
  266. if($links && $links[1]) {
  267. $links = $links[1];
  268. $links = array_unique( $links );
  269. foreach ($links as $value) {
  270. //Parse and get megavideo id
  271. if(strpos($value,".")) {
  272. $value = substr($value, 0, strpos($value,"."));
  273. }
  274. $megavideo_id = substr($value, 0, -32);
  275. if( $megavideo_id ) {
  276. //If megaupload cookie is defined, use it, in other case, use alternative method
  277. if( COOKIE_STATE_ACTIVATED ) {
  278. //generateMegavideoPremiumLink($tempTitle, $imageUrl, $counter, $megavideo_id);
  279. $array = VideoUtil::generateMegavideoPremiumLink($megavideo_id);
  280. if($array) {
  281. $template->addMediaItem(
  282. $array[0],
  283. "",
  284. $array[1],
  285. "",
  286. $array[2]
  287. );
  288. }
  289. }
  290. }
  291. }
  292. }
  293. }
  294. function addMySpaceLink($template,$content) {
  295. preg_match("/file=(.*)&/siU", $content, $link);
  296. if($link) {
  297. $link = $link[1];
  298. $template->addMediaItem(
  299. substr($link, strrpos($link,"/")+1),
  300. "",
  301. $link,
  302. "",
  303. VideoUtil::getEnclosureMimetype($link)
  304. );
  305. }else {
  306. preg_match("/<param name=\"movie\" value=\"(.*)\"/siU", $content, $link);
  307. if($link) {
  308. $link = $link[1];
  309. preg_match("/m=(.*),/siU", $link, $id);
  310. $content = file_get_contents("http://mediaservices.myspace.com/services/rss.ashx?videoID=" . $id[1] . "&type=video");
  311. preg_match("/content url=\"(.*)\" type=\"(.*)\"/siU", $content, $link);
  312. if($link) {
  313. $template->addMediaItem(
  314. substr($link[1], strrpos($link[1],"/")+1),
  315. "",
  316. $link[1],
  317. "",
  318. $link[2]
  319. );
  320. }
  321. }
  322. }
  323. }
  324. function addGubaComFlash($template,$content) {
  325. preg_match("/video_url=(.*)&/siU", $content, $link);
  326. if($link) {
  327. $link = $link[1];
  328. $template->addMediaItem(
  329. substr($link, strrpos($link,"/")+1),
  330. "",
  331. $link,
  332. "",
  333. VideoUtil::getEnclosureMimetype($link)
  334. );
  335. }
  336. }
  337. //------------------------------------------------------------------------------
  338. //------------------------------------------------------------------------------
  339. /**
  340. * Get number of pages and retrieve first page content.
  341. */
  342. function getPages($url,$letter) {
  343. if($letter == "all") {
  344. $url = "http://www.anivide.com/index.html?list=anime&type=series";
  345. }else if($letter == "new") {
  346. $url = "http://www.anivide.com/index.html?list=anime&view=new";
  347. }else {
  348. $url = "http://www.anivide.com/index.html?list=anime&type=series&letter=".$letter;
  349. }
  350. $content = file_get_contents($url);
  351. //Get letter number of entries
  352. preg_match("/<i>\((.*) pages\)/U", $content, $numberEntries);
  353. if($numberEntries) {
  354. $numPages = $numberEntries[1];
  355. }else {
  356. $numberEntries = 0;
  357. }
  358. return array($content,$numPages);
  359. }
  360. function getLinkContext($url) {
  361. //Get page session id from cookie
  362. file_get_contents("http://www.anivide.com/index.html" . $url);
  363. foreach ($http_response_header as $value) {
  364. if(strpos($value,"PHPSESSID")) {
  365. preg_match("/PHPSESSID=(.*);/siU", $value, $cookie);
  366. $cookie = $cookie[1];
  367. break;
  368. }
  369. }
  370. //Create context
  371. $opts = array(
  372. 'http'=>array(
  373. 'method'=>"GET",
  374. 'header'=> "Host: www.anivide.com\r\n".
  375. "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".
  376. "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n".
  377. "Accept-Language: es-es,es;q=0.8,en-us;q=0.5,en;q=0.3\r\n".
  378. "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\n".
  379. "Keep-Alive: 115\r\n".
  380. "Connection: keep-alive\r\n".
  381. "Referer: http://www.anivide.com/index.html" . $url . "\r\n".
  382. "Cookie: PHPSESSID=" . $cookie . ";\r\n"
  383. )
  384. );
  385. //"Cookie: sitechrx=" . $hash . ";Path=/;\r\n"
  386. $context = stream_context_create($opts);
  387. return $context;
  388. }
  389. function getPagesEpisodes($url,$content) {
  390. $episodesRecovered = array();
  391. //Get number of episodes pages
  392. preg_match("/<i>\((.*) pages\)/siU", $content, $episodeNumber);
  393. $episodeNumber = $episodeNumber[1];
  394. //Get all episodes
  395. preg_match_all("/<div class=\"episode\"><a href=\"(.*)\"><b>(.*)</siU", $content, $episodes, PREG_SET_ORDER);
  396. $episodesRecovered = mergeArrays($episodesRecovered, $episodes);
  397. for($i=2;$i<=$episodeNumber;++$i) {
  398. $content = file_get_contents( $url . "&page=" . $i );
  399. preg_match_all("/<div class=\"episode\"><a href=\"(.*)\"><b>(.*)</siU", $content, $episodes, PREG_SET_ORDER);
  400. $episodesRecovered = mergeArrays($episodesRecovered, $episodes);
  401. if( $i > 20 ) {
  402. return;
  403. }
  404. }
  405. return $episodesRecovered;
  406. }
  407. function mergeArrays($sourceArray, $copyArray) {
  408. foreach ($copyArray as $value) {
  409. array_push($sourceArray, $value);
  410. }
  411. return $sourceArray;
  412. }
  413. ?>