Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/andig/videodb
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Oct 30, 2013
2 parents a91cc74 + d22aa5f commit 46e82dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
14 changes: 9 additions & 5 deletions engines/imdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function imdbData($imdbID)
$data['subtitle'] = trim($s);
}
# orig. title
preg_match('/<span class="title-extra".+?>\s*(.*?)\s*<i>\(original title\)<\/i>\s*</si', $resp['data'], $ary);
preg_match('/<span class="title-extra".+?>\s*"?(.*?)"?\s*<i>\(original title\)<\/i>\s*</si', $resp['data'], $ary);
$data['origtitle'] = trim($ary[1]);

// Cover URL
Expand Down Expand Up @@ -269,15 +269,19 @@ function imdbData($imdbID)
if (!$resp['success']) $CLIENTERROR .= $resp['error']."\n";

// Cast
if (preg_match('#<table class="cast">(.*)#si', $resp['data'], $match))
if (preg_match('#<table class="cast_list">(.*)#si', $resp['data'], $match))
{
if (preg_match_all('#<td class="nm"><a href="/name/(.*?)/?".*?>(.*?)</a>.*?<td class="char">(.*?)</td>#si', $match[1], $ary, PREG_PATTERN_ORDER))
// no idea why it does not always work with (.*?)</table
// could be some maximum length of .*?
// anyways, I'm cutting it here
$casthtml = substr($match[1],0,strpos( $match[1],'</table'));
if (preg_match_all('#<td .*? itemprop="actor".*?>\s+<a href="/name/(nm\d+)/?.*?".*?>(.*?)</a>.*?<td class="character">(.*?)</td>#si', $casthtml, $ary, PREG_PATTERN_ORDER))
{
for ($i=0; $i < sizeof($ary[0]); $i++)
{
$actorid = trim(strip_tags($ary[1][$i]));
$actor = trim(strip_tags($ary[2][$i]));
$character = trim(strip_tags($ary[3][$i]));
$character = trim( preg_replace('/\s+/', ' ', strip_tags( preg_replace('/&nbsp;/', ' ', $ary[3][$i]))));
$cast .= "$actor::$character::$imdbIdPrefix$actorid\n";
}
}
Expand Down Expand Up @@ -410,7 +414,7 @@ function imdbActor($name, $actorid)
// now we should have loaded the best match

// only search in img_primary <td> - or we get far to many useless images
preg_match('/<td\s+id="img_primary".*?>(.*?)<\/td>/si',$resp['data'], $match);
preg_match('/<td.*?id="img_primary".*?>(.*?)<\/td>/si',$resp['data'], $match);

if (preg_match('/.*?<a.*?href="(.+?)"\s*?>\s*<img\s+.*?src="(.*?)"/si', $match[1], $m))
{
Expand Down
7 changes: 6 additions & 1 deletion test/test_imdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ function testMovie5() {
$this->assertTrue($data['runtime'] >= 99 && $data['runtime'] <= 101);
}

/*
Disabled test.
Runtime of this movie was removed on IMDB
function testMovie6() {
// She's Out of My League
// http://www.imdb.com/title/tt0815236/
Expand All @@ -127,6 +131,7 @@ function testMovie6() {
$this->assertEqual($data['runtime'], 104);
}
*/

function testMovie7() {
// Romasanta
Expand Down Expand Up @@ -235,7 +240,7 @@ function testSeriesEpisode()
$this->assertTrue( in_array('Jonathan Frakes::Commander William T. Riker::imdb:nm0000408', $cast) );
$this->assertTrue( in_array('Marina Sirtis::Counselor Deanna Troi::imdb:nm0000642', $cast) );
$this->assertTrue( in_array('John de Lancie::Q (as John deLancie)::imdb:nm0209496', $cast) );
$this->assertTrue( in_array('Rob Bowman::Borg (voice)::imdb:nm0101385', $cast) );
$this->assertTrue( in_array('Rob Bowman::Borg (voice) (uncredited)::imdb:nm0101385', $cast) );
$this->assertTrue( sizeof($cast) > 15 );
$this->assertTrue( sizeof($cast) < 30 );

Expand Down

0 comments on commit 46e82dc

Please sign in to comment.