@ -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;
}
}
}