add trailer for tv show, fix login on reinstall

master
root 2 years ago
parent 93f840b599
commit c4b64b2f96

@ -38,13 +38,14 @@ class Controller_Login extends Controller
try {
if (Input::method() === 'POST') {
$config = Config::load('db', true);
$configdb = Config::load('db', true);
$configCrypt = Config::load('crypt', true);
$login = Input::post('email');
$password = Input::post('password');
$password = hash('sha512', $config['default']['hash'] . $password);
$passwordHash = hash('sha512', $configCrypt['sodium']['cipherkey'] . $password);
if($user = Model_User::Login($login, $password)) {
if($user = Model_User::Login($login, $passwordHash)) {
$user->lastlogin = time();
$user->save();

@ -35,7 +35,7 @@ class Controller_Movie extends Controller_Home
public function action_list()
{
$movies = Model_Movie::getList();
$movies = Model_Movie::getAllMovies();
if(!$movies)
Response::redirect('/home');

@ -45,8 +45,6 @@ class Model_Movie extends Model_Overwrite
/** @var Model_Server */
private $_server = null;
public $trailer = null;
public function getSeason()
{
if(!$this->_season && $this->season_id !== null)
@ -471,7 +469,7 @@ class Model_Movie extends Model_Overwrite
return $movies_id_array;
}
public static function getList()
public static function getAllMovies()
{
return self::find(function ($query) {
/** @var Database_Query_Builder_Select $query */
@ -486,16 +484,7 @@ class Model_Movie extends Model_Overwrite
public function getTrailer()
{
try {
$this->trailer = Cache::get($this->id.'.trailer');
return $this->trailer;
} catch (CacheNotFoundException $e)
{
$trailer = new Model_Trailer($this->id, $this->originalTitle ?: $this->title, $this->year, $this->type);
$this->trailer = $trailer->getTrailer();
Cache::set($this->id . '.trailer', $this->trailer, 24 * 60 * 60);
return $this->trailer;
}
$trailer = new Model_Trailer($this->id, $this->originalTitle ?: $this->title, $this->year, $this->type);
return $trailer->getTrailer();
}
}

@ -1,10 +1,11 @@
<?php
use Fuel\Core\Debug;
use Fuel\Core\CacheNotFoundException;
use Fuel\Core\Debug;
class Model_Trailer
{
private $_movie_id;
private $_id;
private $_title;
@ -16,24 +17,12 @@ class Model_Trailer
private $_trailer_url;
public function __construct($movie_id, $title, $year, $type)
public function __construct($id, $title, $year, $type)
{
$this->_movie_id = $movie_id;
$this->_id = $id;
$this->_title = $title;
$this->_year = $year;
$this->_type = $type;
if($this->_type === 'movie') {
$this->getUrl();
if($this->_trailer_url === null)
return;
$this->getMovieTrailer();
if(!$this->_trailer)
$this->getMovieTeaser();
}
}
/**
@ -41,52 +30,69 @@ class Model_Trailer
*/
public function getTrailer()
{
if($this->_type !== 'movie')
return;
try
try {
throw new CacheNotFoundException('');
$this->_trailer = Cache::get($this->_id.'.trailer');
return $this->_trailer;
} catch (CacheNotFoundException $e)
{
$trailer = $this->getMovieTrailer();
$this->getUrl();
if(!$this->_trailer_url)
return null;
if(!$trailer)
$trailer = $this->getMovieTeaser();
$this->_getTrailer();
return $trailer;
} catch (Exception $e) {
return;
if(!$this->_trailer)
$this->_getTeaser();
if(!$this->_trailer)
return null;
Cache::set($this->_id . '.trailer', $this->_trailer, 24 * 60 * 60);
return $this->_trailer;
}
}
private function getUrl()
{
try {
$this->_trailer_url = Cache::get($this->_movie_id.'.trailer_url');
$this->_trailer_url = Cache::get($this->_id.'.trailer_url');
return $this->_trailer_url;
} catch (CacheNotFoundException $e)
{
$html = Request::forge('https://www.themoviedb.org/search/movie?query=' . urlencode($this->_title) . '+y%3A' . $this->_year . '&language=us', 'curl');
$type = $this->_type === 'movie' ? 'movie' : 'tv';
$entities = array('%21', '%2A', '%27', '%28', '%29', '%3B', '%3A', '%40', '%26', '%3D', '%2B', '%24', '%2C', '%2F', '%3F', '%25', '%23', '%5B', '%5D');
$replacements = array('!', '*', "'", "(", ")", ";", ":", "@", "&", "=", "+", "$", ",", "/", "?", "%", "#", "[", "]");
$title = str_replace($entities, $replacements, urlencode(htmlspecialchars_decode($this->_title, ENT_QUOTES)));
$html = Request::forge('https://www.themoviedb.org/search/' . $type . '?query=' . $title . '+y%3A' . $this->_year . '&language=us', 'curl');
$html->set_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0');
$html->execute();
if ($html->response()->status !== 200) return false;
if ($html->response()->status !== 200)
return false;
$media = $html->response()->body;
$regex = '/<a data-id="[a-z0-9]*" data-media-type="movie" data-media-adult="[a-z]*" class="[a-z]*" href="(\/movie\/[\d]*\?language\=us)">/i';
$regex = '/<a data-id="[a-z0-9]+" data-media-type="' . $type . '" data-media-adult="[a-z]+" class="[a-z]*" href="(\/' . $type . '\/[\d]+\?language\=us)">/i';
preg_match($regex, $media, $urls);
if (!isset($urls[1])) return false;
if (!isset($urls[1]))
return false;
$this->_trailer_url = explode('?', $urls[1])[0];
Cache::set($this->_movie_id . '.trailer_url', $this->_trailer_url, 24 * 60 * 60);
return $this->_trailer_url;
Cache::set($this->_id . '.trailer_url', $this->_trailer_url, 24 * 60 * 60);
return true;
}
}
private function getMovieTrailer()
private function _getTrailer()
{
$html = Request::forge('https://www.themoviedb.org' . $this->getUrl() . '/videos?active_nav_item=Trailers&video_language=en-US&language=en-US', 'curl');
$html->set_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0');
@ -112,17 +118,18 @@ class Model_Trailer
$this->_trailer = $youtube;
return $this->_trailer;
return true;
}
private function getMovieTeaser()
private function _getTeaser()
{
$html = Request::forge('https://www.themoviedb.org' . $this->getUrl() . '/videos?active_nav_item=Teasers&video_language=en-US&language=en-US', 'curl');
$html->set_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0');
$html->set_options([CURLOPT_FOLLOWLOCATION => true,]);
$html->execute();
if ($html->response()->status !== 200) return false;
if ($html->response()->status !== 200)
return false;
$media = $html->response()->body;
@ -130,12 +137,13 @@ class Model_Trailer
preg_match($regex, $media, $youtube);
if (!isset($youtube[1])) return false;
if (!isset($youtube[1]))
return false;
$youtube = preg_replace('/\&origin\=https%3A%2F%2Fwww\.themoviedb\.org/i', '', $youtube[1]);
$this->_trailer = $youtube;
return $this->_trailer;
return true;
}
}

@ -14,6 +14,7 @@ class Model_Tvshow extends Model_Overwrite
'plex_key',
'studio',
'title',
'originalTitle',
'contentRating',
'summary',
'rating',
@ -173,6 +174,7 @@ class Model_Tvshow extends Model_Overwrite
'plex_key' => $subsection['@attributes']['ratingKey'],
'studio' => isset($subsection['@attributes']['studio']) ? $subsection['@attributes']['studio'] : null,
'title' => $subsection['@attributes']['title'],
'originalTitle' => isset($subsection['@attributes']['originalTitle']) ? $subsection['@attributes']['originalTitle'] : $subsection['@attributes']['title'],
'contentRating' => isset($subsection['@attributes']['contentRating']) ? $subsection['@attributes']['contentRating'] : null,
'summary' => isset($subsection['@attributes']['summary']) ? $subsection['@attributes']['summary'] : null,
'rating' => isset($subsection['@attributes']['rating']) ? $subsection['@attributes']['rating'] : null,
@ -191,8 +193,6 @@ class Model_Tvshow extends Model_Overwrite
$tvshows_id_array[] = ['id' => $tvshow->id, 'name' => $tvshow->title];
//self::getTvShowSeasons($server, $tvshow);
if (isset($subsections['@attributes']))
break;
}
@ -249,4 +249,10 @@ class Model_Tvshow extends Model_Overwrite
return $this->_seasons;
}
public function getTrailer()
{
$trailer = new Model_Trailer($this->id, $this->originalTitle ?: $this->title, $this->year, 'tv_show');
return $trailer->getTrailer();
}
}

@ -18,6 +18,7 @@ return array(
9 => '010_create_user_history',
10 => '011_create_user_permission',
11 => '012_create_user_settings',
12 => '013_add_originaltitle_to_tvshow.php',
),
),
'module' =>

@ -1,5 +1,10 @@
<?php
return [
// /!\ WARNING /!\
// Using direct mode, exposed your personnal token
// we recommend you to not use it or to not use the owner's TOKEN of the server
'direct_mode' => false,
// Enable/Disabled the registration page
'registration' => true,

@ -0,0 +1,20 @@
<?php
namespace Fuel\Migrations;
class Add_originaltitle_to_tvshow
{
public function up()
{
\DBUtil::add_fields('tvshow', array(
'originalTitle' => array('constraint' => 255, 'null' => false, 'type' => 'varchar'),
));
}
public function down()
{
\DBUtil::drop_fields('tvshow', array(
'originalTitle'
));
}
}

@ -1,4 +1,4 @@
<div class="PrePlayPageHeader-pageHeader-2o14F PageHeader-pageHeader-18RSw">
<div class="PrePlayPageHeader-altPageHeader-3bZbS PrePlayPageHeader-pageHeader-2o14F PageHeader-pageHeader-18RSw">
<div class="PageHeaderLeft-pageHeaderLeft-2TxSo"><span
class="PageHeaderBreadcrumbButton-link-1N0DD"><?php echo $tvshow->title; ?></span></div>
<div class="PageHeaderRight-pageHeaderRight-2CT0g">
@ -7,6 +7,11 @@
<button id="id-22" title="<?php echo __('play'); ?>" data-toggle="tooltip" data-placement="bottom" role="button"
class="ToolbarButton-toolbarButton-3xzHJ Link-link-2XYrU Link-default-32xSO"
type="button"><i class="plex-icon-toolbar-play-560"></i></button>
<?php if(!Model_Permission::isGranted('RIGHT_TRAILER_DISABLED', $tvshow->getLibrary()) && $tvshow->getTrailer() !== null) : ?>
<button id="id-362" title="<?php echo __('watch_trailer'); ?>" 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-23" title="<?php echo __('random_roder'); ?>" data-toggle="tooltip" data-placement="bottom" role="button"
class="ToolbarButton-toolbarButton-3xzHJ Link-link-2XYrU Link-default-32xSO"
type="button"><i class="plex-icon-toolbar-shuffle-560"></i></button>
@ -58,6 +63,13 @@
</div>
</div>
</div>
<?php if(!Model_Permission::isGranted('RIGHT_TRAILER_DISABLED', $tvshow->getLibrary()) && $tvshow->getTrailer() !== null) : ?>
<div style="font-size: 20px;padding: 0;" class="col-sm-12 text-center">
<button id="id-362" class="Link-link-2XYrU Link-default-32xSO" style="background: #dc3535;border-radius: 3px;padding: 0 7px;width: 100%;margin-top: 15px;">
<i class="glyphicon video-hd"></i> <?php echo __('watch_trailer'); ?>
</button>
</div>
<?php endif; ?>
</div>
<div class="PrePlayMetadataContent-content-2ww3j" style="padding-left: 320px;">
<div class="Measure-container-2XznZ">
@ -278,6 +290,17 @@
summary.css('max-height', '78px');
}
});
/** LAUNCH TRAILER **/
$(document).on('click', '#id-362', function (event) {
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 $tvshow->getTrailer(); ?>" 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 **/
$('.actor_img').each(function (index, element) {
var actor_img = $(element).data('background');

Loading…
Cancel
Save