From: Banana Date: Sun, 20 Jul 2025 10:45:52 +0000 (+0200) Subject: Updated PHP-IMDB-Grabber X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fdevelop;p=bibliotheca-php.git Updated PHP-IMDB-Grabber Signed-off-by: Banana --- diff --git a/CHANGELOG b/CHANGELOG index 8f05c98..e4b5608 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,6 +4,8 @@ * Fixed: Usage of default sorting in dashboard and collection view. * Updated to uikit-3.23.11 * Upgrade information files are markdown files. + * Updated PHP-IMDB-Grabber to https://github.com/FabianBeiner/PHP-IMDB-Grabber/tree/v6.2.6 + with some heavy modifications. 1.7 - The Ceremonial Chambers 2024-06-01 * Added i18n. Please read the upgrade file for more information. English and german are available diff --git a/sources/imdb.class.php.txt b/sources/imdb.class.php.txt index 86a8a55..f19db26 100644 --- a/sources/imdb.class.php.txt +++ b/sources/imdb.class.php.txt @@ -13,7 +13,7 @@ * @author Fabian Beiner * @license https://opensource.org/licenses/MIT The MIT License * @link https://github.com/FabianBeiner/PHP-IMDB-Grabber/ GitHub Repository - * @version 6.2.0 + * @version 6.2.6 */ class IMDB { @@ -53,60 +53,60 @@ class IMDB * These are the regular expressions used to extract the data. * If you don’t know what you’re doing, you shouldn’t touch them. */ - const IMDB_AKA = '~]*>\s*Also\s*Known\s*As\s*\s*(.+)~Uis'; - const IMDB_ASPECT_RATIO = '~]*>Aspect\s*Ratio\s*(.+)~Uis'; - const IMDB_AWARDS = '~\s*Awards:(.+)~Uis'; - const IMDB_BUDGET = '~]*>Budget<\/td>\s*\s*(.*)(?:\(estimated\))\s*<\/td>~Ui'; - const IMDB_CAST = '~]*itemprop="actor"[^>]*>\s*]*>\s*(.+)~Ui'; - const IMDB_RATING = '~class="ipl-rating-star__rating">(.*)<~Ui'; - const IMDB_RATING_COUNT = '~class="ipl-rating-star__total-votes">\((.*)\)<~Ui'; - const IMDB_RELEASE_DATE = '~href="/title/[t0-9]*/releaseinfo">(.*)<~Ui'; - const IMDB_RUNTIME = '~]*>\s*Runtime\s*\s*(.+)~Ui'; - const IMDB_SEARCH_ADV = '~text-primary">1[.]\s*(?:.*?)<\/a>~Ui'; + const IMDB_PLOT = '~data-testid="plot-l".*>(.*)<\/span>~Ui'; + const IMDB_PLOT_KEYWORDS = '~explore=keywords.*(.*)<\/span>~Ui'; + const IMDB_POSTER = '~~Ui'; + const IMDB_RATING = '~"ratingsSummary":{"aggregateRating":(.*),.*}~Ui'; + const IMDB_RATING_COUNT = '~"ratingsSummary":{.*"voteCount":(\d+),.*}~Ui'; + const IMDB_RELEASE_DATE = '~\/title\/tt\d+\/releaseinfo\/\?ref_=ttrv_ov_rdat">(.*)~Ui'; + const IMDB_RUNTIME = '~id="runtime".*]+>(.*)~Ui'; + const IMDB_SEARCH_ADV = '~(?:.*?)alt="(.*?)"(?:.*?)href="\/title\/(tt\d{6,})\/(?:.*?)">(.*?)<\/a>~'; - const IMDB_SEASONS = '~episodes\?season=(?:\d+)">(\d+)<~Ui'; - const IMDB_SOUND_MIX = '~]*>\s*Sound\s*Mix\s*\s*(.+)~Ui'; - const IMDB_TAGLINE = '~]*>\s*Taglines\s*\s*(.+)~Ui'; - const IMDB_TITLE = '~itemprop="name">(.*)(<\/h3>|(.*)~Ui'; + const IMDB_VOTES = '~"ratingsSummary":{.*"voteCount":(\d+),.*}~Ui'; + const IMDB_WRITER = '~>\s*(?:Writer|Writers).*]*>(.+)~Uxsi'; + const IMDB_YEAR = '~.*\s*\((?:[^()]+ )?(\d{4}(?:–\d{4})?)\)\s*-\sReference\s*view \s*-\s*IMDb~iU'; /** * @var string The string returned, if nothing is found. @@ -334,7 +334,7 @@ class IMDB } $aCurlInfo = IMDBHelper::runCurl($this->sUrl); - $sSource = $aCurlInfo['contents']; + $sSource = isset($aCurlInfo['contents']) ? $aCurlInfo['contents'] : false; if (false === $sSource) { if (true === self::IMDB_DEBUG) { @@ -549,7 +549,7 @@ class IMDB return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound, $aReturn); } else { - $fullAkas = sprintf('https://www.imdb.com/title/tt%s/releaseinfo', $this->iId); + $fullAkas = sprintf('https://www.imdb.com/title/tt%s/releaseinfo/', $this->iId); $aCurlInfo = IMDBHelper::runCurl($fullAkas); $sSource = $aCurlInfo['contents'] ?? false; @@ -561,7 +561,7 @@ class IMDB return false; } - $aReturned = IMDBHelper::matchRegex($sSource, "~(.*?)<\/td>\s+(.*?)<\/td>~"); + $aReturned = IMDBHelper::matchRegex($sSource, '~.*?(?:\s*)?~s'); if ($aReturned) { $aReturn = []; @@ -610,7 +610,7 @@ class IMDB return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound, $aReturn); } else { - $fullCritics = sprintf('https://www.imdb.com/title/tt%s/criticreviews', $this->iId); + $fullCritics = sprintf('https://www.imdb.com/title/tt%s/criticreviews/', $this->iId); $aCurlInfo = IMDBHelper::runCurl($fullCritics); $sSource = $aCurlInfo['contents'] ?? false; @@ -619,19 +619,19 @@ class IMDB echo '
cURL error: ' . var_dump($aCurlInfo) . '
'; } - return false; + return IMDB::$sNotFound; } $aReturned = IMDBHelper::matchRegex( $sSource, - '~metascore_wrap(?:.*)\s+(?:.*)\s+(?:.*)ratingValue\">([0-9]+)<\/span>(?:\s+(?:.*)){4}ratingCount\">([0-9]+)~' + '~
(\d+)
.*?(\d+) reviews~s' ); if ($aReturned) { $aReturn = []; $aReturn[] = [ - 'metascore' => IMDBHelper::cleanString($aReturned[1][0]), - 'reviews' => IMDBHelper::cleanString($aReturned[2][0]), + 'metascore' => isset($aReturned[1][0]) ? IMDBHelper::cleanString($aReturned[1][0]) : '', + 'reviews' => isset($aReturned[2][0]) ? IMDBHelper::cleanString($aReturned[2][0]) : '', ]; file_put_contents($sCacheFile, serialize($aReturn)); @@ -674,7 +674,7 @@ class IMDB return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound, $aReturn); } else { - $fullCritics = sprintf('https://www.imdb.com/title/tt%s/criticreviews', $this->iId); + $fullCritics = sprintf('https://www.imdb.com/title/tt%s/criticreviews/', $this->iId); $aCurlInfo = IMDBHelper::runCurl($fullCritics); $sSource = $aCurlInfo['contents'] ?? false; @@ -683,12 +683,12 @@ class IMDB echo '
cURL error: ' . var_dump($aCurlInfo) . '
'; } - return false; + return IMDB::$sNotFound; } $aReturned = IMDBHelper::matchRegex( $sSource, - '~"ratingValue\">([0-9]+)<\/span>\s+<\/div>\s+<\/td>\s+(?:.*)\s+(?:(.*)<\/span>(?:.*)\"name\">(.*)<\/span><\/span>(?:<\/a>)?\s+(?:.*)\"reviewbody\"> (.*)<\/div>~' + '~
(\d+)
.*?(.*?)(?:)?(.*?).*?
(.*?)
~' ); if ($aReturned) { @@ -915,7 +915,8 @@ class IMDB if (0 !== $iLimit && $i >= $iLimit) { break; } - $sChar = str_replace(' / ', ' and ', $aMatchChar[1][$i]); + $sCharRaw = $aMatchChar[1][$i] ?? 'Unknown'; + $sChar = str_replace(' / ', ' and ', $sCharRaw); $aReturn[] = '' . IMDBHelper::cleanString( @@ -956,7 +957,9 @@ class IMDB if (0 !== $iLimit && $i >= $iLimit) { break; } - $sChar = str_replace(' / ', ' and ', $aMatchChar[1][$i]); + $sCharRaw = $aMatchChar[1][$i] ?? 'Unknown'; + $sChar = str_replace(' / ', ' and ', $sCharRaw); + $aReturn[] = IMDBHelper::cleanString($sName) . ' as ' . IMDBHelper::cleanString($sChar); } @@ -1441,8 +1444,7 @@ class IMDB /** * Returns all locations * - * @return string location - * @return string specification + * @return string|array locations */ public function getLocations() { @@ -1464,7 +1466,7 @@ class IMDB 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; @@ -1473,22 +1475,19 @@ class IMDB echo '
cURL error: ' . var_dump($aCurlInfo) . '
'; } - return false; + return IMDB::$sNotFound; } $aReturned = IMDBHelper::matchRegex($sSource, self::IMDB_LOCATIONS); 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]), ]; } } @@ -1565,7 +1564,7 @@ class IMDB * @param bool $bMore Add … if there are more cast members than printed. * @param string $sSize small or big images * - * @return array Array with title and url. + * @return string Array with title and url. */ public function getPhotos($iLimit = 0, $bMore = true, $sSize = 'small') { @@ -1610,14 +1609,14 @@ class IMDB while ($isPage) { $fullPhotos = sprintf('https://www.imdb.com/title/tt%s/mediaindex?page=%d', $this->iId, $page); $aCurlInfo = IMDBHelper::runCurl($fullPhotos); - $sSource = $aCurlInfo['contents']; + $sSource = isset($aCurlInfo['contents']) ? $aCurlInfo['contents'] : false; if (false === $sSource) { if (true === self::IMDB_DEBUG) { echo '
cURL error: ' . var_dump($aCurlInfo) . '
'; } - return false; + return IMDB::$sNotFound; } $aReturned = IMDBHelper::matchRegex($sSource, '~title="(.*?)"\s+>~'); @@ -1829,7 +1828,7 @@ class IMDB return IMDBHelper::arrayOutput($this->bArrayOutput, $this->sSeparator, self::$sNotFound, $aReturn); } else { - $fullAkas = sprintf('https://www.imdb.com/title/tt%s/releaseinfo', $this->iId); + $fullAkas = sprintf('https://www.imdb.com/title/tt%s/releaseinfo/', $this->iId); $aCurlInfo = IMDBHelper::runCurl($fullAkas); $sSource = $aCurlInfo['contents'] ?? false; @@ -1838,12 +1837,12 @@ class IMDB echo '
cURL error: ' . var_dump($aCurlInfo) . '
'; } - return false; + return IMDB::$sNotFound; } $aReturned = IMDBHelper::matchRegex( $sSource, - '~>(.*)\s+<\/a><\/td>\s+(.*)<\/td>~' + '~
~Ui'; + const IMDB_RUNTIME = '~id="runtime".*]+>(.*)~Ui'; + const IMDB_SEARCH_ADV = '~(?:.*?)alt="(.*?)"(?:.*?)href="\/title\/(tt\d{6,})\/(?:.*?)">(.*?)<\/a>~'; - const IMDB_SEASONS = '~episodes\?season=(?:\d+)">(\d+)<~Ui'; - const IMDB_SOUND_MIX = '~]*>\s*Sound\s*Mix\s*\s*(.+)~Ui'; - const IMDB_TAGLINE = '~]*>\s*Taglines\s*\s*(.+)~Ui'; - const IMDB_TITLE = '~itemprop="name">(.*)(<\/h3>|(.*)~Ui'; + const IMDB_VOTES = '~"ratingsSummary":{.*"voteCount":(\d+),.*}~Ui'; + const IMDB_WRITER = '~>\s*(?:Writer|Writers).*]*>(.+)~Uxsi'; + const IMDB_YEAR = '~.*\s*\((?:[^()]+ )?(\d{4}(?:–\d{4})?)\)\s*-\sReference\s*view \s*-\s*IMDb~iU'; /** * @var string The string returned, if nothing is found. @@ -328,7 +328,7 @@ class IMDB } $aCurlInfo = $this->runCurl($this->sUrl); - $sSource = is_bool($aCurlInfo) ? $aCurlInfo : $aCurlInfo['contents'] ; + $sSource = isset($aCurlInfo['contents']) ? $aCurlInfo['contents'] : false; if (false === $sSource) { if ($this->IMDB_DEBUG) { @@ -440,7 +440,7 @@ class IMDB return $this->arrayOutput($this->bArrayOutput, $this->sSeparator, $this->sNotFound, $aReturn); } else { - $fullAkas = sprintf('https://www.imdb.com/title/tt%s/releaseinfo', $this->iId); + $fullAkas = sprintf('https://www.imdb.com/title/tt%s/releaseinfo/', $this->iId); $aCurlInfo = $this->runCurl($fullAkas); $sSource = $aCurlInfo['contents']; @@ -1121,16 +1121,13 @@ class IMDB if ($aReturned) { $aReturn = []; - foreach ($aReturned[1] as $i => $strName) { + foreach ($aReturned['url'] as $i => $strName) { if (strpos($strName, '(') === false) { - $aReturn[] = [ - 'location' => $this->cleanString($strName), - ]; - } - if (strpos($aReturned[2][$i], '(') !== false) { - $aReturn[] = [ - 'specification' => $this->cleanString($aReturned[2][$i]), - ]; + $aReturn[] = [ + 'url' => IMDBHelper::cleanString($aReturned['url'][$i]), + 'location' => IMDBHelper::cleanString($aReturned['location'][$i]), + 'specification' => IMDBHelper::cleanString($aReturned['specification'][$i]), + ]; } } @@ -1323,7 +1320,7 @@ class IMDB return $this->arrayOutput($this->bArrayOutput, $this->sSeparator, $this->sNotFound, $aReturn); } else { - $fullAkas = sprintf('https://www.imdb.com/title/tt%s/releaseinfo', $this->iId); + $fullAkas = sprintf('https://www.imdb.com/title/tt%s/releaseinfo/', $this->iId); $aCurlInfo = $this->runCurl($fullAkas); $sSource = $aCurlInfo['contents']; @@ -1332,12 +1329,12 @@ class IMDB echo '
cURL error: ' . var_dump($aCurlInfo) . '
'; } - return false; + return $this->sNotFound; } $aReturned = $this->matchRegex( $sSource, - '~>(.*)<\/a><\/td>\s+(.*)<\/td>~' + '~