Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.74 KB | None | 0 0
  1. <?php
  2. class IWatchOnline {
  3.  
  4. var $curl = null;
  5.  
  6. function __construct() {
  7. global $basepath;
  8. $this->curl = new Curl();
  9. $this->curl->setCookieFile($basepath . "/cachefiles/iwatchonline.cookie.txt");
  10. }
  11.  
  12. public function getTitle($title) {
  13. $title = trim($title);
  14. return $title;
  15. }
  16.  
  17. public function getMovieEmbeds($title) {
  18. $embeds = array();
  19. $misc = new Misc();
  20. $dom = new DOMDocument;
  21. $movie_url = null;
  22.  
  23. $data = array(
  24. 'searchin' => '1',
  25. 'searchquery' => $title
  26. );
  27.  
  28. $page = $this->curl->plainPost('http://www.iwatchonline.ag/advance-search', $data);
  29.  
  30. @$dom->loadHTML($page);
  31.  
  32. $tds = $dom->getElementsByTagName('td');
  33.  
  34. if($tds->length > 0){
  35. $part = $tds->item(0)->getElementsByTagName('a');
  36.  
  37. if($part->length > 0){
  38. $movie_url = $part->item(0)->getAttribute("href");
  39.  
  40. }
  41.  
  42. }
  43.  
  44. if (is_null($movie_url)) {
  45. return array();
  46. }
  47.  
  48. $movie_url = str_replace("https", "http", $movie_url);
  49.  
  50. $movie_data = $this->curl->get($movie_url);
  51. @$dom->loadHTML($movie_data);
  52.  
  53. $parts = $dom->getElementsByTagName('a');
  54.  
  55. foreach($parts as $part){
  56.  
  57. $part_check = $part->getAttribute("href");
  58.  
  59. if(substr_count($part_check, '/play/')){
  60.  
  61. $link = $this->getLink($part->getAttribute("href"));
  62.  
  63. if($link){
  64. $embed = $misc->buildEmbed($link);
  65.  
  66. if ($embed) {
  67. $embeds[] = array(
  68. "embed" => $embed,
  69. "link" => $link,
  70. "language" => "ENG",
  71. );
  72. }
  73. }
  74. }
  75. }
  76.  
  77. return $embeds;
  78. }
  79.  
  80. public function getLink($url){
  81. $page = $this->curl->get($url);
  82. $dom = new DOMDocument;
  83. @$dom->loadHTML($page);
  84.  
  85. $movie_link = $dom->getElementsByTagName('iframe');
  86.  
  87. if($movie_link->length > 0){
  88. return $movie_link->item(0)->getAttribute("src");
  89. }else{
  90. return null;
  91. }
  92. }
  93.  
  94. public function getEmbeds($title, $showid, $season, $episode) {
  95. $misc = new Misc();
  96.  
  97.  
  98. //Step 1 Find TVshow Url
  99. $request = array(
  100. 'http' => array(
  101. 'method' => 'POST',
  102. 'header' => "Accept-language: en-US,en;q=0.5\r\n" .
  103. "Content-type: application/x-www-form-urlencoded; charset=UTF-8\r\n".
  104. "Host: http://www.iwatchonline.ag\r\n".
  105. "Referer: http://www.iwatchonline.ag/advance-search\r\n".
  106. "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0 FirePHP/0.7.4\r\n",
  107. 'content' => http_build_query(array(
  108. 'searchin' => '2',
  109. 'searchquery' => $title
  110. )),
  111. )
  112. );
  113.  
  114. $context = stream_context_create($request);
  115. $html = file_get_html('http://www.iwatchonline.ag/advance-search', false, $context);
  116. if(is_null($html) || $html=="") { return array(); }
  117. $elements = $html->find('.search-page td > a');
  118.  
  119. $movie_url = null;
  120. if (!is_null($elements)) {
  121. foreach ($elements as $element) {
  122. $clean = trim(preg_replace("/\([^)]+\)/","",strtolower($element->innertext)));
  123. if ($clean == strtolower(trim($title))) {
  124. $movie_url = str_replace("/episode/", "/tv-shows/", $element->href);
  125. break;
  126. }
  127.  
  128. }
  129. }
  130.  
  131. if (is_null($movie_url)) {
  132. //echo "Could not find any video on iWatchonline for $title.\n";
  133. return array();
  134. }
  135. //Step 2 Find Embeds Links...
  136. $season_term = "season" . str_pad($season, 2, "0", STR_PAD_LEFT);
  137. $episode_term = "Episode " . str_pad($episode, 2, "0", STR_PAD_LEFT);
  138.  
  139. $html = file_get_html($movie_url);
  140. if(is_null($html) || $html=="") { return array(); }
  141. $elements = $html->find('#' . $season_term . " .sideleft a");
  142.  
  143. if (!is_null($elements)) {
  144.  
  145. $embeds = array();
  146. foreach ($elements as $element) {
  147.  
  148. if (trim(strip_tags($element->innertext)) == $episode_term) {
  149. $html2 = file_get_html($element->href);
  150. if(is_null($html2) || $html2=="") { continue; }
  151. $elements2 = $html2->find('#streamlinks .sideleft a');
  152. if (!is_null($elements2)) {
  153. foreach ($elements2 as $element) {
  154. $html3 = file_get_html($element->href);
  155. if(is_null($html3) || $html3=="") { continue; }
  156. $iframe_element = $html3->find('.frame', 0);
  157. if (!is_null($iframe_element)) {
  158. $embed = $misc->buildEmbed($iframe_element->src);
  159. if ($embed) {
  160. $embeds[] = array(
  161. "embed" => $embed,
  162. "link" => $iframe_element->src,
  163. "language" => "ENG",
  164. );
  165. }
  166. }
  167. }
  168. }
  169. }
  170. }
  171. return $embeds;
  172. }
  173. return array();
  174. }
  175.  
  176. public function getRandomMovies(){
  177. //MAX = 353 //you can increase this if more movies added on website
  178. $min = 1; $max = 353; //min is 2 because we can get first page from recent movies function
  179. $page = rand ($min, $max) * 25;
  180. return $this->getRecentMovies($page);
  181. }
  182.  
  183. public function getRecentMovies($page=1) {
  184. $movies = array();
  185. if($page==1){
  186. $html = file_get_html("http://www.iwatchonline.ag/movies");
  187. } else {
  188. $html = file_get_html("http://www.iwatchonline.ag/movies?&p=".$page);
  189. }
  190. if(is_null($html) || $html=="") { return array(); }
  191. $elements = $html->find("#listings .thumbnails li .title");
  192. if(!is_null($elements)){
  193. foreach($elements as $element){
  194. $movie_name = trim(strip_tags($element->innertext));
  195. if(is_numeric(substr($movie_name,-4))){
  196. $movie_name = trim(substr($movie_name,0,-4));
  197. }
  198. $movies[] = $movie_name;
  199. }
  200. }
  201. return $movies;
  202. }
  203.  
  204. }
  205.  
  206. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement