Skip to content

Commit

Permalink
Fix scrapping of locations data (#195)
Browse files Browse the repository at this point in the history
* Add method to get all location place

* Fix scrapping of locations data

* Fix return type of getLocations method
  • Loading branch information
defro authored Jan 17, 2024
1 parent 57f630d commit 438aa15
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions imdb.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class IMDB
const IMDB_ID = '~((?:tt\d{6,})|(?:itle\?\d{6,}))~';
const IMDB_LANGUAGE = '~<a href="\/language\/(\w+)">(.*)<\/a>~Ui';
const IMDB_LOCATION = '~href="\/search\/title\?locations=(.*)">(.*)<\/a>~Ui';
const IMDB_LOCATIONS = '~href="\/search\/title\?locations=[^>]*>\s?(.*)\s?<\/a>[^"]*<dd>\s?(.*)\s<\/dd>~Ui';
const IMDB_LOCATIONS = '~href="(?<url>\/search\/title\/\?locations=[^>]*)">\s?(?<location>.*)\s?<\/a><p(.*)>\((?<specification>.*)\)<\/p>~Ui';
const IMDB_MPAA = '~<li class="ipl-inline-list__item">(?:\s+)(TV-Y|TV-Y7|TV-G|TV-PG|TV-14|TV-MA|G|PG|PG-13|R|NC-17|NR|UR)(?:\s+)<\/li>~Ui';
const IMDB_MUSIC = '~Music by\s*<\/h4>.*<table class=.*>(.*)</table>~Us';
const IMDB_NAME = '~href="/name/(.+)/?(?:\?[^"]*)?"[^>]*>(.+)</a>~Ui';
Expand Down Expand Up @@ -1441,8 +1441,7 @@ public function getLocationAsUrl($sTarget = '')
/**
* Returns all locations
*
* @return string location
* @return string specification
* @return string|array locations
*/
public function getLocations()
{
Expand All @@ -1464,7 +1463,7 @@ public function getLocations()

return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound, $aReturn);
} else {
$fullLocations = sprintf('https://www.imdb.com/title/tt%s/locations', $this->iId);
$fullLocations = sprintf('https://www.imdb.com/title/tt%s/locations/', $this->iId);
$aCurlInfo = IMDBHelper::runCurl($fullLocations);
$sSource = $aCurlInfo['contents'] ?? false;

Expand All @@ -1480,15 +1479,12 @@ public function getLocations()

if ($aReturned) {
$aReturn = [];
foreach ($aReturned[1] as $i => $strName) {
foreach ($aReturned['url'] as $i => $strName) {
if (strpos($strName, '(') === false) {
$aReturn[] = [
'location' => IMDBHelper::cleanString($strName),
];
}
if (strpos($aReturned[2][$i], '(') !== false) {
$aReturn[] = [
'specification' => IMDBHelper::cleanString($aReturned[2][$i]),
'url' => IMDBHelper::cleanString($aReturned['url'][$i]),
'location' => IMDBHelper::cleanString($aReturned['location'][$i]),
'specification' => IMDBHelper::cleanString($aReturned['specification'][$i]),
];
}
}
Expand Down

0 comments on commit 438aa15

Please sign in to comment.