Movie trailer

pull/9/head
Chewbaka69 6 years ago
parent 2cc475d86e
commit 96acb05f54

@ -0,0 +1,99 @@
<?php
class Model_Trailer
{
private $_title;
private $_year;
private $_type;
private $_url;
public $trailer;
public function __construct($title, $year, $type)
{
$this->_title = $title;
$this->_year = $year;
$this->_type = $type;
if($this->_type === 'movie') {
$this->getUrl();
if($this->_url === null)
return;
$this->getMovieTrailer();
if(!$this->trailer)
$this->getMovieTeaser();
return $this->trailer;
}
}
private function getUrl()
{
$html = Request::forge('https://www.themoviedb.org/search/movie?query=' . urlencode($this->_title) . '+y%3A' . $this->_year . '&language=us', 'curl');
$html->execute();
if ($html->response()->status !== 200)
return false;
$media = $html->response()->body;
preg_match('/<a id="[a-z0-9_]*" data-id="[a-z0-9]*" data-media-type="movie" data-media-adult="[a-z]*" class="[a-z]*" href="(\/movie\/[\d]*\?language\=us)" title=".*" alt=".*">/i', $media, $urls);
if (!isset($urls[1]))
return false;
$this->_url = explode('?', $urls[1])[0];
}
private function getMovieTrailer()
{
$html = Request::forge('https://www.themoviedb.org' . $this->_url . '/videos?active_nav_item=Trailers&video_language=en-US&language=en-US', 'curl');
$html->set_options(array(
CURLOPT_FOLLOWLOCATION => true,
)
);
$html->execute();
if ($html->response()->status !== 200)
return false;
$media = $html->response()->body;
preg_match('/<iframe type="text\/html" src="(\/\/www.youtube.com\/embed\/[a-zA-Z0-9\_\-]*\?enablejsapi\=1&autoplay\=0\&origin\=https%3A%2F%2Fwww\.themoviedb\.org\&hl\=en-US\&modestbranding\=1\&fs\=1)" frameborder\="0" allowfullscreen><\/iframe>/', $media, $youtube);
if (!isset($youtube[1]))
return false;
$this->trailer = $youtube[1];
}
private function getMovieTeaser()
{
$html = Request::forge('https://www.themoviedb.org' . $this->_url . '/videos?active_nav_item=Teasers&video_language=en-US&language=en-US', 'curl');
$html->set_options(array(
CURLOPT_FOLLOWLOCATION => true,
)
);
$html->execute();
if ($html->response()->status !== 200)
return false;
$media = $html->response()->body;
preg_match('/<iframe type="text\/html" src="(\/\/www.youtube.com\/embed\/[a-zA-Z0-9\_]*\?enablejsapi\=1&autoplay\=0\&origin\=https%3A%2F%2Fwww\.themoviedb\.org\&hl\=en-US\&modestbranding\=1\&fs\=1)" frameborder\="0" allowfullscreen><\/iframe>/', $media, $youtube);
if (!isset($youtube[1]))
return false;
$youtube = preg_replace('/\&origin\=https%3A%2F%2Fwww\.themoviedb\.org/i', '', $youtube[1]);
$this->trailer = $youtube;
}
}

@ -372,15 +372,15 @@
});
/** LAUNCH TRAILER **/
$(document).on('click', '#id-362', function (event) {
$(document).find('body').append('<div style="position: absolute; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.8); z-index:1;">' +
'<object width="640" height="360" style="position: absolute; margin: auto; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index:2;">\n' +
' <param name="movie" value="<?php echo $movie->trailer; ?>&amp;version=3"/\n' +
' <param name="allowFullScreen" value="true"/>\n' +
' <param name="allowscriptaccess" value="always"/>\n' +
' <embed width="640" height="360" src="https:<?php echo $movie->trailer; ?>&amp;version=3" class="youtube-player" type="text/html" allowscriptaccess="always" allowfullscreen="true"/>\n' +
'</object>\n' +
var height = $(window).height();
var width = $(window).width();
$(document).find('body').append('<div id="youtube-iframe" style="position: absolute; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.8); z-index:1;">' +
'<iframe style="position: absolute; margin: auto; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index:2;" width="' + (width/3*2) + '" height="' + (height/3*2) + '" src="<?php echo $movie->trailer; ?>" frameborder="0" allow="accelerometer; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>' +
'</div>');
});
$(document).on('click', '#youtube-iframe', function (event) {
event.target.remove();
});
/** LOAD IMG **/
$('.PosterCardImg-imageContainer-1Ar4M[data-movie-id]').each(function (index, element) {
var movie_id = $(element).data('movie-id');

Loading…
Cancel
Save