Add trailer for movies

pull/9/head
Chewbaka69 6 years ago
parent 38647b1f92
commit 241c58888f

@ -19,7 +19,10 @@ class Controller_Movie extends Controller_Home
$movie->getMetaData();
$movie->getTrailer();
$body = View::forge('movie/index');
$body->set('movie', $movie);
$this->template->body = $body;

@ -2,6 +2,7 @@
use Fuel\Core\Config;
use Fuel\Core\DB;
use Fuel\Core\Format;
use Fuel\Core\Request;
use Fuel\Core\Cache;
use Fuel\Core\CacheNotFoundException;
@ -43,6 +44,8 @@ class Model_Movie extends Model_Overwrite
private $_library = null;
private $_server = null;
public $trailer = null;
public function getSeason()
{
if(!$this->_season)
@ -372,7 +375,7 @@ class Model_Movie extends Model_Overwrite
->where('server.id', $server->id)
->and_where('movie.type', 'episode')
->order_by('movie.addedAt', 'DESC')
->order_by(DB::expr('MAX(' . $conf['default']['table_prefix'] .'movie.addedAt)'), 'DESC')//'movie.addedAt', 'DESC')
->order_by(DB::expr('MAX(' . $conf['default']['table_prefix'] .'movie.addedAt)'), 'DESC ')//'movie.addedAt', 'DESC')
->group_by('movie.season_id')
->limit(30)
;
@ -408,4 +411,46 @@ class Model_Movie extends Model_Overwrite
;
});
}
public function getTrailer()
{
if($this->type === 'movie') {
$html = Request::forge('https://www.themoviedb.org/search/movie?query=' . urlencode($this->originalTitle ?: $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;
$url = explode('?', $urls[1]);
$html = Request::forge('https://www.themoviedb.org' . $url[0] . '/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;
$youtube = preg_replace('/\&origin\=https%3A%2F%2Fwww\.themoviedb\.org/i', '', $youtube[1]);
$this->trailer = $youtube;
}
}
}

@ -9,9 +9,11 @@
class="ToolbarButton-toolbarButton-3xzHJ Link-link-2XYrU Link-default-32xSO"
type="button"><i class="plex-icon-toolbar-play-560" aria-hidden="true"></i>
</button>
<?php if($movie->trailer !== null) : ?>
<button id="id-362" title="Visionner la bande annonce." data-placement="bottom" data-toggle="tooltip" role="button" class="ToolbarButton-toolbarButton-3xzHJ Link-link-2XYrU Link-default-32xSO" type="button">
<i class="plex-icon-toolbar-play-trailer-560" aria-hidden="true"></i>
</button>
<?php endif; ?>
<button id="id-21" title="Marquer comme vu" data-placement="bottom" data-toggle="tooltip" role="button" class="ToolbarButton-toolbarButton-3xzHJ Link-link-2XYrU Link-default-32xSO" type="button">
<i class="plex-icon-toolbar-played-toggle-560" aria-hidden="true"></i>
</button>
@ -215,9 +217,9 @@
<div class="PrePlayDetailsGroupItem-label-2Ee43">Audio</div>
<div class="PrePlayDetailsGroupItem-content-1aRNU">
<span>
<?php echo $movie->getMetaData()['Stream']['Audio'][0]['language']; ?>
<?php echo isset($movie->getMetaData()['Stream']['Audio'][0]['language']) ? $movie->getMetaData()['Stream']['Audio'][0]['language'] : ''; ?>
<span class="DashSeparator-separator-2a3yn"></span>
<?php echo isset($movie->getMetaData()['Stream']['Audio'][0]['displayTitle']) ? $movie->getMetaData()['Stream']['Audio'][0]['displayTitle'] : isset($movie->getMetaData()['Stream']['Audio'][0]['title']) ? $movie->getMetaData()['Stream']['Audio'][0]['title'] : $movie->getMetaData()['Stream']['Audio'][0]['language']; ?>
<?php echo isset($movie->getMetaData()['Stream']['Audio'][0]['displayTitle']) ? $movie->getMetaData()['Stream']['Audio'][0]['displayTitle'] : (isset($movie->getMetaData()['Stream']['Audio'][0]['title']) ? $movie->getMetaData()['Stream']['Audio'][0]['title'] : $movie->getMetaData()['Stream']['Audio'][0]['language']); ?>
</span>
</div>
</div>
@ -299,7 +301,7 @@
<a data-qa-id="castTitle" title="<?php echo $role['@attributes']['tag']; ?>" href="#" role="link" class=" MetadataPosterTitle-singleLineTitle-24_DN MetadataPosterTitle-title-3tU5F Link-link-2XYrU Link-default-32xSO">
<?php echo $role['@attributes']['tag']; ?>
</a>
<span class=" MetadataPosterTitle-singleLineTitle-24_DN MetadataPosterTitle-title-3tU5F MetadataPosterTitle-isSecondary-2VUxY " title="Johnny English">
<span class=" MetadataPosterTitle-singleLineTitle-24_DN MetadataPosterTitle-title-3tU5F MetadataPosterTitle-isSecondary-2VUxY " title="<?php echo $role['@attributes']['role']; ?>">
<?php echo $role['@attributes']['role']; ?>
</span>
</div>
@ -368,6 +370,17 @@
console.error(data);
});
});
/** 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' +
'</div>');
});
/** LOAD IMG **/
$('.PosterCardImg-imageContainer-1Ar4M[data-movie-id]').each(function (index, element) {
var movie_id = $(element).data('movie-id');

Loading…
Cancel
Save