From b8b98c2754017f1688916f8d1799055693b04abc Mon Sep 17 00:00:00 2001 From: root Date: Wed, 8 Apr 2020 16:26:23 +0200 Subject: [PATCH] Update cache time, add cache to home page, fixe some errors, add permission watch on movie/tv show, update home movie/tv show from plex server, update install --- fuel/app/classes/controller/home.php | 6 +- fuel/app/classes/controller/rest/install.php | 10 +- fuel/app/classes/controller/rest/movie.php | 4 + fuel/app/classes/controller/settings.php | 5 +- .../classes/controller/settings/libraries.php | 8 +- fuel/app/classes/model/movie.php | 10 +- fuel/app/classes/model/permission.php | 81 +++++ fuel/app/classes/model/season.php | 2 +- fuel/app/classes/model/server.php | 25 +- fuel/app/classes/model/settings.php | 19 -- fuel/app/classes/model/trailer.php | 6 +- fuel/app/classes/model/tvshow.php | 5 +- fuel/app/lang/en/permissions.php | 18 +- fuel/app/lang/en/settings.php | 1 + fuel/app/views/episode/index.php | 3 +- fuel/app/views/home/index.php | 28 +- fuel/app/views/season/index.php | 5 +- fuel/app/views/settings/libraries.php | 15 +- .../views/settings/libraries/permissions.php | 5 +- fuel/app/views/settings/servers.php | 8 +- fuel/app/views/stream/index.php | 293 ------------------ 21 files changed, 189 insertions(+), 368 deletions(-) delete mode 100644 fuel/app/classes/model/settings.php delete mode 100644 fuel/app/views/stream/index.php diff --git a/fuel/app/classes/controller/home.php b/fuel/app/classes/controller/home.php index 9362d69..a1385f7 100755 --- a/fuel/app/classes/controller/home.php +++ b/fuel/app/classes/controller/home.php @@ -21,10 +21,10 @@ class Controller_Home extends Controller_Template if(null === $user) Response::redirect('/login'); - $server = $sessionServer ? Model_Server::find_by_pk($sessionServer->id) : (Model_Server::find_one_by('user_id', $user->id) ?: Model_Server::find_by([ + $server = $sessionServer ? Model_Server::find_by_pk($sessionServer->id) : (Model_Server::find_one_by('user_id', $user->id) ?: Model_Server::find_one_by([ ['online', '=', 1], ['disable', '=', 0], - ], null, null, 10)[0] + ], null, null)[0] ); if(!$server) @@ -73,7 +73,7 @@ class Controller_Home extends Controller_Template $episodes = $this->template->MenuServer->getThirtyLastedTvShows(); - $movies = $this->template->MenuServer->getThirtyLastedMovies($this->template->MenuServer); + $movies = $this->template->MenuServer->getThirtyLastedMovies(); $body->set('episodes', $episodes); $body->set('movies', $movies); diff --git a/fuel/app/classes/controller/rest/install.php b/fuel/app/classes/controller/rest/install.php index b6fefdd..c2f0ae9 100755 --- a/fuel/app/classes/controller/rest/install.php +++ b/fuel/app/classes/controller/rest/install.php @@ -161,7 +161,7 @@ class Controller_Rest_Install extends Controller_Rest 'title' => array('constraint' => 255, 'type' => 'varchar'), 'contentRating' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), 'summary' => array('type' => 'text', 'null' => true), - 'rating' => array('constraint' => 3, 'type' => 'varchar', 'null' => true), + 'rating' => array('constraint' => 4, 'type' => 'varchar', 'null' => true), 'year' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'thumb' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), 'art' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), @@ -217,7 +217,7 @@ class Controller_Rest_Install extends Controller_Rest 'title' => array('constraint' => 255, 'type' => 'varchar'), 'originalTitle' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), 'summary' => array('type' => 'text', 'null' => true), - 'rating' => array('constraint' => 3, 'type' => 'varchar', 'null' => true), + 'rating' => array('constraint' => 4, 'type' => 'varchar', 'null' => true), 'year' => array('constraint' => 11, 'type' => 'int', 'null' => true), 'thumb' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), 'art' => array('constraint' => 255, 'type' => 'varchar', 'null' => true), @@ -273,7 +273,7 @@ class Controller_Rest_Install extends Controller_Rest 'id' => array('constraint' => 36, 'type' => 'varchar'), 'permission_id' => array('constraint' => 36, 'type' => 'varchar'), 'library_id' => array('constraint' => 36, 'type' => 'varchar'), - 'value' => array('constraint' => 36, 'type' => 'varchar'), + 'value' => array('constraint' => 36, 'type' => 'varchar', 'null' => true), 'disable' => array('constraint' => 1, 'type' => 'int', 'default' => 0) ), array('id'), false, 'InnoDB', 'utf8_unicode_ci' @@ -493,11 +493,11 @@ class Controller_Rest_Install extends Controller_Rest $logs .= 'Foreign key create!'."\r\n"; DB::insert('permission',['name', 'parameters']) - ->values(['RIGHT_WATCH']) + ->values(['RIGHT_WATCH_DISABLED']) ->values(['RIGHT_MAX_WATCH', 1]) ->values(['RIGHT_MAX_QUALITY', 1]) ->values(['RIGHT_MAX_CONCURRENT_STREAM', 1]) - ->values(['RIGHT_DOWNLOAD', 1]) + ->values(['RIGHT_DOWNLOAD_DISABLED']) ->values(['RIGHT_MAX_DOWNLOAD', 1]) ; diff --git a/fuel/app/classes/controller/rest/movie.php b/fuel/app/classes/controller/rest/movie.php index 53818b2..22f99f0 100644 --- a/fuel/app/classes/controller/rest/movie.php +++ b/fuel/app/classes/controller/rest/movie.php @@ -11,6 +11,7 @@ class Controller_Rest_Movie extends Controller_Rest public function get_stream() { try { + $movie_id = Input::get('movie_id'); if (!$movie_id) @@ -21,6 +22,9 @@ class Controller_Rest_Movie extends Controller_Rest if (!$movie) throw new FuelException('No movie found'); + if(!Model_Permission::isGranted('RIGHT_WATCH_DISABLED', $movie)) + throw new FuelException('You dont have the permission to watch in this library!'); + $user_settings = Model_Setting::find_one_by('user_id', Session::get('user')->id); if ($movie->type !== 'movie') diff --git a/fuel/app/classes/controller/settings.php b/fuel/app/classes/controller/settings.php index d8afc47..71dbb77 100644 --- a/fuel/app/classes/controller/settings.php +++ b/fuel/app/classes/controller/settings.php @@ -46,9 +46,9 @@ class Controller_Settings extends Controller_Template ; }); - $this->template->countServers = count($servers); + $this->template->countServers = $servers ? count($servers) : 0; - $this->template->countLibraries = count($libraries); + $this->template->countLibraries = $libraries ? count($libraries): 0; $this->template->servers = $servers; @@ -96,6 +96,7 @@ class Controller_Settings extends Controller_Template $body = View::forge('settings/servers'); + $body->set('countServers',$this->template->countServers); $body->set('servers', $this->template->servers); $body->set('user', Session::get('user')); diff --git a/fuel/app/classes/controller/settings/libraries.php b/fuel/app/classes/controller/settings/libraries.php index 5c32427..e64ac5a 100644 --- a/fuel/app/classes/controller/settings/libraries.php +++ b/fuel/app/classes/controller/settings/libraries.php @@ -13,6 +13,7 @@ class Controller_Settings_Libraries extends Controller_Settings $body = View::forge('settings/libraries'); + $body->set('countLibraries', $this->template->countLibraries); $body->set('libraries', $this->template->libraries); $body->set('user', Session::get('user')); @@ -29,6 +30,11 @@ class Controller_Settings_Libraries extends Controller_Settings $library_id = $this->param('library_id'); + $library = Model_Library::find_by_pk($library_id); + + if($library === null) + Response::redirect('/settings/libraries'); + $permissions = Model_Permission::find_all(); $library_permissions = Model_Library_Permission::find_by('library_id', $library_id); @@ -44,7 +50,7 @@ class Controller_Settings_Libraries extends Controller_Settings $library_permissions = $temp; - $body->set('library_id', $library_id); + $body->set('library', $library); $body->set('permissions', $permissions); $body->set('library_permissions', $library_permissions); $body->set('user', Session::get('user')); diff --git a/fuel/app/classes/model/movie.php b/fuel/app/classes/model/movie.php index 9116f0f..9b7b3a3 100644 --- a/fuel/app/classes/model/movie.php +++ b/fuel/app/classes/model/movie.php @@ -145,13 +145,13 @@ class Model_Movie extends Model_Overwrite try { $curl->execute(); } catch (Exception $exception) { - Cache::set($this->id . $path_cache, null); + Cache::set($this->id . $path_cache, null, 24 * 60 * 60); } if ($curl->response()->status !== 200) return false; - Cache::set($this->id . $path_cache, $curl->response()->body); + Cache::set($this->id . $path_cache, $curl->response()->body, 24 * 60 * 60); } public function getThumb($width = null, $height = null) @@ -254,7 +254,7 @@ class Model_Movie extends Model_Overwrite } } - Cache::set($this->id . '.metadata', $this->metadata); + Cache::set($this->id . '.metadata', $this->metadata, 7 * 24 * 60 * 60); return $this->metadata; } catch (Exception $exception) { throw new FuelException($exception->getMessage(),$exception->getCode()); @@ -375,7 +375,7 @@ class Model_Movie extends Model_Overwrite || (!isset($this->metadata['Media']['Part']) && !isset($this->metadata['Media'][0]['Part'])) || (!isset($this->metadata['Media']['Part']['@attributes']) && !isset($this->metadata['Media'][0]['Part']['@attributes'])) || (!isset($this->metadata['Media']['Part']['@attributes']['key']) && !isset($this->metadata['Media'][0]['Part']['@attributes']['key'])) ) { - Cache::set($this->id . '.download', null); + Cache::set($this->id . '.download', null,24 * 60 * 60); return null; } @@ -390,7 +390,7 @@ class Model_Movie extends Model_Overwrite $this->download = $curl; - Cache::set($this->id . '.download', $curl); + Cache::set($this->id . '.download', $curl, 24 * 60 * 60); return $this->download; } catch (Exception $exception) { throw new FuelException($exception->getMessage(),$exception->getCode()); diff --git a/fuel/app/classes/model/permission.php b/fuel/app/classes/model/permission.php index d6ae271..d359786 100644 --- a/fuel/app/classes/model/permission.php +++ b/fuel/app/classes/model/permission.php @@ -2,6 +2,15 @@ class Model_Permission extends Model_Overwrite { + /** + * RIGHT_WATCH_DISABLED + * RIGHT_DOWNLOAD_DISABLED + * RIGHT_MAX_DOWNLOAD + * RIGHT_MAX_WATCH + * RIGHT_MAX_QUALITY + * RIGHT_MAX_CONCURRENT_STREAM + */ + protected static $_table_name = 'permission'; protected static $_primary_key = 'id'; protected static $_properties = array( @@ -9,4 +18,76 @@ class Model_Permission extends Model_Overwrite 'name', 'disable' ); + + /** + * @param string $permission + * @param Model_Movie $movie + * @return bool + */ + public static function isGranted($permission, Model_Movie $movie) + { + if ($movie === null) + return false; + + $library = $movie->getLibrary(); + + if ($library === null) + return false; + + $permission = Model_Permission::find_one_by('name', $permission); + + if ($permission === null) + return true; + + $library_permission = Model_Library_Permission::find_one_by([ + ['library_id', '=', $library->id], + ['permission_id', '=', $permission->id], + ['disable', '=', 0] + ]); + + if ($library_permission === null) + return true; + + if ($permission->name === 'RIGHT_WATCH_DISABLED') + return false; + + if ($permission->name === 'RIGHT_DOWNLOAD_DISABLED') + return false; + + if ($permission->name === 'RIGHT_MAX_DOWNLOAD') { + /** @TODO IF (NUMBER_DOWNLOAD <= MAX_DOWNLOAD) + * RETURN TRUE + * ELSE + * RETURN FALSE + */ + return true; + } + + if ($permission->name === 'RIGHT_MAX_WATCH') { + /** @TODO IF (NUMBER_WATCH <= MAX_WATCH) + * RETURN TRUE + * ELSE + * RETURN FALSE + */ + return true; + } + + if ($permission->name === 'RIGHT_MAX_QUALITY') { + /** @TODO IF (VIDEO SETTINGS QUALITY <= MAX_QUALITY) + * RETURN TRUE + * ELSE + * RETURN FALSE + */ + return true; + } + + if ($permission->name === 'RIGHT_MAX_CONCURRENT_STREAM') { + /** @TODO IF (VIDEO SETTINGS QUALITY <= MAX_QUALITY) + * RETURN TRUE + * ELSE + * RETURN FALSE + */ + return true; + } + } } \ No newline at end of file diff --git a/fuel/app/classes/model/season.php b/fuel/app/classes/model/season.php index 6dc6380..9800e89 100644 --- a/fuel/app/classes/model/season.php +++ b/fuel/app/classes/model/season.php @@ -104,7 +104,7 @@ class Model_Season extends Model_Overwrite if ($curl->response()->status !== 200) return false; - Cache::set($this->id . $path_cache, $curl->response()->body); + Cache::set($this->id . $path_cache, $curl->response()->body, 24 * 60 * 60); } /** diff --git a/fuel/app/classes/model/server.php b/fuel/app/classes/model/server.php index 5b7be0f..2ac82cc 100755 --- a/fuel/app/classes/model/server.php +++ b/fuel/app/classes/model/server.php @@ -1,5 +1,7 @@ id . '.getThirtyLastedTvShows'); + + if ($getThirtyLastedTvShows) + return $getThirtyLastedTvShows; + + } catch (CacheNotFoundException $e) { + $curl = Request::forge(($this->https === '1' ? 'https' : 'http').'://' . $this->url . ($this->port ? ':' . $this->port : '') . '/hubs/home/recentlyAdded?type=2&X-Plex-Token=' . $this->token, 'curl'); if($this->https) { @@ -151,9 +160,11 @@ class Model_Server extends Model_Overwrite } } + Cache::set($this->id . '.getThirtyLastedTvShows', $tvshows, 6 * 60); + return $tvshows; - }catch (Exception $exception){ + } catch (Exception $exception){ Debug::dump($exception); } @@ -188,6 +199,14 @@ class Model_Server extends Model_Overwrite public function getThirtyLastedMovies() { try { + + $getThirtyLastedMovies = Cache::get($this->id . '.getThirtyLastedMovies'); + + if ($getThirtyLastedMovies) + return $getThirtyLastedMovies; + + } catch (CacheNotFoundException $e) { + $curl = Request::forge(($this->https === '1' ? 'https' : 'http').'://' . $this->url . ($this->port ? ':' . $this->port : '') . '/hubs/home/recentlyAdded?type=1&X-Plex-Token=' . $this->token, 'curl'); if($this->https) { @@ -212,9 +231,11 @@ class Model_Server extends Model_Overwrite $movies[] = Model_Movie::find_one_by('plex_key', $movie->key) ?: new Model_Movie(); } + Cache::set($this->id . '.getThirtyLastedMovies', $movies, 6 * 60); + return $movies; - }catch (Exception $exception){ + } catch (Exception $exception){ Debug::dump($exception); } //return Model_Movie::find(function ($query) use ($server) { diff --git a/fuel/app/classes/model/settings.php b/fuel/app/classes/model/settings.php deleted file mode 100644 index e56843c..0000000 --- a/fuel/app/classes/model/settings.php +++ /dev/null @@ -1,19 +0,0 @@ - 'required', - ); - protected static $_properties = array( - 'id', - 'user_id', - 'language', - 'trailer_type', - 'trailer', - 'subtitle', - 'maxdownloadspeed', - ); -} \ No newline at end of file diff --git a/fuel/app/classes/model/trailer.php b/fuel/app/classes/model/trailer.php index db3a730..383798e 100644 --- a/fuel/app/classes/model/trailer.php +++ b/fuel/app/classes/model/trailer.php @@ -1,5 +1,7 @@ response()->body; - $regex = '//i'; + $regex = '//i'; preg_match($regex, $media, $urls); + //Debug::dump($urls);die(); + if (!isset($urls[1])) return false; diff --git a/fuel/app/classes/model/tvshow.php b/fuel/app/classes/model/tvshow.php index 73c699e..514dc97 100644 --- a/fuel/app/classes/model/tvshow.php +++ b/fuel/app/classes/model/tvshow.php @@ -1,6 +1,7 @@ response()->status !== 200) return false; - Cache::set($this->id . $path_cache, $curl->response()->body); + Cache::set($this->id . $path_cache, $curl->response()->body, 24 * 60 * 60); } public function getMetaData() @@ -135,7 +136,7 @@ class Model_Tvshow extends Model_Overwrite //ROLES $this->metadata['Role'] = isset($array['Directory']['Role']) ? $array['Directory']['Role'] : null; - Cache::set($this->id . '.metadata', $this->metadata); + Cache::set($this->id . '.metadata', $this->metadata, 7 * 24 * 60 * 60); return $this->metadata; } } diff --git a/fuel/app/lang/en/permissions.php b/fuel/app/lang/en/permissions.php index 985e7e1..9e41d4c 100644 --- a/fuel/app/lang/en/permissions.php +++ b/fuel/app/lang/en/permissions.php @@ -1,14 +1,14 @@ 'Allow Watch', - 'RIGHT_WATCH_DESCRIPTION' => 'Allow use to watch movie/tv show.', - 'RIGHT_MAX_WATCH' => 'Max Play in 24H', - 'RIGHT_MAX_WATCH_DESCRIPTION' => 'Maximum number to play movie/tv show in 24H.', + 'RIGHT_WATCH_DISABLED' => 'Block Watch', + 'RIGHT_WATCH_DISABLED_DESCRIPTION' => 'Block user to watch movie/tv show.', + 'RIGHT_MAX_WATCH' => 'Max watch in 24H', + 'RIGHT_MAX_WATCH_DESCRIPTION' => 'Maximum number to watch movie/tv show in 24H by user.', 'RIGHT_MAX_QUALITY' => 'Stream Quality', 'RIGHT_MAX_QUALITY_DESCRIPTION' => 'The maximum quality to play a move/tv show.', - 'RIGHT_MAX_CONCURRENT_STREAM' => 'Concurrent stream ', - 'RIGHT_MAX_CONCURRENT_STREAM_DESCRIPTION' => 'Number of concurrent stream allowed.', - 'RIGHT_DOWNLOAD' => 'Allow Download', - 'RIGHT_DOWNLOAD_DESCRIPTION' => 'Give the permission at user to download movie/tv show.', + 'RIGHT_MAX_CONCURRENT_STREAM' => 'Concurrent stream', + 'RIGHT_MAX_CONCURRENT_STREAM_DESCRIPTION' => 'Number of concurrent stream allowed by user.', + 'RIGHT_DOWNLOAD_DISABLED' => 'Block Download', + 'RIGHT_DOWNLOAD_DISABLED_DESCRIPTION' => 'Remove the permission to a user to download movie/tv show.', 'RIGHT_MAX_DOWNLOAD' => 'Max Download', - 'RIGHT_MAX_DOWNLOAD_DESCRIPTION' => 'The maximum number of download allow to a use in 24H.', + 'RIGHT_MAX_DOWNLOAD_DESCRIPTION' => 'The maximum number of download allow to a user in 24H.', ]; \ No newline at end of file diff --git a/fuel/app/lang/en/settings.php b/fuel/app/lang/en/settings.php index c67cbc6..8950213 100644 --- a/fuel/app/lang/en/settings.php +++ b/fuel/app/lang/en/settings.php @@ -16,4 +16,5 @@ 'trailers_type' => 'Cinema Trailers Type', 'trailers_number' => 'Cinema Trailers to Play Before Movies', 'permissions' => 'Permissions', + 'last_update' => 'Last Update', ]; \ No newline at end of file diff --git a/fuel/app/views/episode/index.php b/fuel/app/views/episode/index.php index 7f85c48..752a686 100644 --- a/fuel/app/views/episode/index.php +++ b/fuel/app/views/episode/index.php @@ -357,7 +357,8 @@ }).done(function (view) { launchPlayer(view); }).fail(function (data) { - console.error(data); + console.error(data.responseText); + show_alert('error', data.responseText); }); }); $('.PosterCardImg-imageContainer-1Ar4M[data-movie-id]').each(function (index, element) { diff --git a/fuel/app/views/home/index.php b/fuel/app/views/home/index.php index 3aff2dc..87ed8e1 100755 --- a/fuel/app/views/home/index.php +++ b/fuel/app/views/home/index.php @@ -15,7 +15,9 @@ style="visibility: visible;">
- +
@@ -40,7 +42,7 @@ + ?>
@@ -68,16 +70,18 @@ role="link" class="MetadataPosterCardOverlay-link-1Swhl Link-link-2XYrU Link-default-32xSO"> - - + + + +
diff --git a/fuel/app/views/season/index.php b/fuel/app/views/season/index.php index 95b171e..7cf124f 100644 --- a/fuel/app/views/season/index.php +++ b/fuel/app/views/season/index.php @@ -196,8 +196,9 @@ dataType: 'html' }).done(function(view) { launchPlayer(view); - }).fail(function(data) { - console.error(data); + }).fail(function (data) { + console.error(data.responseText); + show_alert('error', data.responseText); }); }); }); diff --git a/fuel/app/views/settings/libraries.php b/fuel/app/views/settings/libraries.php index f8826df..6983a81 100644 --- a/fuel/app/views/settings/libraries.php +++ b/fuel/app/views/settings/libraries.php @@ -1,7 +1,9 @@
+ 0) : ?> \ No newline at end of file + + \ No newline at end of file diff --git a/fuel/app/views/settings/libraries/permissions.php b/fuel/app/views/settings/libraries/permissions.php index ed247f1..f76a54c 100644 --- a/fuel/app/views/settings/libraries/permissions.php +++ b/fuel/app/views/settings/libraries/permissions.php @@ -1,5 +1,6 @@
-
+
getServer()->name; ?> > name; ?>
+
By default a user can do everything without restriction. Use -1 to unlimited and 0 to block.
@@ -29,7 +30,7 @@ url: '/rest/library/permission', method: 'post', data: { - library_id: '', + library_id: 'id; ?>', right_name: $(this).data('name'), checked: $(this).is(':checked'), parameter: $('input[data-permission-name="' + $(this).data('name') + '"]').val() diff --git a/fuel/app/views/settings/servers.php b/fuel/app/views/settings/servers.php index e8d301f..ae944a3 100644 --- a/fuel/app/views/settings/servers.php +++ b/fuel/app/views/settings/servers.php @@ -2,7 +2,9 @@
+ 0) : ?> +
@@ -35,7 +37,9 @@

name; ?>

-
getLastCheck(); ?>
+
+ getLastCheck(); ?> +