diff --git a/src/Imdb/Title.php b/src/Imdb/Title.php index 3245708..af5fb80 100755 --- a/src/Imdb/Title.php +++ b/src/Imdb/Title.php @@ -126,7 +126,7 @@ class Title extends MdbBase "Soundtrack" => "/soundtrack", "Technical" => "/technical", "Title" => "/", - "Trailers" => "/videogallery/content_type-trailer", + "Trailers" => "/videogallery/?contentTypes=trailer", "Trivia" => "/trivia", "VideoSites" => "/externalsites", ); @@ -2253,35 +2253,66 @@ EOF; if (empty($page)) { return array(); } // no such page - - $has_trailers = strpos($page, '
    '); +//print_r($page); + #$has_trailers = strpos($page, '
      '); + $has_trailers = strpos($page, '
      ' . $html_trailer); - foreach ($doc->getElementsByTagName('li') as $trailerNode) { - $titleNode = $trailerNode->getElementsByTagName('a')->item(1); - $title = $titleNode->nodeValue; - $url = "https://" . $this->imdbsite . $titleNode->getAttribute('href'); - $imageUrl = $trailerNode->getElementsByTagName('img')->item(0)->getAttribute('loadlate'); - $res = (strpos($imageUrl, 'HDIcon') !== false) ? 'HD' : 'SD'; - - if ($full) { - $this->trailers[] = array( - 'title' => $title, - 'url' => $url, - 'resolution' => $res, - 'lang' => '', - 'restful_url' => '' - ); - } else { - $this->trailers[] = $url; - } - } + $xpath = new \DOMXPath($doc); + $elements = $xpath->query('//*[@data-testid[starts-with(., "videos-slate-overlay-")]]'); + // Controleer of het element gevonden is + //print_r($elements); + // Controleer of er elementen zijn gevonden + if ($elements->length > 0) { + $i = 0; + foreach ($elements as $element) { + $url = "https://" . $this->imdbsite . $element->getAttribute('href'); + if( ! preg_match('/german|latin|french|dutch|spanish/i', $element->getAttribute('aria-label')) && $i < 1 ) { + $i++; + $title = $element->getAttribute('aria-label'); + $title = preg_replace('/Trailer/', '', $title); + $videohtml = file_get_contents($url); + $videodom = new \DOMDocument(); + if (@$videodom->loadHTML($videohtml) === FALSE) { + die('Kan de HTML inhoud niet laden'); + } + $xvideopath = new \DOMXPath($videodom); + $videoElements = $xvideopath->query('//script[@id="__NEXT_DATA__"]'); + if ($videoElements->length > 0) { + $video = json_decode("[".$videoElements->item(0)->nodeValue."]"); + $vimage = $video[0]->props->pageProps->videoPlaybackData->video->thumbnail->url; + $v = $video[0]->props->pageProps->videoPlaybackData->video; + $vurls = $video[0]->props->pageProps->videoPlaybackData->video->playbackURLs; + //print_r($video[0]->props->pageProps); + //die(); + foreach ( $vurls as $vurl ) { + if ( preg_match('/1080/', $vurl->videoDefinition )) { + $url = $vurl->url; + } + } + } + if ($full) { + $this->trailers[] = array( + 'title' => $title, + 'url' => $url, + 'resolution' => 'HD', + 'lang' => '', + 'restful_url' => '' + ); + } else { + $this->trailers[] = $url; + } + //$title = $this->Title(). " ( ".$this->Year()." )"; + #echo 'Element gevonden met href: ' . $url . " $title\n"; + } + } + } } } return $this->trailers;