@@ -693,7 +693,7 @@ public function languages_detailed()
693693 * @return string genre first of the genres listed on the movies main page
694694 * @brief There is not really a main genre on the IMDB sites (yet), so this
695695 * simply returns the first one
696- * @see IMDB page / (TitlePage)
696+ * @see IMDB page /reference
697697 */
698698 public function genre ()
699699 {
@@ -710,34 +710,29 @@ public function genre()
710710
711711 /** Get all genres the movie is registered for
712712 * @return array genres (array[0..n] of strings)
713- * @see IMDB page / (TitlePage)
713+ * @see IMDB page /reference
714714 */
715715 public function genres ()
716716 {
717717 if (empty ($ this ->moviegenres )) {
718- $ xpath = $ this ->getXpathPage ("Title " );
719- $ extract_genres = $ xpath ->query ("//li[@data-testid='storyline-genres']//li[@class='ipc-inline-list__item']/a " );
720- $ genres = array ();
721- foreach ($ extract_genres as $ genre ) {
722- if (!empty ($ genre ->nodeValue )) {
723- $ genres [] = trim ($ genre ->nodeValue );
724- }
725- }
726- if (count ($ genres ) > 0 ) {
727- $ this ->moviegenres = $ genres ;
728- }
729- }
730- if (empty ($ this ->moviegenres )) {
731- $ genres = isset ($ this ->jsonLD ()->genre ) ? $ this ->jsonLD ()->genre : array ();
732- if (!is_array ($ genres )) {
733- $ genres = (array )$ genres ;
734- }
735- $ this ->moviegenres = $ genres ;
718+ $ query = <<<EOF
719+ query Genres( \$id: ID!) {
720+ title(id: \$id) {
721+ titleGenres {
722+ genres {
723+ genre {
724+ text
736725 }
737- if (empty ($ this ->moviegenres )) {
738- if (@preg_match ('!Genres:</h4>(.*?)</div!ims ' , $ this ->page ["Title " ], $ match )) {
739- if (@preg_match_all ('!href="[^>]+?>\s*(.*?)\s*<! ' , $ match [1 ], $ matches )) {
740- $ this ->moviegenres = $ matches [1 ];
726+ }
727+ }
728+ }
729+ }
730+ EOF ;
731+
732+ $ data = $ this ->graphql ->query ($ query , "Genres " , ["id " => "tt $ this ->imdbID " ]);
733+ if (isset ($ data ->title ->titleGenres ->genres )) {
734+ foreach ($ data ->title ->titleGenres ->genres as $ genres ) {
735+ $ this ->moviegenres [] = $ genres ->genre ->text ;
741736 }
742737 }
743738 }
0 commit comments