Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class IWatchOnline {
- var $curl = null;
- function __construct() {
- global $basepath;
- $this->curl = new Curl();
- $this->curl->setCookieFile($basepath . "/cachefiles/iwatchonline.cookie.txt");
- }
- public function getTitle($title) {
- $title = trim($title);
- return $title;
- }
- public function getMovieEmbeds($title) {
- $embeds = array();
- $misc = new Misc();
- $dom = new DOMDocument;
- $movie_url = null;
- $data = array(
- 'searchin' => '1',
- 'searchquery' => $title
- );
- $page = $this->curl->plainPost('http://www.iwatchonline.ag/advance-search', $data);
- @$dom->loadHTML($page);
- $tds = $dom->getElementsByTagName('td');
- if($tds->length > 0){
- $part = $tds->item(0)->getElementsByTagName('a');
- if($part->length > 0){
- $movie_url = $part->item(0)->getAttribute("href");
- }
- }
- if (is_null($movie_url)) {
- return array();
- }
- $movie_url = str_replace("https", "http", $movie_url);
- $movie_data = $this->curl->get($movie_url);
- @$dom->loadHTML($movie_data);
- $parts = $dom->getElementsByTagName('a');
- foreach($parts as $part){
- $part_check = $part->getAttribute("href");
- if(substr_count($part_check, '/play/')){
- $link = $this->getLink($part->getAttribute("href"));
- if($link){
- $embed = $misc->buildEmbed($link);
- if ($embed) {
- $embeds[] = array(
- "embed" => $embed,
- "link" => $link,
- "language" => "ENG",
- );
- }
- }
- }
- }
- return $embeds;
- }
- public function getLink($url){
- $page = $this->curl->get($url);
- $dom = new DOMDocument;
- @$dom->loadHTML($page);
- $movie_link = $dom->getElementsByTagName('iframe');
- if($movie_link->length > 0){
- return $movie_link->item(0)->getAttribute("src");
- }else{
- return null;
- }
- }
- public function getEmbeds($title, $showid, $season, $episode) {
- $misc = new Misc();
- //Step 1 Find TVshow Url
- $request = array(
- 'http' => array(
- 'method' => 'POST',
- 'header' => "Accept-language: en-US,en;q=0.5\r\n" .
- "Content-type: application/x-www-form-urlencoded; charset=UTF-8\r\n".
- "Host: http://www.iwatchonline.ag\r\n".
- "Referer: http://www.iwatchonline.ag/advance-search\r\n".
- "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0 FirePHP/0.7.4\r\n",
- 'content' => http_build_query(array(
- 'searchin' => '2',
- 'searchquery' => $title
- )),
- )
- );
- $context = stream_context_create($request);
- $html = file_get_html('http://www.iwatchonline.ag/advance-search', false, $context);
- if(is_null($html) || $html=="") { return array(); }
- $elements = $html->find('.search-page td > a');
- $movie_url = null;
- if (!is_null($elements)) {
- foreach ($elements as $element) {
- $clean = trim(preg_replace("/\([^)]+\)/","",strtolower($element->innertext)));
- if ($clean == strtolower(trim($title))) {
- $movie_url = str_replace("/episode/", "/tv-shows/", $element->href);
- break;
- }
- }
- }
- if (is_null($movie_url)) {
- //echo "Could not find any video on iWatchonline for $title.\n";
- return array();
- }
- //Step 2 Find Embeds Links...
- $season_term = "season" . str_pad($season, 2, "0", STR_PAD_LEFT);
- $episode_term = "Episode " . str_pad($episode, 2, "0", STR_PAD_LEFT);
- $html = file_get_html($movie_url);
- if(is_null($html) || $html=="") { return array(); }
- $elements = $html->find('#' . $season_term . " .sideleft a");
- if (!is_null($elements)) {
- $embeds = array();
- foreach ($elements as $element) {
- if (trim(strip_tags($element->innertext)) == $episode_term) {
- $html2 = file_get_html($element->href);
- if(is_null($html2) || $html2=="") { continue; }
- $elements2 = $html2->find('#streamlinks .sideleft a');
- if (!is_null($elements2)) {
- foreach ($elements2 as $element) {
- $html3 = file_get_html($element->href);
- if(is_null($html3) || $html3=="") { continue; }
- $iframe_element = $html3->find('.frame', 0);
- if (!is_null($iframe_element)) {
- $embed = $misc->buildEmbed($iframe_element->src);
- if ($embed) {
- $embeds[] = array(
- "embed" => $embed,
- "link" => $iframe_element->src,
- "language" => "ENG",
- );
- }
- }
- }
- }
- }
- }
- return $embeds;
- }
- return array();
- }
- public function getRandomMovies(){
- //MAX = 353 //you can increase this if more movies added on website
- $min = 1; $max = 353; //min is 2 because we can get first page from recent movies function
- $page = rand ($min, $max) * 25;
- return $this->getRecentMovies($page);
- }
- public function getRecentMovies($page=1) {
- $movies = array();
- if($page==1){
- $html = file_get_html("http://www.iwatchonline.ag/movies");
- } else {
- $html = file_get_html("http://www.iwatchonline.ag/movies?&p=".$page);
- }
- if(is_null($html) || $html=="") { return array(); }
- $elements = $html->find("#listings .thumbnails li .title");
- if(!is_null($elements)){
- foreach($elements as $element){
- $movie_name = trim(strip_tags($element->innertext));
- if(is_numeric(substr($movie_name,-4))){
- $movie_name = trim(substr($movie_name,0,-4));
- }
- $movies[] = $movie_name;
- }
- }
- return $movies;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement