PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/library/imdb/imdb.class.php

https://github.com/hegylako/openTracker
PHP | 1914 lines | 1307 code | 134 blank | 473 comment | 366 complexity | a93d36f2a5e9b7c81c1aa28dbca14722 MD5 | raw file
Possible License(s): MIT

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. #############################################################################
  3. # IMDBPHP (c) Giorgos Giagas & Itzchak Rehberg #
  4. # written by Giorgos Giagas #
  5. # extended & maintained by Itzchak Rehberg <izzysoft AT qumran DOT org> #
  6. # http://www.izzysoft.de/ #
  7. # ------------------------------------------------------------------------- #
  8. # This program is free software; you can redistribute and/or modify it #
  9. # under the terms of the GNU General Public License (see doc/LICENSE) #
  10. #############################################################################
  11. /* $Id: imdb.class.php 473 2011-10-11 13:14:56Z izzy $ */
  12. require_once (dirname(__FILE__) . "/movie_base.class.php");
  13. #=============================================================================
  14. #=================================================[ The IMDB class itself ]===
  15. #=============================================================================
  16. /** Accessing IMDB information
  17. * @package openTracker
  18. * @class imdb
  19. * @extends movie_base
  20. * @author Georgos Giagas
  21. * @author Izzy (izzysoft AT qumran DOT org)
  22. * @copyright (c) 2002-2004 by Giorgos Giagas and (c) 2004-2009 by Itzchak Rehberg and IzzySoft
  23. * @version $Revision: 473 $ $Date: 2011-10-11 15:14:56 +0200 (Di, 11. Okt 2011) $
  24. */
  25. class imdb extends movie_base {
  26. #======================================================[ Common functions ]===
  27. #-----------------------------------------------------------[ Constructor ]---
  28. /** Initialize the class
  29. * @constructor imdb
  30. * @param string id IMDBID to use for data retrieval
  31. */
  32. function __construct($id) {
  33. parent::__construct($id);
  34. $this->revision = preg_replace('|^.*?(\d+).*$|', '$1', '$Revision: 473 $');
  35. $this->setid($id);
  36. }
  37. #-------------------------------------------------------------[ Open Page ]---
  38. /** Define page urls
  39. * @method protected set_pagename
  40. * @param string wt internal name of the page
  41. * @return string urlname page URL
  42. */
  43. protected function set_pagename($wt) {
  44. switch ($wt) {
  45. case "Title" : $urlname = "/";
  46. break;
  47. case "TitleFoot" : $urlname = "/_ajax/iframe?component=footer";
  48. break;
  49. case "Credits" : $urlname = "/fullcredits";
  50. break;
  51. case "CrazyCredits": $urlname = "/crazycredits";
  52. break;
  53. case "Plot" : $urlname = "/plotsummary";
  54. break;
  55. case "Synopsis" : $urlname = "/synopsis";
  56. break;
  57. case "Taglines" : $urlname = "/taglines";
  58. break;
  59. case "Episodes" : $urlname = "/episodes";
  60. break;
  61. case "Quotes" : $urlname = "/quotes";
  62. break;
  63. case "Trailers" : $urlname = "/trailers";
  64. break;
  65. case "VideoSites" : $urlname = "/videosites";
  66. break;
  67. case "Goofs" : $urlname = "/goofs";
  68. break;
  69. case "Trivia" : $urlname = "/trivia";
  70. break;
  71. case "Soundtrack" : $urlname = "/soundtrack";
  72. break;
  73. case "MovieConnections" : $urlname = "/movieconnections";
  74. break;
  75. case "ExtReviews" : $urlname = "/externalreviews";
  76. break;
  77. case "ReleaseInfo" : $urlname = "/releaseinfo";
  78. break;
  79. case "CompanyCredits" : $urlname = "/companycredits";
  80. break;
  81. case "ParentalGuide" : $urlname = "/parentalguide";
  82. break;
  83. case "OfficialSites" : $urlname = "/officialsites";
  84. break;
  85. case "Keywords" : $urlname = "/keywords";
  86. break;
  87. case "Awards" : $urlname = "/awards";
  88. break;
  89. case "Locations" : $urlname = "/locations";
  90. break;
  91. default :
  92. $this->page[$wt] = "unknown page identifier";
  93. $this->debug_scalar("Unknown page identifier: $wt");
  94. return false;
  95. }
  96. return $urlname;
  97. }
  98. #-----------------------------------------------[ URL to movies main page ]---
  99. /** Set up the URL to the movie title page
  100. * @method main_url
  101. * @return string url full URL to the current movies main page
  102. */
  103. public function main_url() {
  104. return "http://" . $this->imdbsite . "/title/tt" . $this->imdbid() . "/";
  105. }
  106. #======================================================[ Title page infos ]===
  107. #-------------------------------------------[ Movie title (name) and year ]---
  108. /** Setup title and year properties
  109. * @method private title_year
  110. */
  111. private function title_year() {
  112. if ($this->page["Title"] == "")
  113. $this->openpage("Title");
  114. if (@preg_match('!<title>(IMDb\s*-\s*)?(.*) \((.*)(\d{4}|\?{4}).*\)(.*)(\s*-\s*IMDb)?</title>!', $this->page["Title"], $match)) {
  115. $this->main_title = $match[2];
  116. if ($match[3] == "????")
  117. $this->main_year = "";
  118. else
  119. $this->main_year = $match[4];
  120. }
  121. }
  122. /** Get movie title
  123. * @method title
  124. * @return string title movie title (name)
  125. * @see IMDB page / (TitlePage)
  126. */
  127. public function title() {
  128. if ($this->main_title == "")
  129. $this->title_year();
  130. return $this->main_title;
  131. }
  132. /** Get year
  133. * @method year
  134. * @return string year
  135. * @see IMDB page / (TitlePage)
  136. */
  137. public function year() {
  138. if ($this->main_year == -1)
  139. $this->title_year();
  140. return $this->main_year;
  141. }
  142. /** Get range of years for e.g. series spanning multiple years
  143. * @method yearspan
  144. * @return array yearspan [start,end] (if there was no range, start==end)
  145. * @see IMDB page / (TitlePage)
  146. */
  147. function yearspan() {
  148. if (empty($this->main_yearspan)) {
  149. if ($this->page["Title"] == "")
  150. $this->openpage("Title");
  151. if (preg_match('!<title>.*?\(.*?(\d{4})(\&ndash;|-)(\d{4}|\?{4}).*?</title>!i', $this->page['Title'], $match)) {
  152. $this->main_yearspan = array('start' => $match[1], 'end' => $match[3]);
  153. } else {
  154. $this->main_yearspan = array('start' => $this->year(), 'end' => $this->year());
  155. }
  156. }
  157. return $this->main_yearspan;
  158. }
  159. /** Get movie types (if any specified)
  160. * @method movieTypes
  161. * @return array [0..n] of strings (or empty array if no movie types specified)
  162. * @see IMDB page / (TitlePage)
  163. */
  164. public function movieTypes() {
  165. if (empty($this->main_movietypes)) {
  166. if ($this->page["Title"] == "")
  167. $this->openpage("Title");
  168. if (@preg_match("/\<title\>(.*)\<\/title\>/", $this->page["Title"], $match)) {
  169. if (preg_match_all('|\(([^\)]*)\)|', $match[1], $matches)) {
  170. for ($i = 0; $i < count($matches[0]); ++$i)
  171. if (!preg_match('|^\d{4}$|', $matches[1][$i]))
  172. $this->main_movietypes[] = $matches[1][$i];
  173. }
  174. }
  175. }
  176. return $this->main_movietypes;
  177. }
  178. #---------------------------------------------------------------[ Runtime ]---
  179. /** Get general runtime
  180. * @method private runtime_all
  181. * @return string runtime complete runtime string, e.g. "150 min / USA:153 min (director's cut)"
  182. */
  183. private function runtime_all() {
  184. if ($this->main_runtime == "") {
  185. if ($this->page["Title"] == "")
  186. $this->openpage("Title");
  187. if (@preg_match('!Runtime:</h4>\s*(.*)\s*</div!ms', $this->page["Title"], $match))
  188. $this->main_runtime = $match[1];
  189. }
  190. return $this->main_runtime;
  191. }
  192. /** Get overall runtime (first one mentioned on title page)
  193. * @method runtime
  194. * @return mixed string runtime in minutes (if set), NULL otherwise
  195. * @see IMDB page / (TitlePage)
  196. */
  197. public function runtime() {
  198. if (empty($this->movieruntimes))
  199. $runarr = $this->runtimes();
  200. else
  201. $runarr = $this->movieruntimes;
  202. if (isset($runarr[0]["time"]))
  203. return $runarr[0]["time"];
  204. return NULL;
  205. }
  206. /** Retrieve language specific runtimes
  207. * @method runtimes
  208. * @return array runtimes (array[0..n] of array[time,country,comment])
  209. * @see IMDB page / (TitlePage)
  210. */
  211. public function runtimes() {
  212. if (empty($this->movieruntimes)) {
  213. if (empty($this->main_runtime))
  214. $rt = $this->runtime_all();
  215. if (preg_match_all("/[\/ ]*((\D*?):|)([\d]+?) min( \((.*?)\)|)/", $this->main_runtime, $matches)) {
  216. for ($i = 0; $i < count($matches[0]); ++$i)
  217. $this->movieruntimes[] = array("time" => $matches[3][$i], "country" => $matches[2][$i], "comment" => $matches[5][$i]);
  218. } elseif (preg_match('!<div class="infobar">.*?(\d+)\s*min!ims', $this->page['Title'], $match)) {
  219. $this->movieruntimes[] = array('time' => $match[1], 'country' => '', 'comment' => '');
  220. }
  221. }
  222. return $this->movieruntimes;
  223. }
  224. #----------------------------------------------------------[ Aspect Ratio ]---
  225. /** Aspect Ratio of movie screen
  226. * @method aspect_ratio
  227. * @return string ratio
  228. * @see IMDB page / (TitlePage)
  229. */
  230. public function aspect_ratio() {
  231. if (empty($this->aspectratio)) {
  232. if ($this->page["Title"] == "")
  233. $this->openpage("Title");
  234. preg_match('!<h4 class="inline">Aspect Ratio:</h4>\s*(.*?)\s</div>!ims', $this->page["Title"], $match);
  235. $this->aspectratio = $match[1];
  236. }
  237. return $this->aspectratio;
  238. }
  239. #----------------------------------------------------------[ Movie Rating ]---
  240. /** Setup votes
  241. * @method private rate_vote
  242. */
  243. private function rate_vote() {
  244. if ($this->page["Title"] == "")
  245. $this->openpage("Title");
  246. if (preg_match('!<span itemprop="ratingValue">(\d{1,2}\.\d)!i', $this->page["Title"], $match)) {
  247. $this->main_rating = $match[1];
  248. } else {
  249. $this->main_rating = 0;
  250. }
  251. if (preg_match('!href="ratings"\s+title="([\d\,]+)!i', $this->page["Title"], $match)) {
  252. $this->main_votes = $match[1];
  253. } else {
  254. $this->main_votes = 0;
  255. }
  256. }
  257. /** Get movie rating
  258. * @method rating
  259. * @return string rating current rating as given by IMDB site
  260. * @see IMDB page / (TitlePage)
  261. */
  262. public function rating() {
  263. if ($this->main_rating == -1)
  264. $this->rate_vote();
  265. return $this->main_rating;
  266. }
  267. /** Return votes for this movie
  268. * @method votes
  269. * @return string votes count of votes for this movie
  270. * @see IMDB page / (TitlePage)
  271. */
  272. public function votes() {
  273. if ($this->main_votes == -1)
  274. $this->rate_vote();
  275. return $this->main_votes;
  276. }
  277. #------------------------------------------------------[ Movie Comment(s) ]---
  278. /** Get movie main comment (from title page)
  279. * @method comment
  280. * @return string comment full text of movie comment from the movies main page
  281. * @see IMDB page / (TitlePage)
  282. */
  283. public function comment() {
  284. // this stuff whent into a frame in 2011! _ajax/iframe?component=footer
  285. if ($this->main_comment == "") {
  286. if ($this->page["TitleFoot"] == "")
  287. $this->openpage("TitleFoot");
  288. if (@preg_match('!<div class\="user-comments">\s*(.*?)\s*<div class\="yn"!ms', $this->page["TitleFoot"], $match))
  289. $this->main_comment = preg_replace("/a href\=\"\//i", "a href=\"http://" . $this->imdbsite . "/", $match[1]);
  290. $this->main_comment = str_replace("http://i.media-imdb.com/images/showtimes", $this->imdb_img_url . "/showtimes", $this->main_comment);
  291. }
  292. return $this->main_comment;
  293. }
  294. /** Get movie main comment (from title page - split-up variant)
  295. * @method comment_split
  296. * @return array comment array[string title, string date, array author, string comment]; author: array[string url, string name]
  297. * @see IMDB page / (TitlePage)
  298. */
  299. public function comment_split() {
  300. if (empty($this->split_comment)) {
  301. if ($this->main_comment == "")
  302. $comm = $this->comment();
  303. if (@preg_match('!<strong>(.*?)</strong>.*<div class="comment-meta">\s*(.*?)\s*\|\s*by\s*(.*?)\s*&ndash;.*?<p>(.*?)</div!ims', $this->main_comment, $match)) {
  304. @preg_match('!href="(.*?)">(.*)</a!i', $match[3], $author);
  305. $this->split_comment = array("title" => $match[1], "date" => $match[2], "author" => array("url" => $author[1], "name" => $author[2]), "comment" => trim($match[4]));
  306. } elseif (@preg_match('!<div class="comment-meta">\s*(.{10,20})\s*\|\s*by\s*(.*?)\s*&ndash;.*?<div>\s*(.*?)\s*</div>!ims', $this->main_comment, $match)) {
  307. @preg_match('!href="(.*?)">(.*)</a!i', $match[2], $author);
  308. $this->split_comment = array('title' => '', 'date' => $match[1], 'author' => array("url" => $author[1], "name" => $author[2]), "comment" => trim($match[3]));
  309. }
  310. }
  311. return $this->split_comment;
  312. }
  313. #--------------------------------------------------------------[ Keywords ]---
  314. /** Get the keywords for the movie
  315. * @method keywords
  316. * @return array keywords
  317. * @see IMDB page / (TitlePage)
  318. */
  319. public function keywords() {
  320. if (empty($this->main_keywords)) {
  321. if ($this->page["Title"] == "")
  322. $this->openpage("Title");
  323. if (preg_match_all('!<a href\="/keyword/[\w\-]+">(.*?)</a>!', $this->page["Title"], $matches))
  324. $this->main_keywords = $matches[1];
  325. }
  326. return $this->main_keywords;
  327. }
  328. #--------------------------------------------------------[ Language Stuff ]---
  329. /** Get movies original language
  330. * @method language
  331. * @return string language
  332. * @brief There is not really a main language on the IMDB sites (yet), so this
  333. * simply returns the first one
  334. * @see IMDB page / (TitlePage)
  335. */
  336. public function language() {
  337. if ($this->main_language == "") {
  338. if (empty($this->langs))
  339. $this->langs = $this->languages();
  340. if (isset($this->langs[0]))
  341. $this->main_language = $this->langs[0];
  342. }
  343. return $this->main_language;
  344. }
  345. /** Get all languages this movie is available in
  346. * @method languages
  347. * @return array languages (array[0..n] of strings)
  348. * @see IMDB page / (TitlePage)
  349. */
  350. public function languages() {
  351. if (empty($this->langs)) {
  352. if ($this->page["Title"] == "")
  353. $this->openpage("Title");
  354. if (preg_match_all('!<a href="/language/(.*?)">\s*(.*?)\s*</a>(\s+\((.*?)\)|)!m', $this->page["Title"], $matches))
  355. $this->langs = $matches[2];
  356. $mc = count($matches[2]);
  357. for ($i = 0; $i < $mc; $i++) {
  358. $this->langs_full[] = array('name' => $matches[2][$i], 'code' => $matches[1][$i], 'comment' => $matches[4][$i]);
  359. }
  360. }
  361. return $this->langs;
  362. }
  363. /** Get all languages this movie is available in, including details
  364. * @method languages_detailed
  365. * @return array languages (array[0..n] of array[string name, string code, string comment], code being the ISO-Code)
  366. * @see IMDB page / (TitlePage)
  367. */
  368. public function languages_detailed() {
  369. if (empty($this->langs_full))
  370. $foo = $this->languages();
  371. return $this->langs_full;
  372. }
  373. #--------------------------------------------------------------[ Genre(s) ]---
  374. /** Get the movies main genre
  375. * Since IMDB.COM does not really now a "Main Genre", this simply means the
  376. * first mentioned genre will be returned.
  377. * @method genre
  378. * @return string genre first of the genres listed on the movies main page
  379. * @brief There is not really a main genre on the IMDB sites (yet), so this
  380. * simply returns the first one
  381. * @see IMDB page / (TitlePage)
  382. */
  383. public function genre() {
  384. if (empty($this->main_genre)) {
  385. if (empty($this->moviegenres))
  386. $genres = $this->genres();
  387. if (!empty($genres))
  388. $this->main_genre = $this->moviegenres[0];
  389. }
  390. return $this->main_genre;
  391. }
  392. /** Get all genres the movie is registered for
  393. * @method genres
  394. * @return array genres (array[0..n] of strings)
  395. * @see IMDB page / (TitlePage)
  396. */
  397. public function genres() {
  398. if (empty($this->moviegenres)) {
  399. if ($this->page["Title"] == "")
  400. $this->openpage("Title");
  401. if (preg_match_all("@<a href\=\"/genre/[\w\-]+\"\>(.*?)\</a>@", $this->page["Title"], $matches)) {
  402. $this->moviegenres = $matches[1];
  403. } elseif (preg_match('!<div class="infobar">(.*?)</div>!ims', $this->page['Title'], $match)) {
  404. if (preg_match_all('!href="/genre/.*?"\s*>(.*?)<!ims', $match[1], $matches)) {
  405. $this->moviegenres = $matches[1];
  406. }
  407. }
  408. }
  409. return $this->moviegenres;
  410. }
  411. #----------------------------------------------------------[ Color format ]---
  412. /** Get colors
  413. * @method colors
  414. * @return array colors (array[0..1] of strings)
  415. * @see IMDB page / (TitlePage)
  416. */
  417. public function colors() {
  418. if (empty($this->moviecolors)) {
  419. if ($this->page["Title"] == "")
  420. $this->openpage("Title");
  421. if (preg_match_all("|/search/title\?colors=.*?>\s*(.*?)<|", $this->page["Title"], $matches))
  422. $this->moviecolors = $matches[1];
  423. }
  424. return $this->moviecolors;
  425. }
  426. #---------------------------------------------------------------[ Creator ]---
  427. /** Get the creator of a movie (most likely for seasons only)
  428. * @method creator
  429. * @return array creator (array[0..n] of array[name,imdb])
  430. * @see IMDB page / (TitlePage)
  431. */
  432. public function creator() {
  433. if (empty($this->main_creator)) {
  434. if ($this->page["Title"] == "")
  435. $this->openpage("Title");
  436. if (@preg_match("/Creator:\<\/h5\>\s*\n(.*?)(<\/div|<a class=\"tn15more)/ms", $this->page["Title"], $match)) {
  437. if (preg_match_all('|/name/nm(\d{7}).*?>(.*?)<|ims', $match[1], $matches)) {
  438. for ($i = 0; $i < count($matches[0]); ++$i)
  439. $this->main_creator[] = array('name' => $matches[2][$i], 'imdb' => $matches[1][$i]);
  440. }
  441. }
  442. }
  443. return $this->main_creator;
  444. }
  445. #---------------------------------------------------------------[ Tagline ]---
  446. /** Get the main tagline for the movie
  447. * @method tagline
  448. * @return string tagline
  449. * @see IMDB page / (TitlePage)
  450. */
  451. public function tagline() {
  452. if ($this->main_tagline == "") {
  453. if ($this->page["Title"] == "")
  454. $this->openpage("Title");
  455. if (@preg_match('!Taglines:</h4>\s*(.*?)\s*<!ims', $this->page["Title"], $match)) {
  456. $this->main_tagline = trim($match[1]);
  457. }
  458. }
  459. return $this->main_tagline;
  460. }
  461. #---------------------------------------------------------------[ Seasons ]---
  462. /** Get the number of seasons or 0 if not a series
  463. * @method seasons
  464. * @return int seasons number of seasons
  465. * @see IMDB page / (TitlePage)
  466. */
  467. public function seasons() {
  468. if ($this->seasoncount == -1) {
  469. if ($this->page["Title"] == "")
  470. $this->openpage("Title");
  471. if (preg_match_all('|<a href="episodes#season-\d+">(\d+)</a>|Ui', $this->page["Title"], $matches)) {
  472. $this->seasoncount = $matches[1][0];
  473. } else {
  474. $this->seasoncount = 0;
  475. }
  476. if (preg_match_all('|<a href="episodes#season-unknown">unknown</a>|Ui', $this->page["Title"], $matches)) {
  477. $this->seasoncount += count($matches[0]);
  478. }
  479. }
  480. return $this->seasoncount;
  481. }
  482. #-----------------------------------------------[ Is it part of a serial? ]---
  483. /** Try to figure out if this is a movie or part of a serie
  484. * @method is_serial
  485. * @return boolean
  486. * @see IMDB page / (TitlePage)
  487. */
  488. public function is_serial() {
  489. if ($this->page["Title"] == "")
  490. $this->openpage("Title");
  491. return preg_match('|<h5>TV Series:</h5>|i', $this->page["Title"], $matches);
  492. }
  493. #--------------------------------------------------------[ Plot (Outline) ]---
  494. /** Get the main Plot outline for the movie
  495. * @method plotoutline
  496. * @param optional boolean fallback Fallback to storyline if we could not catch plotoutline? Default: FALSE
  497. * @return string plotoutline
  498. * @see IMDB page / (TitlePage)
  499. */
  500. public function plotoutline($fallback = FALSE) {
  501. if ($this->main_plotoutline == "") {
  502. if ($this->page["Title"] == "")
  503. $this->openpage("Title");
  504. if (preg_match('!<span class="rating-rating">.*?(<p>.*?)\s*<div!ims', $this->page['Title'], $match)) {
  505. $this->main_plotoutline = trim($match[1]);
  506. } elseif (preg_match('!<p itemprop="description">\s*(.*?)\s*</p>!ims', $this->page['Title'], $match)) {
  507. $this->main_plotoutline = trim($match[1]);
  508. } elseif ($fallback) {
  509. $this->main_plotoutline = $this->storyline();
  510. }
  511. if (preg_match('!<p>\s*(<p>.*</p>)\s*$!ims', $this->main_plotoutline, $tmp))
  512. $this->main_plotoutline = $tmp[1];
  513. }
  514. return $this->main_plotoutline;
  515. }
  516. /** Get the Storyline for the movie
  517. * @method storyline
  518. * @return string storyline
  519. * @see IMDB page / (TitlePage)
  520. */
  521. public function storyline() {
  522. if ($this->main_storyline == "") {
  523. if ($this->page["Title"] == "")
  524. $this->openpage("Title");
  525. if (@preg_match('!Storyline</h2>\s*\n*<?p?>?(.*?)<?/?p?<h4!ims', $this->page["Title"], $match)) {
  526. if (preg_match('!(.*?)<em class="nobr">Written by!ims', $match[1], $det))
  527. $this->main_storyline = $det[1];
  528. elseif (preg_match('!(.*)\s</p>!ims', $match[1], $det))
  529. $this->main_storyline = $det[1];
  530. elseif (preg_match('!(.*)\s<span class="see-more inline">!ims', $match[1], $det))
  531. $this->main_storyline = $det[1];
  532. elseif (preg_match('!(.*)\s\|!ims', $match[1], $det))
  533. $this->main_storyline = $det[1];
  534. else
  535. $this->main_storyine = trim($match[1]);
  536. }
  537. }
  538. return $this->main_storyline;
  539. }
  540. #--------------------------------------------------------[ Photo specific ]---
  541. /** Setup cover photo (thumbnail and big variant)
  542. * @method private thumbphoto
  543. * @return boolean success (TRUE if found, FALSE otherwise)
  544. * @see IMDB page / (TitlePage)
  545. */
  546. private function thumbphoto() {
  547. if ($this->page["Title"] == "")
  548. $this->openpage("Title");
  549. preg_match("!id\=\"img_primary\">[^<]*<a[^<]+<img src\=\"(.+?)\"!i", $this->page["Title"], $match);
  550. if (empty($match[1]))
  551. return FALSE;
  552. $this->main_thumb = $match[1];
  553. preg_match('|(.*\._V1).*|iUs', $match[1], $mo);
  554. $this->main_photo = $mo[1];
  555. return true;
  556. }
  557. /** Get cover photo
  558. * @method photo
  559. * @param optional boolean thumb get the thumbnail (100x140, default) or the
  560. * bigger variant (400x600 - FALSE)
  561. * @return mixed photo (string url if found, FALSE otherwise)
  562. * @see IMDB page / (TitlePage)
  563. */
  564. public function photo($thumb = true) {
  565. if (empty($this->main_photo))
  566. $this->thumbphoto();
  567. if (!$thumb && empty($this->main_photo))
  568. return false;
  569. if ($thumb && empty($this->main_thumb))
  570. return false;
  571. if ($thumb)
  572. return $this->main_thumb;
  573. return $this->main_photo;
  574. }
  575. /** Save the photo to disk
  576. * @method savephoto
  577. * @param string path where to store the file
  578. * @param optional boolean thumb get the thumbnail (100x140, default) or the
  579. * bigger variant (400x600 - FALSE)
  580. * @return boolean success
  581. * @see IMDB page / (TitlePage)
  582. */
  583. public function savephoto($path, $thumb = true, $rerun = 0) {
  584. switch ($rerun) {
  585. case 2: $req = new MDB_Request('');
  586. break;
  587. case 1: $req = new MDB_Request('', '', !$this->trigger_referer);
  588. break;
  589. default: $req = new MDB_Request('', '', $this->trigger_referer);
  590. break;
  591. }
  592. $photo_url = $this->photo($thumb);
  593. if (!$photo_url)
  594. return FALSE;
  595. $req->setURL($photo_url);
  596. $req->sendRequest();
  597. if (strpos($req->getResponseHeader("Content-Type"), 'image/jpeg') === 0
  598. || strpos($req->getResponseHeader("Content-Type"), 'image/gif') === 0
  599. || strpos($req->getResponseHeader("Content-Type"), 'image/bmp') === 0) {
  600. $fp = $req->getResponseBody();
  601. } else {
  602. switch ($rerun) {
  603. case 2 :
  604. $ctype = $req->getResponseHeader("Content-Type");
  605. $this->debug_scalar("<BR>*photoerror* at " . __FILE__ . " line " . __LINE__ . ": " . $photo_url . ": Content Type is '$ctype'<BR>");
  606. if (substr($ctype, 0, 4) == 'text')
  607. $this->debug_scalar("Details: <PRE>" . $req->getResponseBody() . "</PRE>\n");
  608. return FALSE;
  609. break;
  610. case 1 :
  611. $this->debug_scalar("<BR>Initiate third run for savephoto($path) on IMDBID " . $this->imdbID . "<BR>");
  612. unset($req);
  613. return $this->savephoto($path, $thumb, 2);
  614. break;
  615. default:
  616. $this->debug_scalar("<BR>Initiate second run for savephoto($path) on IMDBID " . $this->imdbID . "<BR>");
  617. unset($req);
  618. return $this->savephoto($path, $thumb, 1);
  619. break;
  620. }
  621. }
  622. $fp2 = fopen($path, "w");
  623. if ((!$fp) || (!$fp2)) {
  624. $this->debug_scalar("image error at " . __FILE__ . " line " . __LINE__ . "...<BR>");
  625. return false;
  626. }
  627. fputs($fp2, $fp);
  628. return TRUE;
  629. }
  630. /** Get the URL for the movies cover photo
  631. * @method photo_localurl
  632. * @param optional boolean thumb get the thumbnail (100x140, default) or the
  633. * bigger variant (400x600 - FALSE)
  634. * @return mixed url (string URL or FALSE if none)
  635. * @see IMDB page / (TitlePage)
  636. */
  637. public function photo_localurl($thumb = true) {
  638. if ($thumb)
  639. $ext = ""; else
  640. $ext = "_big";
  641. if (!is_dir($this->photodir)) {
  642. $this->debug_scalar("<BR>***ERROR*** The configured image directory does not exist!<BR>");
  643. return false;
  644. }
  645. $path = PATH_ROOT . "/images/imdb/" . $this->imdbid() . "${ext}.jpg";
  646. if (file_exists($path))
  647. return $this->photoroot . $this->imdbid() . "${ext}.jpg";
  648. if (!is_writable($this->photodir)) {
  649. $this->debug_scalar("<BR>***ERROR*** The configured image directory lacks write permission!<BR>");
  650. return false;
  651. }
  652. if ($this->savephoto($path, $thumb))
  653. return $this->photoroot . $this->imdbid() . "${ext}.jpg";
  654. else
  655. echo "Could not save file";
  656. return false;
  657. }
  658. /** Get URLs for the pictures on the main page
  659. * @method mainPictures
  660. * @return array [0..n] of [imgsrc, imglink, bigsrc], where<UL>
  661. * <LI>imgsrc is the URL of the thumbnail IMG as displayed on main page</LI>
  662. * <LI>imglink is the link to the <b><i>page</i></b> with the "big image"</LI>
  663. * <LI>bigsrc is the URL of the "big size" image itself</LI>
  664. * @author moonface
  665. * @author izzy
  666. */
  667. public function mainPictures() {
  668. if ($this->page["Title"] == "")
  669. $this->openpage("Title");
  670. if (empty($this->main_pictures)) {
  671. preg_match('!<div class="mediastrip">\s*(.*?)\s*</div>!ims', $this->page["Title"], $match);
  672. if (@preg_match_all('!<a .*?href="(.*?)".*?<img.*?src="(.*?)"!ims', $match[1], $matches)) {
  673. for ($i = 0; $i < count($matches[0]); ++$i) {
  674. $this->main_pictures[$i]["imgsrc"] = $matches[2][$i];
  675. if (substr($matches[1][$i], 0, 4) != "http")
  676. $matches[1][$i] = "http://" . $this->imdbsite . $matches[1][$i];
  677. $this->main_pictures[$i]["imglink"] = $matches[1][$i];
  678. preg_match('|(.*\._V1).*|iUs', $matches[2][$i], $big);
  679. $ext = substr($matches[2][$i], -3);
  680. $this->main_pictures[$i]["bigsrc"] = $big[1] . ".${ext}";
  681. }
  682. }
  683. }
  684. return $this->main_pictures;
  685. }
  686. #-------------------------------------------------[ Country of Production ]---
  687. /** Get country of production
  688. * @method country
  689. * @return array country (array[0..n] of string)
  690. * @see IMDB page / (TitlePage)
  691. */
  692. public function country() {
  693. if (empty($this->countries)) {
  694. if ($this->page["Title"] == "")
  695. $this->openpage("Title");
  696. $this->countries = array();
  697. # if (preg_match_all("/\/country\/\w+\"\>(.*?)<\/a/m",$this->page["Title"],$matches))
  698. if (preg_match_all('!/country/\w+"\s*>(.*?)<\/a!m', $this->page["Title"], $matches))
  699. for ($i = 0; $i < count($matches[0]); ++$i)
  700. $this->countries[$i] = $matches[1][$i];
  701. }
  702. return $this->countries;
  703. }
  704. #------------------------------------------------------------[ Movie AKAs ]---
  705. /** Get movies alternative names
  706. * @method alsoknow
  707. * @return array aka array[0..n] of array[title,year,country,comment]; searching
  708. * on akas.imdb.com will add "lang" (2-char language code) to the array
  709. * for localized names, "country" may hold multiple countries separated
  710. * by commas
  711. * @see IMDB page ReleaseInfo
  712. * @version Due to changes on the IMDB sites, neither the languages nor the year
  713. * seems to be available anymore - so those array properties will always
  714. * be empty, and kept for compatibility only (for a while, at least).
  715. * Moreover, content has been moved from the title page to ReleaseInfo page.
  716. */
  717. public function alsoknow() {
  718. if (empty($this->akas)) {
  719. if ($this->page["ReleaseInfo"] == "")
  720. $this->openpage("ReleaseInfo");
  721. $ak_s = strpos($this->page["ReleaseInfo"], "<a name=\"akas\">");
  722. //if ($ak_s == 0) $ak_s = strpos ($this->page["ReleaseInfo"], "Alternativ:");
  723. if ($ak_s == 0)
  724. return array();
  725. $alsoknow_end = strpos($this->page["ReleaseInfo"], "</table>", $ak_s);
  726. $alsoknow_all = substr($this->page["ReleaseInfo"], $ak_s, $alsoknow_end - $ak_s);
  727. preg_match_all("@<td>(.*?)</td>@i", $alsoknow_all, $matches);
  728. for ($i = 0; $i < count($matches[1]); $i+=2) {
  729. $title = trim($matches[1][$i]);
  730. $countries = explode('/', $matches[1][$i + 1]);
  731. foreach ($countries as $country) {
  732. $firstbracket = strpos($country, '(');
  733. if ($firstbracket === false) {
  734. $_country = trim($country);
  735. $comment = '';
  736. } else {
  737. $_country = trim(substr($country, 0, $firstbracket));
  738. preg_match_all("@\((.+?)\)@", $country, $matches3);
  739. $comment = implode(', ', $matches3[1]);
  740. }
  741. $this->akas[] = array(
  742. "title" => $title,
  743. "year" => '',
  744. "country" => $_country,
  745. "comment" => $comment,
  746. "lang" => ''
  747. );
  748. }
  749. }
  750. }
  751. return $this->akas;
  752. }
  753. #---------------------------------------------------------[ Sound formats ]---
  754. /** Get sound formats
  755. * @method sound
  756. * @return array sound (array[0..n] of strings)
  757. * @see IMDB page / (TitlePage)
  758. */
  759. public function sound() {
  760. if (empty($this->sound)) {
  761. if ($this->page["Title"] == "")
  762. $this->openpage("Title");
  763. if (preg_match_all("|/search/title\?sound_mixes=.*?>\s*(.*?)<|", $this->page["Title"], $matches))
  764. $this->sound = $matches[1];
  765. }
  766. return $this->sound;
  767. }
  768. #-------------------------------------------------------[ MPAA / PG / FSK ]---
  769. /** Get the MPAA data (also known as PG or FSK)
  770. * @method mpaa
  771. * @return array mpaa (array[country]=rating)
  772. * @see IMDB page / (TitlePage)
  773. */
  774. public function mpaa() {
  775. if (empty($this->mpaas)) {
  776. if ($this->page["ParentalGuide"] == "")
  777. $this->openpage("ParentalGuide");
  778. if (preg_match_all("|/search/title\?certificates=.*?>\s*(.*?):(.*?)<|", $this->page["ParentalGuide"], $matches)) {
  779. $cc = count($matches[0]);
  780. for ($i = 0; $i < $cc; ++$i)
  781. $this->mpaas[$matches[1][$i]] = $matches[2][$i];
  782. }
  783. }
  784. return $this->mpaas;
  785. }
  786. /** Get the MPAA data (also known as PG or FSK) - including historical data
  787. * @method mpaa_hist
  788. * @return array mpaa (array[country][0..n]=rating)
  789. * @see IMDB page / (TitlePage)
  790. */
  791. public function mpaa_hist() {
  792. if (empty($this->mpaas_hist)) {
  793. if ($this->page["ParentalGuide"] == "")
  794. $this->openpage("ParentalGuide");
  795. if (preg_match_all("|/search/title\?certificates=.*?>\s*(.*?):(.*?)<|", $this->page["ParentalGuide"], $matches)) {
  796. $cc = count($matches[0]);
  797. for ($i = 0; $i < $cc; ++$i)
  798. $this->mpaas_hist[$matches[1][$i]][] = $matches[2][$i];
  799. }
  800. }
  801. return $this->mpaas_hist;
  802. }
  803. #----------------------------------------------------[ MPAA justification ]---
  804. /** Find out the reason for the MPAA rating
  805. * @method mpaa_reason
  806. * @return string reason why the movie was rated such
  807. * @see IMDB page / (TitlePage)
  808. */
  809. public function mpaa_reason() {
  810. if (empty($this->mpaa_justification)) {
  811. if ($this->page["Title"] == "")
  812. $this->openpage("Title");
  813. if (preg_match('!href="/mpaa">.*?</h4>\s*<span itemprop="contentRating">(.*?)</span!ims', $this->page["Title"], $match))
  814. $this->mpaa_justification = trim($match[1]);
  815. }
  816. return $this->mpaa_justification;
  817. }
  818. #------------------------------------------------------[ Production Notes ]---
  819. /** For not-yet completed movies, we can get the production state
  820. * @method prodNotes
  821. * @return array production notes [status,statnote,lastupdate[day,month,mon,year],more,note]
  822. * @see IMDB page / (TitlePage)
  823. */
  824. public function prodNotes() {
  825. if (empty($this->main_prodnotes)) {
  826. if ($this->page["Title"] == "")
  827. $this->openpage("Title");
  828. if (!preg_match('!(<h2>Production Notes.*?)\s*</div!ims', $this->page["Title"], $match))
  829. return $this->main_prodnotes; // no info available
  830. if (preg_match('!<b>Status:\s*</b>\s*(.*?)\s*<br!ims', $match[1], $tmp))
  831. if (preg_match('!(.*?)\s*<span class="ghost">\|</span>\s*(.*)!ims', $tmp[1], $tmp2)) {
  832. $status = trim($tmp2[1]);
  833. $statnote = trim($tmp2[2]);
  834. } else {
  835. $status = trim($tmp);
  836. $statnote = '';
  837. }
  838. if (preg_match('!<b>Updated:\s*</b>\s*(\d+)\s*(\D+)\s+(\d{4})!ims', $match[1], $tmp))
  839. $update = array("day" => $tmp[1], "month" => $tmp[2], "mon" => $this->monthNo($tmp[2]), "year" => $tmp[3]);
  840. if (preg_match('!<b>More Info:\s*</b>\s*(.*)!ims', $match[1], $tmp))
  841. $more = preg_replace('!\s*onclick=".*?"!ims', '', trim($tmp[1]));
  842. $more = preg_replace('!href="/!ims', 'href="http://' . $this->imdbsite . '/', $more);
  843. if (preg_match('!<b>Note:\s*</b>\s*(.*?)</!ims', $match[1], $tmp))
  844. $note = trim($tmp[1]);
  845. $this->main_prodnotes = array("status" => $status, "statnote" => $statnote, "lastUpdate" => $update, "more" => $more, "note" => $note);
  846. }
  847. return $this->main_prodnotes;
  848. }
  849. #----------------------------------------------[ Position in the "Top250" ]---
  850. /** Find the position of a movie in the top 250 ranked movies
  851. * @method top250
  852. * @return int position a number between 1..250 if the movie is listed, 0 otherwise
  853. * @author abe
  854. * @see http://projects.izzysoft.de/trac/imdbphp/ticket/117
  855. */
  856. public function top250() {
  857. if ($this->main_top250 == -1) {
  858. if ($this->page["Title"] == "")
  859. $this->openpage("Title");
  860. if (@preg_match('!<a href="[^"]*/chart/top\?tt(.*?)"><strong>Top 250 #(.*?)</a>!i', $this->page["Title"], $match)) {
  861. $this->main_top250 = $match[2];
  862. } else {
  863. $this->main_top250 = 0;
  864. }
  865. }
  866. return $this->main_top250;
  867. }
  868. #=====================================================[ /plotsummary page ]===
  869. #--------------------------------------------------[ Full Plot (combined) ]---
  870. /** Get the movies plot(s)
  871. * @method plot
  872. * @return array plot (array[0..n] of strings)
  873. * @see IMDB page /plotsummary
  874. */
  875. public function plot() {
  876. if (empty($this->plot_plot)) {
  877. if ($this->page["Plot"] == "")
  878. $this->openpage("Plot");
  879. if ($this->page["Plot"] == "cannot open page")
  880. return array(); // no such page
  881. if (preg_match_all("/p class=\"plotpar\">(.*?)<\/p>/", str_replace("\n", " ", $this->page["Plot"]), $matches))
  882. for ($i = 0; $i < count($matches[0]); ++$i)
  883. $this->plot_plot[$i] = preg_replace('/<a href=\"\/SearchPlotWriters/i', '<a href="http://' . $this->imdbsite . '/SearchPlotWriters/', $matches[1][$i]);
  884. }
  885. return $this->plot_plot;
  886. }
  887. #-----------------------------------------------------[ Full Plot (split) ]---
  888. /** Get the movie plot(s) - split-up variant
  889. * @method plot_split
  890. * @return array array[0..n] of array[string plot,array author] - where author consists of string name and string url
  891. * @see IMDB page /plotsummary
  892. */
  893. public function plot_split() {
  894. if (empty($this->split_plot)) {
  895. if (empty($this->plot_plot))
  896. $plots = $this->plot();
  897. for ($i = 0; $i < count($this->plot_plot); ++$i) {
  898. if (preg_match("/(.*?)<i>.*<a href=\"(.*?)\">(.*?)<\/a>/", $this->plot_plot[$i], $match))
  899. $this->split_plot[] = array("plot" => $match[1], "author" => array("name" => $match[3], "url" => $match[2]));
  900. }
  901. }
  902. return $this->split_plot;
  903. }
  904. #========================================================[ /synopsis page ]===
  905. #---------------------------------------------------------[ Full Synopsis ]---
  906. /** Get the movies synopsis
  907. * @method synopsis
  908. * @return string synopsis
  909. * @see IMDB page /synopsis
  910. */
  911. public function synopsis() {
  912. if (empty($this->synopsis_wiki)) {
  913. if ($this->page["Synopsis"] == "")
  914. $this->openpage("Synopsis");
  915. if ($this->page["Synopsis"] == "cannot open page")
  916. return $this->synopsis_wiki; // no such page
  917. if (preg_match('|<div id="swiki\.2\.1">(.*?)</div>|ims', $this->page["Synopsis"], $match))
  918. $this->synopsis_wiki = trim($match[1]);
  919. }
  920. return $this->synopsis_wiki;
  921. }
  922. #========================================================[ /taglines page ]===
  923. #--------------------------------------------------------[ Taglines Array ]---
  924. /** Get all available taglines for the movie
  925. * @method taglines
  926. * @return array taglines (array[0..n] of strings)
  927. * @see IMDB page /taglines
  928. */
  929. public function taglines() {
  930. if (empty($this->taglines)) {
  931. if ($this->page["Taglines"] == "")
  932. $this->openpage("Taglines");
  933. if ($this->page["Taglines"] == "cannot open page")
  934. return array(); // no such page
  935. if (preg_match_all("/<p>(.*?)<\/p><hr/", $this->page["Taglines"], $matches))
  936. $this->taglines = $matches[1];
  937. }
  938. return $this->taglines;
  939. }
  940. #=====================================================[ /fullcredits page ]===
  941. #-----------------------------------------------------[ Helper: TableRows ]---
  942. /** Get rows for a given table on the page
  943. * @method private get_table_rows
  944. * @param string html
  945. * @param string table_start
  946. * @return mixed rows (FALSE if table not found, array[0..n] of strings otherwise)
  947. * @see used by the methods director, cast, writing, producer, composer
  948. */
  949. private function get_table_rows($html, $table_start) {
  950. $row_s = strpos($html, ">" . $table_start . "<");
  951. $row_e = $row_s;
  952. if ($row_s == 0)
  953. return FALSE;
  954. $endtable = strpos($html, "</table>", $row_s);
  955. if (preg_match_all("/<tr>(.*?)<\/tr>/", substr($html, $row_s, $endtable - $row_s), $matches)) {
  956. $mc = count($matches[1]);
  957. for ($i = 0; $i < $mc; ++$i)
  958. if (strncmp(trim($matches[1][$i]), "<td valign=", 10) == 0)
  959. $rows[] = $matches[1][$i];
  960. }
  961. return $rows;
  962. }
  963. #------------------------------------------------[ Helper: Cast TableRows ]---
  964. /** Get rows for the cast table on the page
  965. * @method private get_table_rows_cast
  966. * @param string html
  967. * @param string table_start
  968. * @return mixed rows (FALSE if table not found, array[0..n] of strings otherwise)
  969. * @see used by the method cast
  970. */
  971. private function get_table_rows_cast($html, $table_start, $class = "nm") {
  972. $row_s = strpos($html, '<table class="cast">');
  973. $row_e = $row_s;
  974. if ($row_s == 0)
  975. return FALSE;
  976. $endtable = strpos($html, "</table>", $row_s);
  977. if (preg_match_all("/<tr.*?(<td class=\"$class\".*?)<\/tr>/", substr($html, $row_s, $endtable - $row_s), $matches))
  978. return $matches[1];
  979. return array();
  980. }
  981. #------------------------------------------------[ Helper: Awards TableRows ]---
  982. /** Get rows for the awards table on the page
  983. * @method private get_table_rows_awards
  984. * @param string html
  985. * @param string table_start
  986. * @return mixed rows (FALSE if table not found, array[0..n] of strings otherwise)
  987. * @see used by the method awards
  988. * @author Qvist
  989. */
  990. private function get_table_rows_awards($html) {
  991. $row_s = strpos($html, '<table style="margin-top:');
  992. $row_e = $row_s;
  993. if ($row_s == 0)
  994. return FALSE;
  995. $endtable = strpos($html, "</table>", $row_s);
  996. $table_string = substr($html, $row_s, $endtable - $row_s);
  997. if (preg_match_all("/<tr>(.*?)<\/tr>/ims", $table_string, $matches)) {
  998. return $matches[1];
  999. }
  1000. return $rows;
  1001. }
  1002. #------------------------------------------------------[ Helper: RowCells ]---
  1003. /** Get content of table row cells
  1004. * @method private get_row_cels
  1005. * @param string row (as returned by imdb::get_table_rows)
  1006. * @return array cells (array[0..n] of strings)
  1007. * @see used by the methods director, cast, writing, producer, composer
  1008. */
  1009. private function get_row_cels($row) {
  1010. if (preg_match_all("/<td.*?>(.*?)<\/td>/ims", $row, $matches))
  1011. return $matches[1];
  1012. return array();
  1013. }
  1014. #-------------------------------------------[ Helper: Get IMDBID from URL ]---
  1015. /** Get the IMDB ID from a names URL
  1016. * @method private get_imdbname
  1017. * @param string href url to the staff members IMDB page
  1018. * @return string IMDBID of the staff member
  1019. * @see used by the methods director, cast, writing, producer, composer
  1020. */
  1021. private function get_imdbname($href) {
  1022. if (strlen($href) == 0)
  1023. return $href;
  1024. $name_s = 17;
  1025. $name_e = strpos($href, '"', $name_s);
  1026. if ($name_e != 0)
  1027. return substr($href, $name_s, $name_e - 1 - $name_s);
  1028. else
  1029. return $href;
  1030. }
  1031. #-------------------------------------------------------------[ Directors ]---
  1032. /** Get the director(s) of the movie
  1033. * @method director
  1034. * @return array director (array[0..n] of arrays[imdb,name,role])
  1035. * @see IMDB page /fullcredits
  1036. */
  1037. public function director() {
  1038. if (empty($this->credits_director)) {
  1039. if ($this->page["Credits"] == "")
  1040. $this->openpage("Credits");
  1041. if ($this->page["Credits"] == "cannot open page")
  1042. return array(); // no such page
  1043. }
  1044. $director_rows = $this->get_table_rows($this->page["Credits"], "Directed by");
  1045. if ($director_rows == null)
  1046. $director_rows = $this->get_table_rows($this->page["Credits"], "Series Directed by");
  1047. for ($i = 0; $i < count($director_rows); $i++) {
  1048. $cels = $this->get_row_cels($director_rows[$i]);
  1049. if (!isset($cels[0]))
  1050. return array();
  1051. $dir = array();
  1052. $dir["imdb"] = $this->get_imdbname($cels[0]);
  1053. $dir["name"] = strip_tags($cels[0]);
  1054. $role = trim(strip_tags($cels[2]));
  1055. if ($role == "")
  1056. $dir["role"] = NULL;
  1057. else
  1058. $dir["role"] = $role;
  1059. $this->credits_director[$i] = $dir;
  1060. }
  1061. return $this->credits_director;
  1062. }
  1063. #----------------------------------------------------------------[ Actors ]---
  1064. /** Get the actors
  1065. * @method cast
  1066. * @return array cast (array[0..n] of arrays[imdb,name,role,thumb,photo])
  1067. * @see IMDB page /fullcredits
  1068. */
  1069. public function cast() {
  1070. if (empty($this->credits_cast)) {
  1071. if ($this->page["Credits"] == "")
  1072. $this->openpage("Credits");
  1073. if ($this->page["Credits"] == "cannot open page")
  1074. return array(); // no such page
  1075. }
  1076. $cast_rows = $this->get_table_rows_cast($this->page["Credits"], "Cast", "hs");
  1077. for ($i = 0; $i < count($cast_rows); $i++) {
  1078. $cels = $this->get_row_cels($cast_rows[$i]);
  1079. if (!isset($cels[0]))
  1080. return array();
  1081. $dir = array();
  1082. $dir["imdb"] = $this->get_imdbname($cels[1]);
  1083. $dir["name"] = strip_tags($cels[1]);
  1084. $role = strip_tags($cels[3]);
  1085. if ($role == "")
  1086. $dir["role"] = NULL;
  1087. else
  1088. $dir["role"] = $role;
  1089. $dir["thumb"] = preg_replace('|.*<img src="(.*?)".*|is', '$1', $cels[0]);
  1090. if (strpos($dir["thumb"], '._V1'))
  1091. $dir["photo"] = preg_replace('|(.*._V1)\..+\.(.*)|is', '$1.$2', $dir["thumb"]);
  1092. $this->credits_cast[$i] = $dir;
  1093. }
  1094. return $this->credits_cast;
  1095. }
  1096. #---------------------------------------------------------------[ Writers ]---
  1097. /** Get the writer(s)
  1098. * @method writing
  1099. * @return array writers (array[0..n] of arrays[imdb,name,role])
  1100. * @see IMDB page /fullcredits
  1101. */
  1102. public function writing() {
  1103. if (empty($this->credits_writing)) {
  1104. if ($this->page["Credits"] == "")
  1105. $this->openpage("Credits");
  1106. if ($this->page["Credits"] == "cannot open page")
  1107. return array(); // no such page
  1108. }
  1109. $this->credits_writing = array();
  1110. $writing_rows = $this->get_table_rows($this->page["Credits"], "Writing credits");
  1111. for ($i = 0; $i < count($writing_rows); $i++) {
  1112. $cels = $this->get_row_cels($writing_rows[$i]);
  1113. if (count($cels) > 2) {
  1114. $wrt = array();
  1115. $wrt["imdb"] = $this->get_imdbname($cels[0]);
  1116. $wrt["name"] = strip_tags($cels[0]);
  1117. $role = strip_tags($cels[2]);
  1118. if ($role == "")
  1119. $wrt["role"] = NULL;
  1120. else

Large files files are truncated, but you can click here to view the full file