Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into use-graphql-to-fe…
Browse files Browse the repository at this point in the history
…tch-keywords-all
  • Loading branch information
jetrosuni committed Feb 25, 2024
2 parents 2867e2e + c622579 commit afcb64d
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 82 deletions.
15 changes: 13 additions & 2 deletions doc/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@
History for IMDBPHP
====================

v8.2.0 (25.02.2024)
-------------------
+ Add Podcast Episode support #326 by @Fossil01
! Fix Title::trivia() - limited to 5 entries
! Fix Title::filmingDates()
! Fix Title::keywords_all() - limited to 50 entries
! Fix Title::locations() - limited to 5 entries
! Fix Title::quotes() and Title::quotes_split()
! Fix Title::goofs() - limited to 5 entries
! Fix Title::crazy_credits()
! Fix Title::metacriticRating()
! Fix Title::creator()

v8.1.0 (14.03.2023)
-------------------

+ Add Psr/Log v2 to allowed versions in composer.json
! Fix Title::aspect_ratio no longer returning anything

Expand All @@ -22,7 +34,6 @@ v8.0.1 (14.02.2023)

v8.0.0 (13.02.2023)
-------------------

! Title::plot() returns plain text utf-8 strings rather than html. It no longer contains the author at the end (You can get the author from Title::plot_split())
! Title::plot_split() also has plain text utf-8 strings rather than html in its plot field
! Title::releaseInfo() return has changed. The country strings have changed slightly, the dates are numbers rather than stringy numbers and month has been removed.
Expand Down
2 changes: 1 addition & 1 deletion src/Imdb/MdbBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
class MdbBase extends Config
{
public $version = '8.1.0';
public $version = '8.2.0';

protected $months = array(
"January" => "01",
Expand Down
116 changes: 61 additions & 55 deletions src/Imdb/Title.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Title extends MdbBase
"CrazyCredits" => "/crazycredits",
"Credits" => "/fullcredits",
"Episodes" => "/episodes",
"Goofs" => "/trivia?tab=gf",
"Goofs" => "/goofs",
"Keywords" => "/keywords",
"Locations" => "/locations",
"OfficialSites" => "/officialsites",
Expand Down Expand Up @@ -489,7 +489,7 @@ public function votes()
public function metacriticRating()
{
$xpath = $this->getXpathPage("Title");
$extract = $xpath->query("//span[@class='score-meta']");
$extract = $xpath->query("//span[contains(@class, 'metacritic-score-box')]");
if ($extract && $extract->item(0) != null) {
return intval(trim($extract->item(0)->nodeValue));
}
Expand Down Expand Up @@ -778,7 +778,7 @@ public function creator()
if ($creator->{'@type'} === 'Person') {
$result[] = array(
'name' => $creator->name,
'imdb' => rtrim(str_replace('/name/nm', '', $creator->url), '/')
'imdb' => preg_replace('@.*name\/nm(\d+).*@i', '$1', $creator->url)
);
}
}
Expand Down Expand Up @@ -2003,12 +2003,14 @@ public function crazy_credits()
{
if (empty($this->crazy_credits)) {
if (preg_match_all(
'!<div class="sodatext">\s*(.*?)\s*</div>!ims',
'!<p class="crazy-credit-text">\s*(.*?)\s*</p>!ims',
$this->getPage("CrazyCredits"),
$matches
)) {
foreach ($matches[1] as $credit) {
$this->crazy_credits[] = trim(strip_tags($credit));
$this->crazy_credits[] = str_replace(array("\r", "\n"), ' ', trim(
strip_tags(htmlspecialchars_decode($credit, ENT_QUOTES))
));
}
}
}
Expand Down Expand Up @@ -2121,42 +2123,43 @@ public function episodes()
* @return array goofs (array[0..n] of array[type,content]
* @see IMDB page /goofs
* @version Spoilers are currently skipped (differently formatted)
* @version Each goof category is limited to 5 entries
*/
public function goofs()
{
if (empty($this->goofs)) {
$page = $this->getPage("Goofs");
if (empty($page)) {
$xpath = $this->getXpathPage("Goofs");
if (empty($xpath)) {
return array();
} // no such page
if (@preg_match_all(
'@<h4 class="li_group">(.+?)(!?&nbsp;)</h4>\s*(.+?)\s*(?=<h4 class="li_group">|<div id="top_rhs_wrapper")@ims',
$this->page["Goofs"],
$matches
)) {
$gc = count($matches[1]);
for ($i = 0; $i < $gc; ++$i) {
if ($matches[1][$i] == 'Spoilers') {
continue;
} // no spoilers, moreover they are differently formatted
preg_match_all(
'!<div id="gf.+?>(\s*<div class="sodatext">)?(.+?)\s*</div>\s*<div!ims',
$matches[3][$i],
$goofy
);
$ic = count($goofy[0]);
for ($k = 0; $k < $ic; ++$k) {
$this->goofs[] = array(
"type" => $matches[1][$i],
"content" => str_replace(
'href="/',
'href="https://' . $this->imdbsite . '/',
trim($goofy[2][$k])
)
);
$ids = array();

$cells = $xpath->query("//h3[@class='ipc-title__text']//span");
foreach ($cells as $cell) {
if ($cell->attributes->length) {
foreach ($cell->attributes as $attribute) {
if ($attribute->nodeName === 'id') {
$ids[$attribute->nodeValue] = trim($cell->nodeValue);
}
}
}
}

ksort($ids);

foreach ($ids as $id => $title) {
$cells = $xpath->query("//div[@data-testid='sub-section-$id']//div[@class='ipc-html-content-inner-div']");
foreach ($cells as $cell) {
$this->goofs[] = array(
"type" => $title,
"content" => str_replace(
'href="/',
'href="https://' . $this->imdbsite . '/',
trim($cell->nodeValue)
)
);
}
}
}
return $this->goofs;
}
Expand All @@ -2177,7 +2180,7 @@ public function quotes()
}

if (preg_match_all(
'!<div class="sodatext">\s*(.*?)\s*</div>!ims',
'!<div class="ipc-html-content-inner-div">\s*(.*?)\s*</div>!ims',
str_replace("\n", " ", $page),
$matches
)) {
Expand Down Expand Up @@ -2206,11 +2209,11 @@ public function quotes_split()
$i = 0;
if (!empty($this->moviequotes)) {
foreach ($this->moviequotes as $moviequotes) {
if (@preg_match_all('!<p>\s*(.*?)\s*</p>!', $moviequotes, $matches)) {
if (@preg_match_all('!<li>\s*(.*?)\s*</li>!', $moviequotes, $matches)) {
if (!empty($matches[1])) {
foreach ($matches[1] as $quote) {
if (@preg_match(
'!href="([^"]*)"\s*>.+?character">(.*?)</span.+?:(.*)!',
'!href="([^"]*)"\s*>(.*?)<\/a>:(.*)!',
$quote,
$match
)) {
Expand Down Expand Up @@ -2452,6 +2455,7 @@ public function videosites()
* @param boolean $spoil *Deprecated*. There are no longer spoiler trivia on imdb
* @return array trivia (array[0..n] string
* @see IMDB page /trivia
* @version Limited to 5 trivias
*/
public function trivia($spoil = false)
{
Expand All @@ -2462,16 +2466,19 @@ public function trivia($spoil = false)
} // no such page
if ($spoil) {
return [];
} else {
preg_match('!<div id="trivia_content"(.+?)<a id="spoilers"!ims', $this->page["Trivia"], $block);
if (empty($block)) {
preg_match('!<div id="trivia_content"(.+?)<div id="sidebar">!ims', $this->page["Trivia"], $block);
}
}
if (preg_match_all('!<div class="sodatext">\s*(.*?)\s*</div>\s*<div!ims', $block[1], $matches)) {
$gc = count($matches[1]);
for ($i = 0; $i < $gc; ++$i) {
$this->trivia[] = str_replace('href="/', 'href="https://' . $this->imdbsite . "/", $matches[1][$i]);

if (preg_match_all(
'!<div class="ipc-html-content-inner-div">\s*(.*?)\s*</div>!ims',
str_replace("\n", " ", $page),
$matches
)) {
foreach ($matches[1] as $match) {
$this->trivia[] = str_replace(
'href="/name/',
'href="https://' . $this->imdbsite . '/name/',
$match
);
}
}
}
Expand Down Expand Up @@ -2693,14 +2700,14 @@ function ($attr) {
* Filming locations
* @return string[]
* @see IMDB page /locations
* @version Limited to 5 locations
*/
public function locations()
{
if (empty($this->locations)) {
$xpath = $this->getXpathPage("Locations");
$cells = $xpath->query("//section[@id=\"filming_locations\"]//dt");
foreach ($cells as $cell) {
$this->locations[] = trim($cell->nodeValue);
$locations = $this->XmlNextJson("Locations")->xpath("//cardText");
foreach ($locations as $location) {
$this->locations[] = trim(strval($location));
}
}
return $this->locations;
Expand Down Expand Up @@ -2943,6 +2950,7 @@ public function officialSites()
/** Get the complete keywords for the movie
* @return array keywords
* @see IMDB page /keywords
* @version Limited to 50 keywords
*/
public function keywords_all()
{
Expand Down Expand Up @@ -3114,8 +3122,8 @@ public function filmingDates()
{
if (empty($this->filmingDates)) {
$page = $this->getPage("Locations");
if (@preg_match("!<h4[^>]+>Filming Dates</h4>\s*\n*(.*?)(<br/>\n*)*</section!ims", $page, $filDates)) {
if (preg_match("/(\d+ \w+ \d{4}) - (\d+ \w+ \d{4})/", strip_tags($filDates[1]), $dates)) {
if (@preg_match('!sub-section-flmg_dates"[^>]*?>(.*?)<\/section>!ims', $page, $filDates)) {
if (preg_match("/(\w+ \d+, \d{4}) - (\w+ \d+, \d{4})/", strip_tags($filDates[1]), $dates)) {
$this->filmingDates = array(
'beginning' => date('Y-m-d', strtotime($dates[1])),
'end' => date('Y-m-d', strtotime($dates[2])),
Expand Down Expand Up @@ -3199,14 +3207,12 @@ protected function arrayToXml($array, &$xml)
}

/**
* @param string $page
* @return \SimpleXMLElement
*/
protected function XmlNextJson()
protected function XmlNextJson($page = "Title")
{
if ($this->XmlNextJson) {
return $this->XmlNextJson;
}
$xpath = $this->getXpathPage("Title");
$xpath = $this->getXpathPage($page);
$script = $xpath->query("//script[@id='__NEXT_DATA__']")->item(0)->nodeValue;
$decode = json_decode($script, true);
$xml = new \SimpleXMLElement('<root/>');
Expand Down
2 changes: 1 addition & 1 deletion tests/CalendarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function getCalendar()
$config->imdbsite = 'www.imdb.com';
$config->cachedir = realpath(dirname(__FILE__) . '/cache') . '/';
$config->usezip = false;
$config->cache_expire = 3600;
$config->cache_expire = 86400;

return new Calendar($config);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ChartsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function getCharts()
$config->imdbsite = 'www.imdb.com';
$config->cachedir = realpath(dirname(__FILE__) . '/cache') . '/';
$config->usezip = false;
$config->cache_expire = 3600;
$config->cache_expire = 86400;

return new Charts($config);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/PersonSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function getimdbpersonsearch()
$config->language = 'en';
$config->cachedir = realpath(dirname(__FILE__) . '/cache') . '/';
$config->usezip = false;
$config->cache_expire = 3600;
$config->cache_expire = 86400;
$config->debug = false;

$imdbsearch = new PersonSearch($config);
Expand Down
2 changes: 1 addition & 1 deletion tests/PersonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ protected function getimdb_person($id = '0594503')
$config->imdbsite = 'www.imdb.com';
$config->cachedir = realpath(dirname(__FILE__) . '/cache') . '/';
$config->usezip = false;
$config->cache_expire = 3600;
$config->cache_expire = 86400;

return new \Imdb\Person($id, $config);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TitleSearchAdvancedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected function getTitleSearchAdvanced()
$config->imdbsite = 'www.imdb.com';
$config->cachedir = realpath(dirname(__FILE__) . '/cache') . '/';
$config->usezip = false;
$config->cache_expire = 3600;
$config->cache_expire = 86400;

return new TitleSearchAdvanced($config);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TitleSearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ protected function getimdbsearch()
$config->language = 'en';
$config->cachedir = realpath(dirname(__FILE__) . '/cache') . '/';
$config->usezip = false;
$config->cache_expire = 3600;
$config->cache_expire = 86400;
$config->debug = false;

$imdbsearch = new TitleSearch($config);
Expand Down
Loading

0 comments on commit afcb64d

Please sign in to comment.