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

/scripts/feeds/xVoD/xVoD/php/scraper/megastreaming/index.php

http://eboda-hd-for-all-500.googlecode.com/
PHP | 544 lines | 472 code | 38 blank | 34 comment | 26 complexity | c8ca8b2b0c21775e8198ab5180193bf9 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0
  1. <?php
  2. /*-------------------------
  3. * Developed by Maicros
  4. * GNU/GPL v2 Licensed
  5. * ------------------------*/
  6. include_once '../../config/config.php';
  7. include_once 'MegastreamingTemplate.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/megastreaming/");
  14. //Start session
  15. if(isset($_GET["PHPSESID"])) {
  16. session_id($_GET["PHPSESID"]);
  17. }
  18. session_start();
  19. //
  20. if(isset($_GET["cat"])) { //Category movie view -----------------------------
  21. $type = $_GET["type"];
  22. $category = base64_decode($_GET["cat"]);
  23. $title = base64_decode($_GET["title"]);
  24. fetchMovieCategoryItems($type,$category,$title);
  25. }else if(isset($_GET["item"])) { //Movie detail view -------------------------------
  26. $type = $_GET["type"];
  27. $item = base64_decode($_GET["item"]);
  28. $title = base64_decode($_GET["title"]);
  29. fetchMovie($type,$item,$title);
  30. }else if(isset($_GET["serie"])) { // Serie seasons view ---------------------
  31. $type = $_GET["type"];
  32. $serieLink = base64_decode($_GET["serie"]);
  33. $title = base64_decode($_GET["title"]);
  34. fetchSerieSeasons($type,$serieLink,$title);
  35. }else if(isset($_GET["season"])) { // Serie season episodes view ------------
  36. $type = $_GET["type"];
  37. $seasonLink = base64_decode($_GET["season"]);
  38. fetchSerieSeasonEpisodes($type,$seasonLink);
  39. }else if(isset($_GET["episode"])) { // Serie episode links view -------------
  40. $type = $_GET["type"];
  41. $episodeLink = base64_decode($_GET["episode"]);
  42. $episodeName = base64_decode($_GET["episodeName"]);
  43. $seasonTitle = base64_decode($_GET["seasonTitle"]);
  44. fetchSerieSeasonEpisodeLinks($type,$episodeLink,$episodeName,$seasonTitle);
  45. }else if(isset($_GET["type"])) { // Show home view --------------------------
  46. $type = $_GET["type"];
  47. switch($type) {
  48. case "mov":
  49. fetchMovieCategories($type);
  50. break;
  51. case "ser":
  52. fetchSerieCategories($type);
  53. break;
  54. }
  55. }else { // Show home principal view ----------------------------------------
  56. fetchHome();
  57. }
  58. //------------------------------------------------------------------------------
  59. //------------------------------------------------------------------------------
  60. /**
  61. * Get principal scraper view.
  62. */
  63. function fetchHome() {
  64. $_SESSION["megastreamingLastReferer"] = "http://www.megastreaming.ws";
  65. $template = new MegastreamingTemplate();
  66. $template->addItem(
  67. resourceString("movie"),
  68. resourceString("movie"),
  69. SCRAPER_URL . "index.php?type=mov". URL_AMP . "PHPSESID=" . session_id(),
  70. ""
  71. );
  72. $template->addItem(
  73. resourceString("serie"),
  74. resourceString("serie"),
  75. SCRAPER_URL . "index.php?type=ser". URL_AMP . "PHPSESID=" . session_id(),
  76. ""
  77. );
  78. $template->generateView(MegastreamingTemplate::VIEW_HOME, "Megastreaming");
  79. }
  80. //------------------------------------------------------------------------------
  81. //------------------------------------------------------------------------------
  82. /**
  83. */
  84. function fetchMovieCategories($type) {
  85. $template = new MegastreamingTemplate();
  86. $template->setType($type);
  87. $content = @file_get_contents( "http://www.megastreaming.ws" );
  88. $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
  89. $content = str_replace($newlines, "", html_entity_decode($content));
  90. $content = strstr($content,"TOUS LES FILMS");
  91. $content = substr($content, 0, strpos($content,"</ul>"));
  92. preg_match_all("/<a href\=\"(.*)\"(.*)>(.*)</U", $content, $links, PREG_SET_ORDER);
  93. $template->addItem(
  94. "Tous les films Par date",
  95. resourceString("category") . " Tous les films Par date",
  96. SCRAPER_URL . "index.php?type=$type" . URL_AMP . "cat=" . base64_encode("http://www.megastreaming.ws/streaming/films") . URL_AMP . "title=" . base64_encode($link[3]) . URL_AMP . "PHPSESID=" . session_id(),
  97. ""
  98. );
  99. foreach ( $links as $link ) {
  100. $template->addItem(
  101. $link[3],
  102. resourceString("category") . " " . $link[3],
  103. SCRAPER_URL . "index.php?type=$type" . URL_AMP . "cat=" . base64_encode($link[1]) . URL_AMP . "title=" . base64_encode($link[3]) . URL_AMP . "PHPSESID=" . session_id(),
  104. ""
  105. );
  106. }
  107. // $template->setSearch( array(
  108. // resourceString("search_by") . "...",
  109. // resourceString("search_by") . "...",
  110. // "rss_command://search",
  111. // SCRAPER_URL . "index.php?search=%s" . URL_AMP . "type=$type" . URL_AMP . "title=" . base64_encode("Search by") . URL_AMP . "PHPSESID=" . session_id(),
  112. // ""
  113. // )
  114. // );
  115. $template->generateView(MegastreamingTemplate::VIEW_CATEGORY, "");
  116. }
  117. /**
  118. */
  119. function fetchMovieCategoryItems($type,$category,$title,$search=null) {
  120. $template = new MegastreamingTemplate();
  121. $template->setCategory($category);
  122. $template->setType($type);
  123. //If page equal "x" goto page number list, in other case process actual category page
  124. if( isset($_GET["page"]) && $_GET["page"] == "x" ) {
  125. $maxPages = $_GET["pages"];
  126. for($i=1;$i<=$maxPages;++$i) {
  127. $template->addItem(
  128. $i,
  129. resourceString("goto_page") . $i,
  130. SCRAPER_URL . "index.php?type=" . $type . URL_AMP . "cat=" . base64_encode($category) . URL_AMP . "page=" . $i . URL_AMP . "pages=" . $maxPages . URL_AMP . "PHPSESID=" . session_id(),
  131. ""
  132. );
  133. }
  134. $template->generateView(MegastreamingTemplate::VIEW_PAGE_NUMBERS );
  135. }else {
  136. if(!isset($_GET["page"])) {
  137. $pages = getPages($category);
  138. $template->setActualPage(1);
  139. $template->setMaxPages($pages[1]);
  140. $content = $pages[0];
  141. }else {
  142. $template->setActualPage($_GET["page"]);
  143. $template->setMaxPages($_GET["pages"]);
  144. $content = @file_get_contents( $category . "page/" . $_GET["page"] . "/");
  145. $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
  146. $content = str_replace($newlines, "", html_entity_decode($content,ENT_QUOTES,"UTF-8"));
  147. }
  148. preg_match_all("/<div class\=\"Styleazer2\">(.*)<\/table>/siU", $content, $links, PREG_SET_ORDER);
  149. if($links) {
  150. foreach ($links as $value) {
  151. //Link and Title
  152. preg_match("/<a href\=\"(.*)\"(.*)>(.*)</siU", $value[1], $matches);
  153. $movieLink = $matches[1];
  154. $movieTitle = $matches[3];
  155. //Image
  156. preg_match("/<img alt\=\"film streaming\" src\=\"(.*)\"/siU", $value[1], $matches);
  157. if(!$matches) {
  158. $image = XTREAMER_IMAGE_PATH . "background/transparent_square.png";
  159. }else {
  160. $image = $matches[1];
  161. }
  162. //Description
  163. preg_match("/<\/h3><p>(.*)</siU", $value[1], $matches);
  164. if($matches) {
  165. $movieDescription = $matches[ count($matches)-1 ];
  166. }
  167. $template->addItem(
  168. utf8_decode($movieTitle),
  169. utf8_decode($movieDescription),
  170. SCRAPER_URL . "index.php?type=$type" . URL_AMP . "item=" . base64_encode($movieLink) . URL_AMP . "title=" . base64_encode($movieTitle) . URL_AMP . "image=" . base64_encode($image) . URL_AMP . "PHPSESID=" . session_id(),
  171. $image
  172. );
  173. }
  174. }
  175. $template->generateView(MegastreamingTemplate::VIEW_MOVIE, "");
  176. }
  177. }
  178. /**
  179. */
  180. function fetchMovie($type,$movie,$title) {
  181. $template = new MegastreamingTemplate();
  182. $template->setType($type);
  183. $template->setMovieTitle($title);
  184. //Parse movie page
  185. $content = @file_get_contents($movie);
  186. $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
  187. $content = str_replace($newlines, "", utf8_decode( $content) );
  188. $_SESSION["megastreamingLastReferer"] = $movie;
  189. if( strpos($content,"<strong>DESCRIPTION</strong>")) {
  190. $content = strstr($content, "<strong>DESCRIPTION</strong>");
  191. $content = strstr($content, "<p>");
  192. $description = substr($content, 0, strpos($content, "</p>"));
  193. $description = str_replace("<p>", "", $description);
  194. $template->setDescription($description);
  195. }
  196. if( strpos($content, "http://www.megavideo.com/v" ) ) {
  197. $regex = "|www.megavideo.com\/v\/(.*)\"|U";
  198. }else if( strpos($content, "&v=" ) ) {
  199. $regex = "|\&v\=(.*)\"|U";
  200. }else {
  201. $regex = false;
  202. }
  203. if($regex) {
  204. preg_match_all($regex, $content, $links);
  205. if($links && $links[1]) {
  206. $links = $links[1];
  207. $links = array_unique( $links );
  208. foreach ($links as $value) {
  209. //Get megavideo id
  210. if(count_chars($value) > 20 ) {
  211. $megavideo_id = substr($value, 0, -32);
  212. }else {
  213. $megavideo_id = $value;
  214. }
  215. if( COOKIE_STATE_ACTIVATED && $megavideo_id ) {
  216. $array = VideoUtil::generateMegavideoPremiumLink($megavideo_id);
  217. if($array) {
  218. $template->addMediaItem(
  219. $array[0],
  220. $description,
  221. $array[1],
  222. "",
  223. $array[2]
  224. );
  225. }
  226. }
  227. }
  228. }
  229. }
  230. //Get megaupload links
  231. if( strpos($content, "www.megaupload.com/?d=" ) ) {
  232. preg_match_all("|www\.megaupload\.com\/\?d\=(.*)\s?\" class\=\"Stylehopbleu\"|U", $content, $links);
  233. if($links && $links[1]) {
  234. $links = $links[1];
  235. $links = array_unique( $links );
  236. foreach($links as $megaupload_id ) {
  237. if( COOKIE_STATE_ACTIVATED ) {
  238. $array = VideoUtil::generateMegauploadPremiumLink($megaupload_id);
  239. if($array) {
  240. //echo $megavideo_id;
  241. $template->addMediaItem(
  242. $array[0],
  243. $description,
  244. $array[1],
  245. "",
  246. $array[2]
  247. );
  248. }
  249. }
  250. }
  251. }
  252. }
  253. $content = strstr($content,"yapb_cache/");
  254. $image = "http://www.megastreaming.ws/wp-content/uploads/" . substr($content, 0, strpos($content, '"'));
  255. $template->setImage($image);
  256. $template->generateView(MegastreamingTemplate::VIEW_MOVIE_DETAIL);
  257. }
  258. //------------------------------------------------------------------------------
  259. //------------------------------------------------------------------------------
  260. /**
  261. */
  262. function fetchSerieCategories($type) {
  263. session_start();
  264. $template = new MegastreamingTemplate();
  265. $template->setType($type);
  266. $seriesLoaded = false;
  267. //Check for loaded series on session
  268. if(isset($_SESSION["megastreamingSeries"])) {
  269. $div = unserialize($_SESSION["megastreamingSeries"]);
  270. $seriesLoaded = true;
  271. }else {
  272. //Get principal page and parse category list
  273. $content = @file_get_contents("http://www.megastreaming.ws/series-tv.html");
  274. $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
  275. $input = str_replace($newlines, "", $content );
  276. $content = strstr($content, "<!-- Breadcrumbs -->");
  277. $content = strstr($content, "<table");
  278. $content = substr($content, 0, strpos($content,"</table>"));
  279. $content = html_entity_decode($content,ENT_QUOTES,"UTF-8");
  280. preg_match_all("/href=\"(.*)\">(.*)<\/a>/U", $content, $div, PREG_SET_ORDER);
  281. }
  282. if($div) {
  283. $newlines = array("<strong>","</strong>");
  284. foreach ($div as $value) {
  285. $name = utf8_decode($value[2]);
  286. $name = str_replace($newlines, "", $name );
  287. if($name != "" && $name != " ") {
  288. $weblink = str_replace("../", "http://www.megastreaming.ws/", $value[1]);
  289. $serieLink = SCRAPER_URL . "index.php?type=" . $type . URL_AMP . "serie=" . base64_encode($weblink) . URL_AMP . "title=" . base64_encode($name). URL_AMP . "PHPSESID=" . session_id();
  290. $template->addItem(
  291. $name,
  292. $name,
  293. $serieLink,
  294. ""
  295. );
  296. }
  297. }
  298. }
  299. //If series has been loaded from page, save to session
  300. if(!$seriesLoaded) {
  301. $_SESSION["megastreamingSeries"] = serialize($div);
  302. }
  303. $template->generateView(MegastreamingTemplate::VIEW_CATEGORY, "");
  304. }
  305. function fetchSerieSeasons($type,$serieLink,$title) {
  306. //Init template
  307. $template = new MegastreamingTemplate();
  308. $template->setType($type);
  309. //Parse first page series
  310. $content = @file_get_contents($serieLink);
  311. $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
  312. $input = str_replace($newlines, "", utf8_decode( $content) );
  313. $_SESSION["megastreamingLastReferer"] = $serieLink;
  314. //Get data
  315. preg_match("/<\!-- Breadcrumbs -->(.*)<table/U", $input, $div);
  316. $div = $div[1];
  317. $div = strstr($div, 'src="' );
  318. $posterImage = substr($div, 5, strpos($div,'" ')-5);
  319. $div = substr($div, strpos($div,'<p>')+3);
  320. $description = substr($div, 0, -4);
  321. if( strpos($description,"</p>")) {
  322. $description = substr($div, 0, strpos($description,"</p>"));
  323. }
  324. $template->setSerieTitle($title);
  325. $template->setHeaderImage($posterImage);
  326. $template->setDescription( utf8_decode( html_entity_decode($description,ENT_QUOTES,"UTF-8") ) );
  327. $seasons = array();
  328. preg_match_all("/<h2>(.*)<\/h2><p>(.*)((<\/p>)|(<\/td>))/U", $input, $div, PREG_SET_ORDER);
  329. foreach ($div as $value) {
  330. $episodes = array();
  331. preg_match_all("/href\=\"(.*)\">(.*)<\/a>/U", $value[2], $links, PREG_SET_ORDER);
  332. foreach ($links as $link) {
  333. $episodeName = $link[2];
  334. $episodeName = str_replace(array("<strong>","</strong>"), "", $episodeName );
  335. if( strpos($link[1],"./")) {
  336. $episodes[$episodeName] = str_replace("..", "http://www.megastreaming.ws", $link[1]);
  337. $lastLink = $episodes[$episodeName];
  338. }else {
  339. $episodes[$episodeName] = $link[1];
  340. $lastLink = $link[1];
  341. }
  342. }
  343. $seasonName = str_replace(array("<strong>","</strong>"), "", html_entity_decode($value[1],ENT_QUOTES,"UTF-8") );
  344. if(strpos($value[1],"<")) {
  345. $seasonName = substr($value[1], 0, strpos($value[1],"<"));
  346. }
  347. $seasons[$seasonName] = $episodes;
  348. }
  349. ksort($seasons);
  350. $template->setSerie($seasons);
  351. //Get cover
  352. $content = @file_get_contents($lastLink);
  353. if(strpos($content,"caticon/")) {
  354. $content = strstr($content,"caticon/");
  355. $coverImage = "http://www.megastreaming.ws/wp-content/uploads/" . substr($content, 0, strpos($content, '"'));
  356. }else if(strpos($content,"yapb_cache/")) {
  357. $content = strstr($content,"yapb_cache/");
  358. $coverImage = "http://www.megastreaming.ws/wp-content/uploads/" . substr($content, 0, strpos($content, '"'));
  359. }
  360. $template->setImage($coverImage);
  361. //save data to session
  362. $_SESSION["serieTitle"] = $title;
  363. $_SESSION["serieLink"] = $serieLink;
  364. $_SESSION["serieDescription"] = $description;
  365. $_SESSION["seriePoster"] = $posterImage;
  366. $_SESSION["serieCover"] = $coverImage;
  367. $_SESSION["seasons"] = serialize( $seasons );
  368. $template->generateView(MegastreamingTemplate::VIEW_SERIE_SEASON, $title);
  369. }
  370. function fetchSerieSeasonEpisodes($type,$season) {
  371. //Init template
  372. $template = new MegastreamingTemplate();
  373. $template->setType($type);
  374. //recover session data
  375. $template->setSerieTitle($_SESSION["serieTitle"]);
  376. $template->setHeaderImage($_SESSION["seriePoster"]);
  377. $template->setImage($_SESSION["serieCover"]);
  378. $template->setDescription($_SESSION["serieDescription"]);
  379. $template->setSeasonTitle($season);
  380. $seasons = unserialize($_SESSION["seasons"]);
  381. $template->setSerie($seasons);
  382. $episodes = $seasons[$season];
  383. $template->setSeason($episodes);
  384. //save data to session
  385. $_SESSION["seasonTitle"] = $season;
  386. $template->generateView(MegastreamingTemplate::VIEW_SERIE_EPISODE, $title);
  387. }
  388. function fetchSerieSeasonEpisodeLinks($type,$episodeLink,$episodeName,$seasonTitle) {
  389. //Init template
  390. $template = new MegastreamingTemplate();
  391. $template->setType($type);
  392. //recover session data
  393. $template->setSerieTitle($_SESSION["serieTitle"]);
  394. $template->setEpisodeTitle($episodeName);
  395. $template->setSeasonTitle($seasonTitle);
  396. $seasons = unserialize($_SESSION["seasonTitle"]);
  397. //Get page content
  398. $content = @file_get_contents( $episodeLink );
  399. $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
  400. $content = str_replace($newlines, "", html_entity_decode(utf8_decode($content),ENT_QUOTES));
  401. $_SESSION["megastreamingLastReferer"] = $episodeLink;
  402. if( strpos($content,"<strong>DESCRIPTION</strong>")) {
  403. $content = strstr($content, "<strong>DESCRIPTION</strong>");
  404. $content = strstr($content, "<p>");
  405. $description = substr($content, 0, strpos($content, "</p>"));
  406. $description = str_replace("<p>", "", $description);
  407. $template->setDescription($description);
  408. }
  409. if( strpos($content, "http://www.megavideo.com/v" ) ) {
  410. $regex = "|www.megavideo.com\/v\/(.*)\"|U";
  411. }else if( strpos($content, "&v=" ) ) {
  412. $regex = "|\&v\=(.*)\"|U";
  413. }else {
  414. $regex = false;
  415. }
  416. if($regex) {
  417. preg_match_all($regex, $content, $links);
  418. if($links && $links[1]) {
  419. $links = $links[1];
  420. $links = array_unique( $links );
  421. foreach ($links as $value) {
  422. //Get megavideo id
  423. if(strlen($value) > 20 ) {
  424. $megavideo_id = substr($value, 0, -32);
  425. }else {
  426. $megavideo_id = $value;
  427. }
  428. //Show real link
  429. if( COOKIE_STATE_ACTIVATED && $megavideo_id ) {
  430. $array = VideoUtil::generateMegavideoPremiumLink($megavideo_id);
  431. if($array) {
  432. $template->addMediaItem(
  433. $array[0],
  434. $description,
  435. $array[1],
  436. $movieImage,
  437. $array[2]
  438. );
  439. }
  440. }
  441. }
  442. }
  443. }
  444. //Set cover image
  445. $template->setImage($_SESSION["serieCover"]);
  446. $template->generateView(MegastreamingTemplate::VIEW_SERIE_EPISODE_LINK,$_SESSION["serieTitle"]);
  447. }
  448. //------------------------------------------------------------------------------
  449. //------------------------------------------------------------------------------
  450. function getPages($url) {
  451. //Add pages
  452. //<span class='pages'>Page 1 sur 72</span>
  453. $content = file_get_contents($url);
  454. echo $url;
  455. echo $content;
  456. $url = substr($url, 0, -1);
  457. $content = file_get_contents($url);
  458. $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
  459. $content = str_replace($newlines, "", html_entity_decode($content,ENT_QUOTES,"UTF-8"));
  460. $_SESSION["megastreamingLastReferer"] = $url;
  461. preg_match("/<span class\=\'pages\'>Page(.*)sur(.*)<\/span>/siU", $content, $pages);
  462. if($pages) {
  463. $numPages = (int)trim($pages[2]);
  464. }else {
  465. $numPages = 1;
  466. }
  467. return array($content,$numPages);
  468. }
  469. ?>