Example #1
0
 protected function makeRequest($url)
 {
     mdb_base::debug_scalar("imdbsearch: Using URL {$url}");
     $be = new MDB_Request($url, $this);
     $be->sendrequest();
     $body = $be->getResponseBody();
     // @TODO The intricacies of http should be delt with by the http library
     // @TODO does this ever happen?
     if ($header = $be->getResponseHeader("Location")) {
         mdb_base::debug_scalar("imdbsearch: No immediate response body - we are redirected.<br>New URL: {$header}");
         if (substr($header, 0, 1) == '/') {
             return $this->makeRequest($this->imdbsite . $header);
         } else {
             return $this->makeRequest($header);
         }
     }
     return $body;
 }
 /** Setup search results
  * @method results
  * @param optional string URL Replace search URL by your own
  * @return array results array of objects (instances of the imdb_person class)
  */
 public function results($url = "")
 {
     if ($this->page == "") {
         if (empty($url)) {
             $url = $this->mkurl();
         }
         $be = new MDB_Request($url);
         $be->sendrequest();
         $fp = $be->getResponseBody();
         if (!$fp) {
             if ($header = $be->getResponseHeader("Location")) {
                 if (strpos($header, $this->imdbsite . "/find?")) {
                     return $this->results($header);
                     break 4;
                 }
                 $url = explode("/", $header);
                 $id = substr($url[count($url) - 2], 2);
                 $this->resu[0] = new imdb_person($id);
                 return $this->resu;
             } else {
                 return NULL;
             }
         }
         $this->page = $fp;
     }
     // end (page="")
     if ($this->maxresults > 0) {
         $maxresults = $this->maxresults;
     } else {
         $maxresults = 999999;
     }
     // make sure to catch col #3, not #1 (pic only)
     preg_match_all('|<tr>\\s*<td.*>.*</td>\\s*<td.*>.*</td>\\s*<td.*<a href="/name/nm(\\d{7})[^>]*>([^<]+)</a>(.*)</td>|Uims', $this->page, $matches);
     $mc = count($matches[0]);
     $mids_checked = array();
     for ($i = 0; $i < $mc; ++$i) {
         if ($i == $maxresults) {
             break;
         }
         // limit result count
         $pid = $matches[1][$i];
         if (in_array($pid, $mids_checked)) {
             continue;
         }
         $mids_checked[] = $pid;
         $name = $matches[2][$i];
         $info = $matches[3][$i];
         $tmpres = new imdb_person($pid);
         $tmpres->fullname = $name;
         if (!empty($info)) {
             if (preg_match('|<small>\\((.*),\\s*<a href="/title/tt(\\d{7})/">(.*)</a>\\s*\\((\\d{4})\\)\\)|Ui', $info, $match)) {
                 $role = $match[1];
                 $mid = $match[2];
                 $movie = $match[3];
                 $year = $match[4];
                 $tmpres->setSearchDetails($role, $mid, $movie, $year);
             }
         }
         $this->resu[$i] = $tmpres;
         unset($tmpres);
     }
     return $this->resu;
 }
 /** Setup search results
  * @method results
  * @param optional string URL Replace search URL by your own (Default: empty string)
  * @param optional boolean series whether to include TV series in search results (default: TRUE)
  * @param optional boolean s_episodes whether to include TV episodes in search results (default: TRUE)
  * @param optional boolean s_games whether to include games in search results (default: TRUE)
  * @param optional boolean s_video whether to include videos in search results (default: TRUE). These are often Making Ofs and the like
  * @param optional boolean s_short whether to include shorts in search results (default: TRUE)
  * @param optional boolean s_special whether to include specials in search results (default: TRUE)
  * @return array results array of objects (instances of the imdb class)
  */
 public function results($url = "", $series = TRUE, $s_episodes = TRUE, $s_games = TRUE, $s_video = TRUE, $s_short = TRUE, $s_special = TRUE)
 {
     if ($this->page == "") {
         if ($this->usecache && empty($url)) {
             // Try to read from cache
             $this->cache_read(urlencode(strtolower($this->name)) . '.search', $this->page);
         }
         // end cache read
         if ($this->page == "") {
             // not found in cache - go and get it!
             if (empty($url)) {
                 $url = $this->mkurl();
             }
             mdb_base::debug_scalar("imdbsearch::results() called. Using URL {$url}");
             $be = new MDB_Request($url);
             $be->sendrequest();
             $fp = $be->getResponseBody();
             if (!$fp) {
                 if ($header = $be->getResponseHeader("Location")) {
                     mdb_base::debug_scalar("No immediate response body - we are redirected.<br>New URL: {$header}");
                     if (preg_match('!\\.imdb\\.(com|de|it)/find\\?!', $header)) {
                         return $this->results($header);
                         break 4;
                     }
                     $url = explode("/", $header);
                     $id = substr($url[count($url) - 1], 2);
                     $this->resu[0] = new imdb($id);
                     return $this->resu;
                 } else {
                     mdb_base::debug_scalar('No response body, no redirect - going to Nirwana');
                     return NULL;
                 }
             }
             $this->page = $fp;
         }
         if ($this->storecache && $this->page != "cannot open page" && $this->page != "") {
             //store cache
             $this->cache_write(urlencode(strtolower($this->name)) . '.search', $this->page);
         }
     }
     // end (page="")
     // now we have the search content - go and parse it!
     if ($this->maxresults > 0) {
         $maxresults = $this->maxresults;
     } else {
         $maxresults = 999999;
     }
     if (preg_match_all('!class="result_text"\\s*>\\s*<a href="/title/tt(?<imdbid>\\d{7})/[^>]*>(?<title>.*?)</a>\\s*(\\([^\\d{4}]\\)\\s*)?(\\((?<year>\\d{4})(.*?|)\\)|)(?<addons>[^<]*)!ims', $this->page, $matches)) {
         $this->last_results = count($matches[0]);
         $mids_checked = array();
         for ($i = 0; $i < $this->last_results; ++$i) {
             if (count($this->resu) == $maxresults) {
                 break;
             }
             // limit result count
             if (substr(trim($matches[2][$i]), 0, 4) == "<img") {
                 continue;
             }
             // cover mini
             if (empty($matches[2][$i]) || substr(trim($matches[2][$i]), 0, 4) == '<img' || in_array($matches[1][$i], $mids_checked)) {
                 continue;
             }
             // empty titles just come from the images
             if (!$series && (preg_match('!&#x22;.+&#x22;!', $matches[2][$i]) || strpos(strtoupper($matches['addons'][$i]), 'TV SERIES') !== FALSE)) {
                 continue;
             }
             // skip series if commanded so
             if (!$s_episodes && strpos(strtoupper($matches['addons'][$i]), 'TV EPISODE') !== FALSE) {
                 continue;
             }
             // skip episodes if commanded so
             if (!$s_games && strpos(strtoupper($matches['addons'][$i]), 'VIDEO GAME') !== FALSE) {
                 continue;
             }
             // skip games if commanded so
             if (!$s_video && strpos(strtoupper($matches['addons'][$i]), '(VIDEO)') !== FALSE) {
                 continue;
             }
             // skip games if commanded so
             if (!$s_short && strpos(strtoupper($matches['addons'][$i]), '(SHORT)') !== FALSE) {
                 continue;
             }
             // skip shorts if commanded so
             if (!$s_special && strpos(strtoupper($matches['addons'][$i]), 'SPECIAL)') !== FALSE) {
                 continue;
             }
             // skip specials if commanded so
             $mids_checked[] = $matches['imdbid'][$i];
             $tmpres = new imdb($matches['imdbid'][$i]);
             // make a new imdb object by id
             $tmpres->main_title = $matches['title'][$i];
             $tmpres->main_year = $matches['year'][$i];
             $tmpres->addon_info = $matches['addons'][$i];
             $this->resu[] = $tmpres;
         }
     }
     return $this->resu;
 }
 /** Setup search results
  * @method results
  * @param optional string URL Replace search URL by your own (Default: empty string)
  * @param optional boolean series whether to include TV series in search results (default: TRUE)
  * @return array results array of objects (instances of the imdb class)
  */
 public function results($url = "", $series = TRUE)
 {
     if ($this->page == "") {
         if ($this->usecache && empty($url)) {
             // Try to read from cache
             $this->cache_read(urlencode(strtolower($this->name)) . '.search', $this->page);
         }
         // end cache read
         if ($this->page == "") {
             // not found in cache - go and get it!
             if (empty($url)) {
                 $url = $this->mkurl();
             }
             mdb_base::debug_scalar("imdbsearch::results() called. Using URL {$url}");
             $be = new MDB_Request($url);
             $be->sendrequest();
             $fp = $be->getResponseBody();
             if (!$fp) {
                 if ($header = $be->getResponseHeader("Location")) {
                     mdb_base::debug_scalar("No immediate response body - we are redirected.<br>New URL: {$header}");
                     if (preg_match('!\\.imdb\\.(com|de|it)/find\\?!', $header)) {
                         return $this->results($header);
                         break 4;
                     }
                     $url = explode("/", $header);
                     $id = substr($url[count($url) - 2], 2);
                     $this->resu[0] = new imdb($id);
                     return $this->resu;
                 } else {
                     mdb_base::debug_scalar('No response body, no redirect - going to Nirwana');
                     return NULL;
                 }
             }
             $this->page = $fp;
         }
         if ($this->storecache && $this->page != "cannot open page" && $this->page != "") {
             //store cache
             $this->cache_write(urlencode(strtolower($this->name)) . '.search', $this->page);
         }
     }
     // end (page="")
     // now we have the search content - go and parse it!
     if ($this->maxresults > 0) {
         $maxresults = $this->maxresults;
     } else {
         $maxresults = 999999;
     }
     if (preg_match_all('!href="/title/tt(\\d{7})/"[^>]*>(.*?)</a>\\s*(\\((\\d{4})(/.+?|)\\)|)[^<]*(<small>(.*?)</small>|)!ims', $this->page, $matches)) {
         $this->last_results = count($matches[0]);
         $mids_checked = array();
         for ($i = 0; $i < $this->last_results; ++$i) {
             if (count($this->resu) == $maxresults) {
                 break;
             }
             // limit result count
             if (empty($matches[2][$i]) || substr(trim($matches[2][$i]), 0, 4) == '<img' || in_array($matches[1][$i], $mids_checked)) {
                 continue;
             }
             // empty titles just come from the images
             if (!$series && (preg_match('!&#x22;.+&#x22;!', $matches[2][$i]) || strpos(strtoupper($matches[7][$i]), 'TV SERIES') !== FALSE)) {
                 continue;
             }
             // skip series if commanded so
             if (!preg_match('!onclick!i', $matches[0][$i])) {
                 continue;
             }
             // just mentioned something in the AKAs listing
             $mids_checked[] = $matches[1][$i];
             $tmpres = new imdb($matches[1][$i]);
             // make a new imdb object by id
             $tmpres->main_title = $matches[2][$i];
             $tmpres->main_year = $matches[4][$i];
             $this->resu[] = $tmpres;
         }
     }
     return $this->resu;
 }
Example #5
0
 /** Setup search results
  * @method results
  * @param optional string URL Replace search URL by your own
  * @return array results array of objects (instances of the imdb class)
  */
 public function results($url = "")
 {
     if (empty($this->pilot_apikey)) {
         trigger_error('Please provide a valid api key or contact api@moviepilot.de.', E_USER_WARNING);
         return array();
     }
     // get the result list
     if ($this->page == "") {
         if (empty($url)) {
             $url = $this->mkurl();
         }
         $be = new MDB_Request($url);
         $be->sendrequest();
         $fp = $be->getResponseBody();
         if ($fp == '{"error":"please provide a valid api key or contact api@moviepilot.de"}') {
             $this->debug_scalar('ERROR: invalid API key');
             trigger_error('Please provide a valid api key or contact api@moviepilot.de.', E_USER_WARNING);
             return array();
         }
         $this->page = json_decode($fp);
     }
     // end (page="")
     // parse results
     $i = 0;
     if (!empty($this->page->movies)) {
         foreach ($this->page->movies as $movie) {
             if ($this->maxresults && $i > $this->maxresults) {
                 break;
             }
             ++$i;
             $mid = str_pad($movie->alternative_identifiers->imdb, 7, 0, STR_PAD_LEFT);
             $item = new pilot($mid);
             $item->page['Title'] = $movie;
             $item->setid($mid);
             $this->resu[] = $item;
             if ($this->storecache) {
                 $this->cache_write($mid . '.' . 'Title.pilot', json_encode($movie));
             }
         }
     }
     return $this->resu;
 }
 /** Setup search results
  * @method results
  * @param optional string URL Replace search URL by your own
  * @return array results array of objects (instances of the imdb class)
  */
 public function results($url = "")
 {
     if ($this->page == "") {
         if ($this->usecache && empty($url)) {
             // Try to read from cache
             $this->cache_read(urlencode(strtolower($this->name)) . '.search', $this->page);
         }
         // end cache read
         if ($this->page == "") {
             // not found in cache - go and get it!
             if (empty($url)) {
                 $url = $this->mkurl();
             }
             mdb_base::debug_scalar("imdbsearch::results() called. Using URL {$url}");
             $be = new MDB_Request($url);
             $be->sendrequest();
             $fp = $be->getResponseBody();
             if (!$fp) {
                 if ($header = $be->getResponseHeader("Location")) {
                     mdb_base::debug_scalar("No immediate response body - we are redirected.<br>New URL: {$header}");
                     if (preg_match('!\\.imdb\\.(com|de|it)/find\\?!', $header)) {
                         return $this->results($header);
                         break 4;
                     }
                     $url = explode("/", $header);
                     $id = substr($url[count($url) - 2], 2);
                     $this->resu[0] = new imdb($id);
                     return $this->resu;
                 } else {
                     mdb_base::debug_scalar('No response body, no redirect - going to Nirwana');
                     return NULL;
                 }
             }
             $this->page = $fp;
         }
         if ($this->storecache && $this->page != "cannot open page" && $this->page != "") {
             //store cache
             $this->cache_write(urlencode(strtolower($this->name)) . '.search', $this->page);
         }
     }
     // end (page="")
     // now we have the search content - go and parse it!
     $searchstring = array('<A HREF="/title/tt', '<A href="/title/tt', '<a href="/Title?', '<a href="/title/tt');
     $i = 0;
     if ($this->maxresults > 0) {
         $maxresults = $this->maxresults;
     } else {
         $maxresults = 999999;
     }
     foreach ($searchstring as $srch) {
         $res_e = 0;
         $res_s = 0;
         $mids_checked = array();
         $len = strlen($srch);
         while (($res_s = strpos($this->page, $srch, $res_e)) > 10) {
             if ($i == $maxresults) {
                 break 2;
             }
             // limit result count
             $res_e = strpos($this->page, "(", $res_s);
             $imdb_id = substr($this->page, $res_s + $len, 7);
             $ts = strpos($this->page, ">", $res_s) + 1;
             // >movie title</a>
             $te = strpos($this->page, "<", $ts);
             $title = substr($this->page, $ts, $te - $ts);
             if ($title == "" || in_array($imdb_id, $mids_checked)) {
                 continue;
             }
             // empty titles just come from the images
             $mids_checked[] = $imdb_id;
             $tmpres = new imdb($imdb_id);
             // make a new imdb object by id
             $tmpres->main_title = $title;
             $ts = strpos($this->page, "(", $te) + 1;
             $te = strpos($this->page, ")", $ts);
             $tmpres->main_year = substr($this->page, $ts, $te - $ts);
             $i++;
             $this->resu[] = $tmpres;
         }
     }
     return $this->resu;
 }
 /** Setup search results
  * @method results
  * @param optional string URL Replace search URL by your own
  * @return array results array of objects (instances of the imdb class)
  */
 public function results($url = "")
 {
     if ($this->page == "") {
         if (empty($url)) {
             $url = $this->mkurl();
         }
         $be = new MDB_Request($url);
         $be->sendrequest();
         $fp = $be->getResponseBody();
         if (!$fp) {
             if ($header = $be->getResponseHeader("Location")) {
                 if (strpos($header, $this->imdbsite . "/find?")) {
                     return $this->results($header);
                     break 4;
                 }
                 $url = explode("/", $header);
                 $id = substr($url[count($url) - 2], 2);
                 $this->resu[0] = new imdb($id);
                 return $this->resu;
             } else {
                 return NULL;
             }
         }
         $this->page = $fp;
     }
     // end (page="")
     $searchstring = array('<A HREF="/title/tt', '<A href="/title/tt', '<a href="/Title?', '<a href="/title/tt');
     $i = 0;
     if ($this->maxresults > 0) {
         $maxresults = $this->maxresults;
     } else {
         $maxresults = 999999;
     }
     foreach ($searchstring as $srch) {
         $res_e = 0;
         $res_s = 0;
         $mids_checked = array();
         $len = strlen($srch);
         while (($res_s = strpos($this->page, $srch, $res_e)) > 10) {
             if ($i == $maxresults) {
                 break 2;
             }
             // limit result count
             $res_e = strpos($this->page, "(", $res_s);
             $imdb_id = substr($this->page, $res_s + $len, 7);
             $ts = strpos($this->page, ">", $res_s) + 1;
             // >movie title</a>
             $te = strpos($this->page, "<", $ts);
             $title = substr($this->page, $ts, $te - $ts);
             if ($title == "" || in_array($imdb_id, $mids_checked)) {
                 continue;
             }
             // empty titles just come from the images
             $mids_checked[] = $imdb_id;
             $tmpres = new imdb($imdb_id);
             // make a new imdb object by id
             $tmpres->main_title = $title;
             $ts = strpos($this->page, "(", $te) + 1;
             $te = strpos($this->page, ")", $ts);
             $tmpres->main_year = substr($this->page, $ts, $te - $ts);
             $i++;
             $this->resu[] = $tmpres;
         }
     }
     return $this->resu;
 }
 /**
  * Setup search results
  * @method results
  * @param optional string URL Replace search URL by your own
  * @return array results array of objects (instances of the imdb_person class)
  */
 public function results($url = "")
 {
     if ($this->page == "") {
         if ($this->usecache && empty($url)) {
             // Try to read from cache
             $this->cache_read(urlencode(strtolower($this->name)) . '.search', $this->page);
         }
         // end cache read
         if (empty($url)) {
             $url = $this->mkurl();
         }
         $be = new MDB_Request($url, $this);
         $be->sendrequest();
         $fp = $be->getResponseBody();
         if (!$fp) {
             if ($header = $be->getResponseHeader("Location")) {
                 mdb_base::debug_scalar("No immediate response body - we are redirected.<br>New URL: {$header}");
                 if (strpos($header, $this->imdbsite . "/find?")) {
                     return $this->results($header);
                     break 4;
                 }
                 $url = explode("/", $header);
                 $id = substr($url[count($url) - 2], 2);
                 $this->resu[0] = new imdb_person($id, $this);
                 return $this->resu;
             } else {
                 mdb_base::debug_scalar("No result, no redirection -- something's wrong here...");
                 return NULL;
             }
         }
         $this->page = $fp;
         if ($this->storecache && $this->page != "cannot open page" && $this->page != "") {
             //store cache
             $this->cache_write(urlencode(strtolower($this->name)) . '.search', $this->page);
         }
     }
     // end (page="")
     if ($this->maxresults > 0) {
         $maxresults = $this->maxresults;
     } else {
         $maxresults = 999999;
     }
     // make sure to catch col #3, not #1 (pic only)
     //                        photo           name                   1=id        2=name        3=details
     preg_match_all('|<tr.*>\\s*<td.*>.*</td>\\s*<td.*<a href="/name/nm(\\d{7})[^>]*>([^<]+)</a>\\s*(.*)</td>|Uims', $this->page, $matches);
     $mc = count($matches[0]);
     mdb_base::debug_scalar("{$mc} matches");
     $mids_checked = array();
     for ($i = 0; $i < $mc; ++$i) {
         if ($i == $maxresults) {
             break;
         }
         // limit result count
         $pid = $matches[1][$i];
         if (in_array($pid, $mids_checked)) {
             continue;
         }
         $mids_checked[] = $pid;
         $name = $matches[2][$i];
         $info = $matches[3][$i];
         $tmpres = new imdb_person($pid);
         $tmpres->fullname = $name;
         if (!empty($info)) {
             if (preg_match('|<small>\\((.*),\\s*<a href="/title/tt(\\d{7}).*"\\s*>(.*)</a>\\s*\\((\\d{4})\\)\\)|Ui', $info, $match)) {
                 $role = $match[1];
                 $mid = $match[2];
                 $movie = $match[3];
                 $year = $match[4];
                 $tmpres->setSearchDetails($role, $mid, $movie, $year);
             }
         }
         $this->resu[$i] = $tmpres;
         unset($tmpres);
     }
     return $this->resu;
 }