PageRenderTime 27ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

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

http://eboda-hd-for-all-500.googlecode.com/
PHP | 220 lines | 153 code | 31 blank | 36 comment | 13 complexity | 62816426fe6d0dc4f7bee23b843bbd94 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 'MarocTemplate.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/maroc/");
  14. if(isset($_GET["download"])) {
  15. $downloadfile = "/tmp/xvod_links.txt";
  16. if (file_exists( $downloadfile )){
  17. $extension = " > /dev/null 2>&1 & echo $!";
  18. $outputdir = "/tmp/hdd/volumes/HDD1/movie/";
  19. $command ="/opt/bin/wget -i$downloadfile -P $outputdir";
  20. exec($command.$extension, $op);
  21. }
  22. }
  23. else
  24. //Start session
  25. if(isset($_GET["PHPSESID"])) {
  26. session_id($_GET["PHPSESID"]);
  27. }
  28. session_start();
  29. //
  30. if(isset($_GET["cat"])) { //Category movie view -----------------------------
  31. $category = base64_decode($_GET["cat"]);
  32. $title = base64_decode($_GET["title"]);
  33. fetchMovieCategoryItems($category,$title);
  34. }else if(isset($_GET["item"])) { //Movie detail view -------------------------------
  35. $item = base64_decode($_GET["item"]);
  36. $title = base64_decode($_GET["title"]);
  37. $image = base64_decode($_GET["image"]);
  38. fetchMovie($item,$title,$image);
  39. }else { // Show home view --------------------------
  40. fetchMovieCategories();
  41. }
  42. //------------------------------------------------------------------------------
  43. //------------------------------------------------------------------------------
  44. /**
  45. */
  46. function fetchMovieCategories() {
  47. $template = new MarocTemplate();
  48. $content = @file_get_contents( "http://www.01maroc.com/modules/films/index.php" );
  49. $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
  50. $content = str_replace($newlines, "", html_entity_decode($content));
  51. $content = strstr($content,"<!-- Start category loop -->");
  52. $content = substr($content, 0, strpos($content,"<!-- End category loop -->"));
  53. //echo $content;
  54. preg_match_all("/<td width\=\"5%\" style=\"text-align\: center;\"><a href\=\"(.*)\"><img src\=\"(.*)\" title\=\"(.*)\"(.*)\/><\/a>(.*)<b>(.*)<\/b>/U", $content, $links, PREG_SET_ORDER);
  55. //var_dump($links);
  56. // $template->addItem(
  57. // "Tous les films Par date",
  58. // resourceString("category") . " Tous les films Par date",
  59. // 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(),
  60. // ""
  61. // );
  62. foreach ( $links as $link ) {
  63. $template->addItem(
  64. $link[6],
  65. $link[3],
  66. SCRAPER_URL . "index.php?cat=" . base64_encode($link[1]) . URL_AMP . "title=" . base64_encode($link[6]) . URL_AMP . "PHPSESID=" . session_id(),
  67. $link[2]
  68. );
  69. }
  70. // $template->setSearch( array(
  71. // resourceString("search_by") . "...",
  72. // resourceString("search_by") . "...",
  73. // "rss_command://search",
  74. // SCRAPER_URL . "index.php?search=%s" . URL_AMP . "type=$type" . URL_AMP . "title=" . base64_encode("Search by") . URL_AMP . "PHPSESID=" . session_id(),
  75. // ""
  76. // )
  77. // );
  78. $template->generateView(MarocTemplate::VIEW_CATEGORY, "");
  79. }
  80. /**
  81. */
  82. function fetchMovieCategoryItems($category,$title,$search=null) {
  83. $template = new MarocTemplate();
  84. $template->setCategory($category);
  85. //Check for name ordered
  86. if( !strpos($category,"orderby") ) {
  87. $category = $category . "&orderby=titleA";
  88. }
  89. //If page equal "x" goto page number list, in other case process actual category page
  90. if( isset($_GET["page"]) && $_GET["page"] == "x" ) {
  91. $maxPages = $_GET["pages"];
  92. for($i=1;$i<=$maxPages;++$i) {
  93. $template->addItem(
  94. $i,
  95. resourceString("goto_page") . $i,
  96. SCRAPER_URL . "index.php?cat=" . base64_encode($category) . URL_AMP . "page=" . $i . URL_AMP . "pages=" . $maxPages . URL_AMP . "PHPSESID=" . session_id(),
  97. ""
  98. );
  99. }
  100. $template->generateView(MarocTemplate::VIEW_PAGE_NUMBERS );
  101. }else {
  102. if(!isset($_GET["page"])) {
  103. $pages = getPages($category);
  104. $template->setActualPage(1);
  105. $template->setMaxPages($pages[1]);
  106. $content = $pages[0];
  107. }else {
  108. $template->setActualPage($_GET["page"]);
  109. $template->setMaxPages($_GET["pages"]);
  110. $content = @file_get_contents( $category . "&start=" . ((((int)$_GET["page"])-1)*10) . "/");
  111. $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
  112. $content = str_replace($newlines, "", html_entity_decode($content,ENT_QUOTES,"UTF-8"));
  113. }
  114. //Get movies block
  115. $content = strstr($content,"<!-- Start link loop -->");
  116. $content = substr($content, 0, strpos($content,"<!-- End link loop -->"));
  117. preg_match_all("/<div style=\"float: left; padding: 0 4px 4px 0;\">(.*)<a href=\"(.*)\" target=\"\"><img src=\"(.*)\"(.*)title=\"(.*)\"/siU", $content, $links, PREG_SET_ORDER);
  118. //var_dump($links);
  119. if($links) {
  120. foreach ($links as $link) {
  121. $template->addItem(
  122. $link[5],
  123. $movieDescription,
  124. SCRAPER_URL . "index.php?title=" . base64_encode($link[5]) . URL_AMP . "item=" . base64_encode($link[2]) . URL_AMP . "image=" . base64_encode($link[3]) . URL_AMP . "PHPSESID=" . session_id(),
  125. $link[3]
  126. );
  127. }
  128. }
  129. $template->generateView(MarocTemplate::VIEW_MOVIE, "");
  130. }
  131. }
  132. /**
  133. */
  134. function fetchMovie($movie,$title,$image) {
  135. $template = new MarocTemplate();
  136. $template->setMovieTitle($title);
  137. $template->setImage($image);
  138. //Parse movie page
  139. $content = file_get_contents($movie);
  140. $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
  141. $content = str_replace($newlines, "", html_entity_decode( $content,ENT_QUOTES,"UTF-8") );
  142. $content = strstr($content,"<fieldset class=\"film_description\">");
  143. $content = strstr($content, "</table>");
  144. $description = substr($content, 8, strpos($content, "</fieldset>")-8);
  145. $template->setDescription($description);
  146. //Get megavideo id and link
  147. preg_match("/wwwstatic.megavideo.com\/mv_player.swf(.*)&v=(.*)\"/siU", $content, $links);
  148. if($links && $links[2]) {
  149. $megavideo_id = $links[2];
  150. if( COOKIE_STATE_ACTIVATED && $megavideo_id ) {
  151. $array = VideoUtil::generateMegavideoPremiumLink($megavideo_id);
  152. if($array) {
  153. $template->addMediaItem(
  154. $title,
  155. $description,
  156. $array[1],
  157. "",
  158. $image
  159. );
  160. }
  161. }
  162. }
  163. $template->generateView(MarocTemplate::VIEW_MOVIE_DETAIL);
  164. }
  165. //------------------------------------------------------------------------------
  166. //------------------------------------------------------------------------------
  167. function getPages($url) {
  168. $content = @file_get_contents($url);
  169. $newlines = array("\t","\n","\r","\x20\x20","\0","\x0B");
  170. $content = str_replace($newlines, "", html_entity_decode($content,ENT_QUOTES,"UTF-8"));
  171. //Get page list begin
  172. $newcontent = strstr($content, "<b>(1)");
  173. $newcontent = substr($newcontent, 0, strpos($newcontent, "</div>") );
  174. preg_match_all("/start=(.*)\"/siU", $newcontent, $pages, PREG_SET_ORDER);
  175. if($pages) {
  176. $pages = $pages[ count($pages)-2 ];
  177. $numPages = ((int)trim($pages[1]))/10 + 1;
  178. }else {
  179. $numPages = 1;
  180. }
  181. return array($content,$numPages);
  182. }
  183. ?>