diff --git a/fuel/app/classes/controller/home.php b/fuel/app/classes/controller/home.php index 4dd4ca2..96f180e 100755 --- a/fuel/app/classes/controller/home.php +++ b/fuel/app/classes/controller/home.php @@ -26,7 +26,7 @@ class Controller_Home extends Controller_Security $server = $sessionServer ? Model_Server::find_by_pk($sessionServer->id) : Model_Server::find_one_by([ ['online', '=', 1], ['disable', '=', 0], - ], null, null); + ]); Lang::load('menu'); Lang::load('settings'); diff --git a/fuel/app/classes/controller/movie.php b/fuel/app/classes/controller/movie.php index efd37dc..51486ad 100644 --- a/fuel/app/classes/controller/movie.php +++ b/fuel/app/classes/controller/movie.php @@ -1,5 +1,6 @@ getTrailer(); - $this->template->title = $movie->title; $body->set('movie', $movie); @@ -70,7 +69,8 @@ class Controller_Movie extends Controller_Home $user_downloads = Model_User_Download::find(function ($query) use ($user_id) { $startOfDay = date("Y-m-d 00:00:00"); $endOfDay = date("Y-m-d 23:59:59"); - $query->where('user_id', $user_id) + $query->select(DB::expr('count(id) as count')) + ->where('user_id', $user_id) ->and_where('date', '>=', strtotime($startOfDay)) ->and_where('date', '<=', strtotime($endOfDay)) ; @@ -79,8 +79,8 @@ class Controller_Movie extends Controller_Home if (Model_Permission::isGranted('RIGHT_DOWNLOAD_DISABLED', $movie->getLibrary())) throw new FuelException('You dont have the permission to download in this library!'); - if (Model_Permission::isGranted('RIGHT_MAX_DOWNLOAD', $movie->getLibrary(), count($user_downloads))) - throw new FuelException('You reach the limit of download in this library today!'); + if (!Model_Permission::isGranted('RIGHT_MAX_DOWNLOAD', $movie->getLibrary(), $user_downloads[0]->count)) + throw new FuelException('You have reach the maximum number of download in this library today!'); $url = $movie->getDownloadLink(); @@ -152,9 +152,25 @@ class Controller_Movie extends Controller_Home if (!$movie) throw new FuelException('No movie found'); + $user_id = $this->_user->id; + + $user_histories = Model_User_History::find(function ($query) use ($movie_id, $user_id) { + $startOfDay = date("Y-m-d 00:00:00"); + $endOfDay = date("Y-m-d 23:59:59"); + $query->select(DB::expr('count(id) as count')) + ->where('user_id', $user_id) + ->and_where('movie_id', '<>', $movie_id) + ->and_where('date', '>=', strtotime($startOfDay)) + ->and_where('date', '<=', strtotime($endOfDay)) + ; + }); + if (Model_Permission::isGranted('RIGHT_WATCH_DISABLED', $movie->getLibrary())) throw new FuelException('You dont have the permission to watch in this library!'); + if (!Model_Permission::isGranted('RIGHT_MAX_WATCH', $movie->getLibrary(), $user_histories[0]->count)) + throw new FuelException('You have reach the maximum number of watch in this library for today!'); + $url = ($movie->getServer()->https === '1' ? 'https' : 'http') . '://'; $url .= $movie->getServer()->url . ($movie->getServer()->port ? ':' . $movie->getServer()->port : '') . '/'; $url .= 'video/:/'; diff --git a/fuel/app/classes/controller/rest/library.php b/fuel/app/classes/controller/rest/library.php index 3ee541a..d8efe1b 100644 --- a/fuel/app/classes/controller/rest/library.php +++ b/fuel/app/classes/controller/rest/library.php @@ -17,7 +17,10 @@ class Controller_Rest_Library extends Controller_Rest if ($library_id === null || $right_name === null || $checked === null) throw new FuelException('Missing parameters'); - $permission = Model_Permission::find_one_by('name', $right_name); + $permission = Model_Permission::find_one_by([ + ['name', '=', $right_name], + ['disable', '=', 0] + ]); $permission_id = $permission->id; diff --git a/fuel/app/classes/controller/rest/movie.php b/fuel/app/classes/controller/rest/movie.php index 8c84c51..0d1e8f9 100644 --- a/fuel/app/classes/controller/rest/movie.php +++ b/fuel/app/classes/controller/rest/movie.php @@ -1,9 +1,8 @@ id; + + $user_histories = Model_User_History::find(function ($query) use ($movie_id, $user_id) { + $startOfDay = date("Y-m-d 00:00:00"); + $endOfDay = date("Y-m-d 23:59:59"); + $query->select(DB::expr('count(id) as count')) + ->where('user_id', $user_id) + ->and_where('movie_id', '<>', $movie_id) + ->and_where('date', '>=', strtotime($startOfDay)) + ->and_where('date', '<=', strtotime($endOfDay)) + ; + }); if (Model_Permission::isGranted('RIGHT_WATCH_DISABLED', $movie->getLibrary())) throw new FuelException('You dont have the permission to watch in this library!'); + if (!Model_Permission::isGranted('RIGHT_MAX_WATCH', $movie->getLibrary(), $user_histories[0]->count)) + throw new FuelException('You have reach the maximum number of watch in this library for today!'); $user_settings = Model_User_Settings::find_one_by('user_id', Session::get('user')->id); @@ -52,24 +64,65 @@ class Controller_Rest_Movie extends Controller_Rest public function post_watching() { try { - $user = Session::get('user'); + $user_id = Session::get('user')->id; $movie_id = Input::post('movie_id'); $totaltime = Input::post('totaltime'); $timeplay = Input::post('timeplay'); - $isFinish = Input::post('isFinish'); + $is_ended = Input::post('is_ended') === 'true'; + + if (!$movie_id) + throw new FuelException('No movie id'); + + $movie = Model_Movie::find_by_pk($movie_id); + + if (!$movie) + throw new FuelException('No movie found'); + + $user_histories = Model_User_History::find(function ($query) use ($movie_id, $user_id) { + $startOfDay = date("Y-m-d 00:00:00"); + $endOfDay = date("Y-m-d 23:59:59"); + $query->select(DB::expr('count(id) as count')) + ->where('user_id', $user_id) + ->and_where('movie_id', '<>', $movie_id) + ->and_where('date', '>=', strtotime($startOfDay)) + ->and_where('date', '<=', strtotime($endOfDay)) + ; + }); + + if (Model_Permission::isGranted('RIGHT_WATCH_DISABLED', $movie->getLibrary())) + throw new FuelException('You dont have the permission to watch in this library!'); + + if (!Model_Permission::isGranted('RIGHT_MAX_WATCH', $movie->getLibrary(), $user_histories[0]->count)) + throw new FuelException('You have reach the maximum number of watch in this library for today!'); $watching = Model_User_History::find_one_by([ - ['movie_id', '=', $movie_id], - ['user_id', '=', $user->id] - ]) ?: new Model_User_History(); - - $watching->set([ - 'user_id' => $user->id, - 'movie_id' => $movie_id, - 'ended_time' => $totaltime, - 'watching_time' => $timeplay, - 'isFinish' => ($isFinish === 'true' ? true : false) - ]); + ['movie_id', '=', $movie_id], + ['user_id', '=', $user_id], + ['is_ended', '=', 0] + ]); + + $params = []; + + if($watching && $watching->date + (24 * 60 * 60) < time()) + { + $watching->set(['is_ended' => $is_ended]); + $watching->save(); + + $watching = null; + } + + if($watching === null){ + $watching = new Model_User_History(); + $params['date'] = time(); + } + + $params = array_merge($params, ['user_id' => $user_id, + 'movie_id' => $movie_id, + 'watching_time' => $timeplay, + 'ended_time' => $totaltime, + 'is_ended' => $is_ended]); + + $watching->set($params); $watching->save(); diff --git a/fuel/app/classes/controller/rest/search.php b/fuel/app/classes/controller/rest/search.php index bcdd530..b0ca401 100644 --- a/fuel/app/classes/controller/rest/search.php +++ b/fuel/app/classes/controller/rest/search.php @@ -9,23 +9,50 @@ class Controller_Rest_Search extends Controller_Rest { public function get_index() { - $search = '%'.Input::get('search').'%'; + $search = '+'.implode('* +', + explode(' ', + rtrim(Input::get('search')) + ) + ).'*'; - $query = DB::query('SELECT * FROM '.DB::table_prefix('movie'). - ' WHERE '.DB::table_prefix('movie').'.type = :type - AND ('.DB::table_prefix('movie').'.`title` LIKE :search - OR MATCH('.DB::table_prefix('movie').'.`title`) AGAINST(:search)) - ORDER BY MATCH('.DB::table_prefix('movie').'.`title`) - AGAINST(:search) DESC LIMIT 5'); + $query = DB::query('SELECT * FROM '.DB::table_prefix('movie').' + WHERE MATCH('.DB::table_prefix('movie').'.`title`) AGAINST(:search IN BOOLEAN MODE) + ORDER BY MATCH('.DB::table_prefix('movie').'.`title`) AGAINST(:search IN BOOLEAN MODE) DESC LIMIT 6'); + $query->bind('search', $search); + $movies = $query->execute(); + $query = DB::query('SELECT * FROM '.DB::table_prefix('tvshow').' + WHERE MATCH('.DB::table_prefix('tvshow').'.`title`) AGAINST(:search IN BOOLEAN MODE) + ORDER BY MATCH('.DB::table_prefix('tvshow').'.`title`) AGAINST(:search IN BOOLEAN MODE) DESC LIMIT 4'); $query->bind('search', $search); + $tv_shows = $query->execute(); + + $results = []; + + foreach ($movies as $movie) { + $data = [ + 'id' => $movie['id'], + 'type' => $movie['type'], + 'title' => $movie['title'], + 'year' => $movie['type'] === 'movie' ? $movie['year'] : '', + 'tvshow' => $movie['tvshow'] ?? '', + ]; + + $results[] = $data; + } - $query->param('type', 'movie'); - $search_movie = $query->execute(); + foreach ($tv_shows as $movie) { + $data = [ + 'id' => $movie['id'], + 'type' => 'tvshow', + 'title' => $movie['title'], + 'year' => $movie['year'], + 'tvshow' => $movie['tvshow'] ?? '', + ]; - $query->param('type', 'episode'); - $search_episode = $query->execute(); + $results[] = $data; + } - return $this->response(['movies' => $search_movie, 'episodes' => $search_episode]); + return $this->response($results); } } \ No newline at end of file diff --git a/fuel/app/classes/controller/settings.php b/fuel/app/classes/controller/settings.php index c09786d..7badfc6 100644 --- a/fuel/app/classes/controller/settings.php +++ b/fuel/app/classes/controller/settings.php @@ -3,8 +3,7 @@ use Fuel\Core\Config; use Fuel\Core\Input; use Fuel\Core\Lang; - use Fuel\Core\Migrate; - use Fuel\Core\Response; +use Fuel\Core\Response; use Fuel\Core\Session; use Fuel\Core\View; diff --git a/fuel/app/classes/controller/settings/libraries.php b/fuel/app/classes/controller/settings/libraries.php index e64ac5a..feab7bc 100644 --- a/fuel/app/classes/controller/settings/libraries.php +++ b/fuel/app/classes/controller/settings/libraries.php @@ -35,15 +35,14 @@ class Controller_Settings_Libraries extends Controller_Settings if($library === null) Response::redirect('/settings/libraries'); - $permissions = Model_Permission::find_all(); + $permissions = Model_Permission::find_by('disable', 0); $library_permissions = Model_Library_Permission::find_by('library_id', $library_id); - $library_permissions = $library_permissions ?: []; - $temp = []; // ORDER ARRAY BY PERMISSION ID + // MORE EASY TO DISPLAY foreach ($library_permissions as $library_permission) { $temp[$library_permission->permission_id] = $library_permission; } diff --git a/fuel/app/classes/model/movie.php b/fuel/app/classes/model/movie.php index 5a02ac4..c50ca37 100644 --- a/fuel/app/classes/model/movie.php +++ b/fuel/app/classes/model/movie.php @@ -1,5 +1,6 @@ _server->https === '1' ? 'https' : 'http') . '://' . $this->_server->url . ($this->_server->port ? ':' . $this->_server->port : '') . '/video/:/transcode/universal/session/' . $this->_session . '/base/index.m3u8'; } catch (Exception $exception) { if($exception->getCode() === 403) - throw new FuelException('Cannot connect to the server.
The token must be outdated!', 200); + throw new FuelException('Cannot connect to the server.
The token must be outdated!', $exception->getCode()); else - throw new FuelException($exception->getMessage(), 200); + throw new FuelException($exception->getMessage(), $exception->getCode()); } } @@ -478,7 +479,7 @@ class Model_Movie extends Model_Overwrite ->select('*') ->where('type', 'movie') ->group_by('originalTitle', 'title', 'year') - ->order_by('title', 'ASC') + ->order_by(DB::expr("str_to_date(`originallyAvailableAt`, '%Y-%m-%d')"), 'DESC') ; }); } diff --git a/fuel/app/classes/model/permission.php b/fuel/app/classes/model/permission.php index 7adc4cf..a2e73df 100644 --- a/fuel/app/classes/model/permission.php +++ b/fuel/app/classes/model/permission.php @@ -74,11 +74,11 @@ class Model_Permission extends Model_Overwrite * RETURN TRUE */ if($library_permission === NULL) - return false; + return true; else if((int)$library_permission->value > $data) - return false; - else return true; + else + return false; } if ($permission->name === 'RIGHT_MAX_DOWNLOAD_SPEED') { @@ -91,12 +91,17 @@ class Model_Permission extends Model_Overwrite } if ($permission->name === 'RIGHT_MAX_WATCH') { - /** @TODO IF (NUMBER_WATCH <= MAX_WATCH) // in last 24h - * RETURN TRUE - * ELSE + /** @TODO IF (MAX_WATCH > NUMBER_WATCH) // in last 24h * RETURN FALSE + * ELSE + * RETURN TRUE */ - return true; + if($library_permission === NULL) + return true; + else if((int)$library_permission->value > $data) + return true; + else + return false; } if ($permission->name === 'RIGHT_MAX_QUALITY') { diff --git a/fuel/app/classes/model/user/history.php b/fuel/app/classes/model/user/history.php index 1a85fe6..56a21a0 100644 --- a/fuel/app/classes/model/user/history.php +++ b/fuel/app/classes/model/user/history.php @@ -12,7 +12,8 @@ class Model_User_History extends Model_Overwrite 'movie_id', 'watching_time', 'ended_time', - 'is_ended' + 'is_ended', + 'date' ); private $_movie = null; diff --git a/fuel/app/config/routes.php b/fuel/app/config/routes.php index 448248e..4650d3d 100755 --- a/fuel/app/config/routes.php +++ b/fuel/app/config/routes.php @@ -9,9 +9,9 @@ return array( 'season/:season_id' => 'season/index', 'episode/:movie_id/download' => 'movie/download', 'episode/:episode_id' => 'episode/index', + 'movie/list' => 'movie/list', 'movie/:movie_id/video/\:/transcode/:transcode/session/:session/:index/:base' => 'movie/stream', 'movie/:movie_id/download' => 'movie/download', 'movie/:movie_id' => 'movie/index', - 'movie/list' => 'movie/list', 'settings/libraries/premissions/:library_id' => 'settings/libraries/permissions' ); diff --git a/fuel/app/migrations/004_create_movie.php b/fuel/app/migrations/004_create_movie.php index 9bab534..51b93f6 100644 --- a/fuel/app/migrations/004_create_movie.php +++ b/fuel/app/migrations/004_create_movie.php @@ -30,14 +30,14 @@ class Create_movie \DB::query('CREATE INDEX constraintMovieLibrary ON ' . \DB::table_prefix('movie') . '(`library_id`)')->execute(); \DB::query('CREATE INDEX constraintMovieSeason ON ' . \DB::table_prefix('movie') . '(`season_id`)')->execute(); - \DB::query('CREATE INDEX searchTitle ON ' . \DB::table_prefix('movie') . '(`title` DESC)')->execute(); + \DB::query('CREATE FULLTEXT searchTitle ON ' . \DB::table_prefix('movie') . '(`title` DESC)')->execute(); } public function down() { \DB::query('DROP INDEX constraintMovieLibrary ON ' . \DB::table_prefix('movie'))->execute(); \DB::query('DROP INDEX constraintMovieSeason ON ' . \DB::table_prefix('movie'))->execute(); - \DB::query('DROP INDEX searchTitle ON ' . \DB::table_prefix('movie'))->execute(); + \DB::query('DROP FULLTEXT searchTitle ON ' . \DB::table_prefix('movie'))->execute(); \DBUtil::drop_table('movie'); } diff --git a/fuel/app/migrations/010_create_user_history.php b/fuel/app/migrations/010_create_user_history.php index 8af598b..21f4169 100644 --- a/fuel/app/migrations/010_create_user_history.php +++ b/fuel/app/migrations/010_create_user_history.php @@ -13,6 +13,7 @@ class Create_user_history 'watching_time' => array('type' => 'int', 'null' => false, 'constraint' => 11), 'ended_time' => array('default' => '0', 'type' => 'int', 'null' => false, 'constraint' => 11), 'is_ended' => array('default' => '0', 'type' => 'int', 'null' => false, 'constraint' => 1), + 'date' => array('default' => '0', 'type' => 'int', 'null' => false, 'constraint' => 1), ), array('id')); \DB::query('CREATE INDEX constraintUserUserHistory ON ' . \DB::table_prefix('user_history') . '(`user_id`)')->execute(); diff --git a/fuel/app/views/layout/body.php b/fuel/app/views/layout/body.php index 305b0be..49c5a94 100644 --- a/fuel/app/views/layout/body.php +++ b/fuel/app/views/layout/body.php @@ -105,36 +105,44 @@ $(function() { method: 'GET', data: {search: $(this).val()}, dataType: 'json' - }).done(function (data) { + }).done(function (datas) { $('._search').remove(); - if(data.movies.length === 0 && data.episodes.length === 0) + if(datas.length === 0) return; $('#search_result').removeClass('hidden'); - data.movies.forEach(function (movie, index) { - let template = $('#film_template').clone(); + datas.forEach(function (data, index) { + if(!data.type) + return; + + let template = $('#search_template').clone(); template.removeClass('hidden'); template.addClass('_search'); - template.html(template.html().replace(/{\$TITLE\$}/g, movie.title)); - template.html(template.html().replace(/{\$YEAR\$}/g, movie.year)); - template.html(template.html().replace(/{\$MOVIEID\$}/g, movie.id)); - $('#film_template').after(template); - }); + if(data.type === 'movie') { + template.html(template.html().replace(/{\$HREF_SEARCH\$}/g, '/movie/' + data.id)); + template.html(template.html().replace(/{\$URL_COVER\$}/g, '/cover/movie?movie_id=' + data.id)); + } - data.episodes.forEach(function (episode, index) { - let template = $('#episode_template').clone(); + if(data.type === 'episode') { + template.html(template.html().replace(/{\$HREF_SEARCH\$}/g, '/episode/' + data.id)); + template.html(template.html().replace(/{\$URL_COVER\$}/g, '/cover/movie?movie_id=' + data.id)); + } - template.removeClass('hidden'); - template.addClass('_search'); - template.html(template.html().replace(/{\$TITLE\$}/g, episode.title)); - template.html(template.html().replace(/{\$YEAR\$}/g, episode.year)); - template.html(template.html().replace(/{\$MOVIEID\$}/g, episode.id)); + if(data.type === 'tvshow') { + template.html(template.html().replace(/{\$HREF_SEARCH\$}/g, '/tvshow/' + data.id)); + template.html(template.html().replace(/{\$URL_COVER\$}/g, '/cover/tvshow?tvshow_id=' + data.id)); + } + + template.html(template.html().replace(/{\$TITLE\$}/g, data.title)); + template.html(template.html().replace(/{\$YEAR\$}/g, data.year)); + template.html(template.html().replace(/{\$TYPE\$}/g, data.type)); + template.html(template.html().replace(/{\$TVSHOW\$}/g, data.tvshow)); - $('#episode_template').after(template); + $('#search_template').after(template); }); }).fail(function (data) { console.error(data.responseText); diff --git a/fuel/app/views/layout/search.php b/fuel/app/views/layout/search.php index 538a07c..91d5fe5 100644 --- a/fuel/app/views/layout/search.php +++ b/fuel/app/views/layout/search.php @@ -4,18 +4,18 @@ de résultats...
-
Library
+
-
Films
- -
+
Épisodes
*/ + ?>
diff --git a/fuel/app/views/movie/index.php b/fuel/app/views/movie/index.php index 2fc7153..9ee1d5e 100644 --- a/fuel/app/views/movie/index.php +++ b/fuel/app/views/movie/index.php @@ -94,11 +94,11 @@
- getMetaData()['Stream']['Audio'][0]) && preg_match('/7\.1(\([a-z]*\))?/',$movie->getMetaData()['Stream']['Audio'][0]['audioChannelLayout'])) : ?> + getMetaData()['Stream']['Audio'][0]) && preg_match('/7\.1(\([a-z]*\))?/',$movie->getMetaData()['Stream']['Audio'][0]['displayTitle'])) : ?>
- getMetaData()['Stream']['Audio'][0]) && preg_match('/5\.1(\([a-z]*\))?/',$movie->getMetaData()['Stream']['Audio'][0]['audioChannelLayout'])) : ?> + getMetaData()['Stream']['Audio'][0]) && preg_match('/5\.1(\([a-z]*\))?/',$movie->getMetaData()['Stream']['Audio'][0]['displayTitle'])) : ?>
- getMetaData()['Stream']['Audio'][0]) && preg_match('/stereo/',$movie->getMetaData()['Stream']['Audio'][0]['audioChannelLayout'])) : ?> + getMetaData()['Stream']['Audio'][0]) && preg_match('/Stereo/',$movie->getMetaData()['Stream']['Audio'][0]['displayTitle'])) : ?>
diff --git a/fuel/app/views/movie/list.php b/fuel/app/views/movie/list.php index dcfafdb..2e163fc 100644 --- a/fuel/app/views/movie/list.php +++ b/fuel/app/views/movie/list.php @@ -12,7 +12,7 @@ @@ -217,88 +217,72 @@
diff --git a/fuel/app/views/settings/servers.php b/fuel/app/views/settings/servers.php index ae944a3..ec7223d 100644 --- a/fuel/app/views/settings/servers.php +++ b/fuel/app/views/settings/servers.php @@ -93,10 +93,10 @@ }).done(function (data) { show_alert('success', 'Server save succesfully!'); $('.media-server-modal button.close').click(); + setTimeout(function(){location.reload()}, 200); }).fail(function (data) { data = JSON.parse(data.responseText); show_alert('error', data.message); - setTimeout(function(){location.reload()}, 200); }); }); 0) : ?> diff --git a/public/assets/js/player.js b/public/assets/js/player.js index 5f639b9..4e75e90 100644 --- a/public/assets/js/player.js +++ b/public/assets/js/player.js @@ -13,7 +13,7 @@ function toHHMMSS(num) { return times + minutes + ':' + seconds; } -async function updateWatching(movie_id, totaltime, timeplay, isFinish = false){ +async function updateWatching(movie_id, totaltime, timeplay, is_ended = false){ $.ajax({ url: '/rest/movie/watching', method: 'POST', @@ -21,7 +21,7 @@ async function updateWatching(movie_id, totaltime, timeplay, isFinish = false){ movie_id: movie_id, totaltime: totaltime, timeplay: timeplay, - isFinish: isFinish + is_ended: is_ended }, dataType: 'json' }).done(function (data) { @@ -116,7 +116,7 @@ function launchPlayer(view) { let now = Date.now(); - if(totaltime !== null && timeplay !== 0 && (lastUpdateTime === 0 || (lastUpdateTime + 10*1000) < now)) { + if(totaltime !== null && timeplay !== 0 && (lastUpdateTime === 0 || (lastUpdateTime + 5*1000) < now)) { lastUpdateTime = now; updateWatching(movie_id, totaltime, timeplay, (percent > 97)); }