/** Constructor: Obtain the raw data from IMDB site * @constructor imdb_nowplaying */ function __construct() { $req = new MDB_Request($this->nowplayingpage); $req->sendRequest(); $this->page = $req->getResponseBody(); $this->revision = preg_replace('|^.*?(\\d+).*$|', '$1', '$Revision: 471 $'); }
/** * Constructor: Get data from the charts page * @constructor imdb_topcharts * @param optional object mdb_config override default config */ function __construct(mdb_config $config = null) { $req = new MDB_Request($this->chartspage, $config); $req->sendRequest(); $this->page = $req->getResponseBody(); $this->revision = preg_replace('|^.*?(\\d+).*$|', '$1', '$Revision: 691 $'); }
/** Constructor: Get data from the charts page * @constructor imdb_topcharts */ function imdb_topcharts() { $req = new MDB_Request($this->chartspage); $req->sendRequest(); $this->page = $req->getResponseBody(); $this->revision = preg_replace('|^.*?(\\d+).*$|', '$1', '$Revision: 269 $'); }
protected function getPage($page, array $context = array()) { if (!empty($this->page[$page])) { return $this->page[$page]; } $url = "http://" . $this->imdbsite . $this->set_pagename($page, $context); $req = new MDB_Request($url, $this); if (!$req->sendRequest()) { $this->logger->error("[Page] Failed to connect to server when requesting url [{$url}]"); } else { $this->page[$page] = $req->getResponseBody(); } return $this->page[$page]; }
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; }
/** * Request the page from IMDb * @param $url * @return string Page html. Empty string on failure */ protected function requestPage($url) { $this->logger->info("[Page] Requesting [{$url}]"); $req = new MDB_Request($url, $this->config); if (!$req->sendRequest()) { $this->logger->error("[Page] Failed to connect to server when requesting url [{$url}]"); return ''; } if (200 == $req->getStatus()) { return $req->getResponseBody(); } elseif ($redirectUrl = $req->getRedirect()) { $this->logger->debug("[Page] Following redirect from [{$url}] to [{$redirectUrl}]"); return $this->requestPage($redirectUrl); } else { $this->logger->error("[Page] Failed to retrieve url [{url}]. Response headers:{headers}", array('url' => $url, 'headers' => $req->getLastResponseHeaders())); return ''; } }
/** Save the photo to disk * @method savephoto * @param string path where to store the file * @param optional boolean thumb get the thumbnail (100x140, default) or the * bigger variant (400x600 - FALSE) * @return boolean success * @see IMDB page / (TitlePage) */ public function savephoto($path, $thumb = true, $rerun = 0) { switch ($rerun) { case 2: $req = new MDB_Request(''); break; case 1: $req = new MDB_Request('', '', !$this->trigger_referer); break; default: $req = new MDB_Request('', '', $this->trigger_referer); break; } $photo_url = $this->photo($thumb); if (!$photo_url) { return FALSE; } $req->setURL($photo_url); $req->sendRequest(); if (strpos($req->getResponseHeader("Content-Type"), 'image/jpeg') === 0 || strpos($req->getResponseHeader("Content-Type"), 'image/gif') === 0 || strpos($req->getResponseHeader("Content-Type"), 'image/bmp') === 0) { $fp = $req->getResponseBody(); } else { switch ($rerun) { case 2: $ctype = $req->getResponseHeader("Content-Type"); $this->debug_scalar("<BR>*photoerror* at " . __FILE__ . " line " . __LINE__ . ": " . $photo_url . ": Content Type is '{$ctype}'<BR>"); if (substr($ctype, 0, 4) == 'text') { $this->debug_scalar("Details: <PRE>" . $req->getResponseBody() . "</PRE>\n"); } return FALSE; break; case 1: $this->debug_scalar("<BR>Initiate third run for savephoto({$path}) on IMDBID " . $this->imdbID . "<BR>"); unset($req); return $this->savephoto($path, $thumb, 2); break; default: $this->debug_scalar("<BR>Initiate second run for savephoto({$path}) on IMDBID " . $this->imdbID . "<BR>"); unset($req); return $this->savephoto($path, $thumb, 1); break; } } $fp2 = fopen($path, "w"); if (!$fp || !$fp2) { $this->debug_scalar("image error at " . __FILE__ . " line " . __LINE__ . "...<BR>"); return false; } fputs($fp2, $fp); return TRUE; }
/** 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('!".+"!', $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; }
/** * Save the poster/cover photo to disk * @param string $path where to store the file * @param boolean $thumb get the thumbnail (100x140, default) or the * bigger variant (400x600 - FALSE) * @return boolean success * @see IMDB page / (TitlePage) */ public function savephoto($path, $thumb = true) { $photo_url = $this->photo($thumb); if (!$photo_url) { return false; } $req = new MDB_Request($photo_url, $this); $req->sendRequest(); if (strpos($req->getResponseHeader("Content-Type"), 'image/jpeg') === 0 || strpos($req->getResponseHeader("Content-Type"), 'image/gif') === 0 || strpos($req->getResponseHeader("Content-Type"), 'image/bmp') === 0) { $fp = $req->getResponseBody(); } else { $ctype = $req->getResponseHeader("Content-Type"); $this->debug_scalar("<BR>*photoerror* at " . __FILE__ . " line " . __LINE__ . ": " . $photo_url . ": Content Type is '{$ctype}'<BR>"); if (substr($ctype, 0, 4) == 'text') { $this->debug_scalar("Details: <PRE>" . $req->getResponseBody() . "</PRE>\n"); } return false; } $fp2 = fopen($path, "w"); if (!$fp || !$fp2) { $this->debug_scalar("image error at " . __FILE__ . " line " . __LINE__ . "...<BR>"); return false; } fputs($fp2, $fp); return true; }
/** 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('!".+"!', $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; }
/** Obtain page from web server * @method private getWebPage * @param string wt internal name of the page * @param string url URL to open */ function getWebPage($wt, $url) { $req = new MDB_Request(""); $req->setURL($url); if ($req->sendRequest() !== FALSE) { $head = $req->getLastResponseHeaders(); } else { $head[0] = "HTTP/1.1 000"; } $response = explode(" ", $head[0]); $this->lastServerResponse = $response[1]; switch (substr($head[0], 0, 12)) { case "HTTP/1.1 000": $this->page[$wt] = "cannot open page"; $this->debug_scalar("cannot open page (could not connect to host): {$url}"); return false; break; case "HTTP/1.1 404": $this->page[$wt] = "cannot open page"; $this->debug_scalar("cannot open page (error 404): {$url}"); return false; break; case "HTTP/1.1 301": case "HTTP/1.1 302": case "HTTP/1.1 200": break; default: $this->debug_scalar("HTTP response code not handled explicitly: '" . $head[0] . "'"); break; } $this->page[$wt] = $req->getResponseBody(); if (strpos(get_class($this), 'imdb') !== FALSE && $this->imdb_utf8recode && function_exists('mb_detect_encoding')) { $cur_encoding = mb_detect_encoding($this->page[$wt]); if (!($cur_encoding == "UTF-8" && mb_check_encoding($this->page[$wt], "UTF-8"))) { $this->page[$wt] = utf8_encode($this->page[$wt]); } } }
/** 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; }
/** Retrieve trailers from azmovietrailers.com * @method getAZMovieTrailers * @param string url page url as retrieved with imdb::videosites * @return array [0..n] of array[url,format] of movie trailers (Flash) */ function getAZMovieTrailers($url) { $req = new MDB_Request($url); $req->sendRequest(); $this->page = $req->getResponseBody(); if ($this->page == "" || $this->page == false) { return false; } preg_match('|flashvars\\="file\\=(http.*)\\&|iUms', $this->page, $match); preg_match('|\\.(.{3})$|i', $match[1], $format); if (!empty($match[1])) { return array(array("url" => $match[1], "format" => $format[1])); } }
/** 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; }
/** Save the photo to disk * @method savephoto * @param string path where to store the file * @param optional boolean thumb get the thumbnail (100x140, default) or the * bigger variant (400x600 - FALSE) * @return boolean success * @see IMDB person page / (Main page) */ public function savephoto($path, $thumb = TRUE, $rerun = FALSE) { $photo_url = $this->photo($thumb); if (!$photo_url) { return FALSE; } $req = new MDB_Request($photo_url, $this); $req->sendRequest(); if (strpos($req->getResponseHeader("Content-Type"), 'image/jpeg') === 0 || strpos($req->getResponseHeader("Content-Type"), 'image/gif') === 0 || strpos($req->getResponseHeader("Content-Type"), 'image/bmp') === 0) { $fp = $req->getResponseBody(); } else { if ($rerun) { $this->debug_scalar("<BR>*photoerror* at " . __FILE__ . " line " . __LINE__ . ": " . $photo_url . ": Content Type is '" . $req->getResponseHeader("Content-Type") . "'<BR>"); return FALSE; } else { $this->debug_scalar("<BR>Initiate second run for photo '{$path}'<BR>"); return $this->savephoto($path, $thumb, TRUE); } } $fp2 = fopen($path, "w"); if (!$fp || !$fp2) { $this->debug_scalar("image error...<BR>"); return false; } fputs($fp2, $fp); return TRUE; }
/** Save the photo to disk * @method savephoto * @param string path where to store the file * @param optional boolean thumb get the thumbnail (100x140, default) or the * bigger variant (400x600 - FALSE) * @return boolean success * @see IMDB page / (TitlePage) */ public function savephoto($path, $thumb = true) { $req = new MDB_Request(""); $photo_url = $this->photo($thumb); if (!$photo_url) { return FALSE; } $req->setURL($photo_url); $req->sendRequest(); if (strpos($req->getResponseHeader("Content-Type"), 'image/jpeg') === 0 || strpos($req->getResponseHeader("Content-Type"), 'image/gif') === 0 || strpos($req->getResponseHeader("Content-Type"), 'image/bmp') === 0) { $fp = $req->getResponseBody(); } else { $this->debug_scalar("<BR>*photoerror* " . $photo_url . ": Content Type is '" . $req->getResponseHeader("Content-Type") . "'<BR>"); return false; } $fp2 = fopen($path, "w"); if (!$fp || !$fp2) { $this->debug_scalar("image error...<BR>"); return false; } fputs($fp2, $fp); return TRUE; }
/** Obtain page from web server * @method protected getWebPage * @param string wt internal name of the page * @param string url URL to open */ protected function getWebPage($wt, $url) { $req = new MDB_Request(""); $req->setURL($url); if ($req->sendRequest() !== FALSE) { $head = $req->getLastResponseHeaders(); } else { $head[0] = "HTTP/1.1 000"; } $response = explode(" ", $head[0]); $this->lastServerResponse = $response[1]; switch (substr($head[0], 0, 12)) { case "HTTP/1.1 000": $this->page[$wt] = "cannot open page"; $this->debug_scalar("cannot open page (could not connect to host): {$url}"); return false; break; case "HTTP/1.1 404": $this->page[$wt] = "cannot open page"; $this->debug_scalar("cannot open page (error 404): {$url}"); $this->debug_object($response); return false; break; case "HTTP/1.1 301": // permanent redirect // permanent redirect case "HTTP/1.1 302": // found // found case "HTTP/1.1 303": // see other // see other case "HTTP/1.1 307": // temporary redirect // in all these cases, the correct URL is to be found in the 'Location:' header foreach ($head as $headline) { if (strpos(trim(strtolower($headline)), 'location') !== 0) { continue; } $aline = explode(': ', $headline); $target = trim($aline[1]); $this->getWebPage($wt, $target); return; } // echo "<pre>";print_r($head);echo "</pre>\n"; // $this->debug_object($response); // echo "<pre>";print_r($head);echo "</pre>\n"; // $this->debug_object($response); case "HTTP/1.1 200": break; default: $this->debug_scalar("HTTP response code not handled explicitly: '" . $head[0] . "'"); break; } $this->page[$wt] = $req->getResponseBody(); if (strpos(get_class($this), 'imdb') !== FALSE && $this->imdb_utf8recode && function_exists('mb_detect_encoding')) { $cur_encoding = mb_detect_encoding($this->page[$wt]); if (!($cur_encoding == "UTF-8" && mb_check_encoding($this->page[$wt], "UTF-8"))) { $this->page[$wt] = utf8_encode($this->page[$wt]); } } }
/** 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_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 * @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; }