From 3db62758c59ed8a4692306713dd5dab26f307f8b Mon Sep 17 00:00:00 2001 From: Jetro Suni Date: Sat, 17 Feb 2024 16:17:45 +0200 Subject: [PATCH] Fix genre fetching --- src/Imdb/Title.php | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/src/Imdb/Title.php b/src/Imdb/Title.php index aa292b3f..7047620c 100755 --- a/src/Imdb/Title.php +++ b/src/Imdb/Title.php @@ -693,7 +693,7 @@ public function languages_detailed() * @return string genre first of the genres listed on the movies main page * @brief There is not really a main genre on the IMDB sites (yet), so this * simply returns the first one - * @see IMDB page / (TitlePage) + * @see IMDB page /reference */ public function genre() { @@ -710,35 +710,28 @@ public function genre() /** Get all genres the movie is registered for * @return array genres (array[0..n] of strings) - * @see IMDB page / (TitlePage) + * @see IMDB page /reference */ public function genres() { if (empty($this->moviegenres)) { - $xpath = $this->getXpathPage("Title"); - $extract_genres = $xpath->query("//li[@data-testid='storyline-genres']//li[@class='ipc-inline-list__item']/a"); - $genres = array(); - foreach ($extract_genres as $genre) { - if (!empty($genre->nodeValue)) { - $genres[] = trim($genre->nodeValue); - } - } - if (count($genres) > 0) { - $this->moviegenres = $genres; - } - } - if (empty($this->moviegenres)) { - $genres = isset($this->jsonLD()->genre) ? $this->jsonLD()->genre : array(); - if (!is_array($genres)) { - $genres = (array)$genres; - } - $this->moviegenres = $genres; + $query = <<moviegenres)) { - if (@preg_match('!Genres:(.*?)page["Title"], $match)) { - if (@preg_match_all('!href="[^>]+?>\s*(.*?)\s*moviegenres = $matches[1]; - } + } + } + } +} +EOF; + + $data = $this->graphql->query($query, "Genres", ["id" => "tt$this->imdbID"]); + foreach ($data->title->titleGenres->genres as $genres) { + $this->moviegenres[] = $genres->genre->text; } } return $this->moviegenres;