diff --git a/fuel/app/classes/model/library.php b/fuel/app/classes/model/library.php index ad2b28d..7d4f281 100644 --- a/fuel/app/classes/model/library.php +++ b/fuel/app/classes/model/library.php @@ -73,10 +73,13 @@ class Model_Library extends Model_Overwrite foreach ($list_libraries as $index => $library) { $library = !isset($list_libraries['@attributes']) ? $library : $list_libraries; - $libraries_id_array[] = ['id' => $library['@attributes']['uuid'], 'name' => $library['@attributes']['title']]; - $new_library = Model_Library::find_by_pk($library['@attributes']['uuid']) ?: Model_Library::forge(); + if(isset($new_library->disable) && $new_library->disable) + continue; + + $libraries_id_array[] = ['id' => $library['@attributes']['uuid'], 'name' => $library['@attributes']['title']]; + $new_library->set(array( 'id' => $library['@attributes']['uuid'], 'plex_key' => $library['@attributes']['key'], diff --git a/fuel/app/classes/model/movie.php b/fuel/app/classes/model/movie.php index dbd98f4..cb5239f 100644 --- a/fuel/app/classes/model/movie.php +++ b/fuel/app/classes/model/movie.php @@ -1,5 +1,7 @@ _server) - $this->getServer(); - - $curl = Request::forge('http://' . $this->_server->url . ($this->_server->port ? ':' . $this->_server->port : '') . '/video/:/transcode/universal/start?identifier=[PlexShare]&path=http%3A%2F%2F127.0.0.1%3A32400' . urlencode($this->plex_key) . '&mediaIndex=0&partIndex=0&protocol=hls&offset=0&fastSeek=1&directStream=0&directPlay=1&videoQuality=100&maxVideoBitrate=2294&subtitleSize=100&audioBoost=100&X-Plex-Platform=Chrome&X-Plex-Token=' . $this->_server->token, 'curl'); - //$curl = Request::forge('http://' . $this->_server->url . ($this->_server->port ? ':' . $this->_server->port : '') . '/video/:/transcode/universal/start?identifier=[PlexShare]&path=http%3A%2F%2F127.0.0.1%3A32400' . urlencode($this->plex_key) . '&mediaIndex=0&partIndex=0&protocol=hls&offset=0&fastSeek=1&directStream=0&directPlay=1&videoQuality=100&videoResolution=576x320&maxVideoBitrate=2294&subtitleSize=100&audioBoost=100&X-Plex-Platform=Chrome&X-Plex-Token=' . $this->_server->token, 'curl'); + try { + if (!$this->_server) + $this->getServer(); - $curl->execute(); + $curl = Request::forge('http://' . $this->_server->url . ($this->_server->port ? ':' . $this->_server->port : '') . '/video/:/transcode/universal/start?identifier=[PlexShare]&path=http%3A%2F%2F127.0.0.1%3A32400' . urlencode($this->plex_key) . '&mediaIndex=0&partIndex=0&protocol=hls&offset=0&fastSeek=1&directStream=0&directPlay=1&videoQuality=100&maxVideoBitrate=2294&subtitleSize=100&audioBoost=100&X-Plex-Platform=Chrome&X-Plex-Token=' . $this->_server->token, 'curl'); + //$curl = Request::forge('http://' . $this->_server->url . ($this->_server->port ? ':' . $this->_server->port : '') . '/video/:/transcode/universal/start?identifier=[PlexShare]&path=http%3A%2F%2F127.0.0.1%3A32400' . urlencode($this->plex_key) . '&mediaIndex=0&partIndex=0&protocol=hls&offset=0&fastSeek=1&directStream=0&directPlay=1&videoQuality=100&videoResolution=576x320&maxVideoBitrate=2294&subtitleSize=100&audioBoost=100&X-Plex-Platform=Chrome&X-Plex-Token=' . $this->_server->token, 'curl'); + $curl->execute(); - if ($curl->response()->status !== 200) - throw new FuelException('No session found!'); + if ($curl->response()->status !== 200) + throw new FuelException('No session found!'); - preg_match('/session\/[a-z0-9\-]+\/base\/index\.m3u8/', $curl->response()->body,$matches); + preg_match('/session\/[a-z0-9\-]+\/base\/index\.m3u8/', $curl->response()->body, $matches); - if(count($matches) <= 0) - throw new FuelException('No session found!'); + if (count($matches) <= 0) + throw new FuelException('No session found!'); - $split = preg_split('/\//', $matches[0]); + $split = preg_split('/\//', $matches[0]); - if(count($split) <= 0) - throw new FuelException('No session found!'); + if (count($split) <= 0) + throw new FuelException('No session found!'); - $this->_session = $split[1]; + $this->_session = $split[1]; - return 'http://' . $this->_server->url . ($this->_server->port ? ':' . $this->_server->port : '') . '/video/:/transcode/universal/session/' . $this->_session . '/base/index.m3u8'; + return 'http://' . $this->_server->url . ($this->_server->port ? ':' . $this->_server->port : '') . '/video/:/transcode/universal/session/' . $this->_session . '/base/index.m3u8'; + }catch (Exception $exception) { + throw new FuelException('TOKEN MAYBE OUTDATED',$exception->getCode()); + } } /** @@ -328,10 +333,12 @@ class Model_Movie extends Model_Overwrite public static function getThirtyLastedTvShows($server) { - return self::find(function ($query) use ($server) { + $conf = Config::get('db'); + + return self::find(function ($query) use ($server, $conf) { /** @var Database_Query_Builder_Select $query */ return $query - ->select('movie.*') + ->select('movie.*', DB::expr('COUNT(' . $conf['default']['table_prefix'] . 'movie.type) AS count')) ->join('season', 'LEFT') ->on('movie.season_id', '=', 'season.id') ->join('tvshow', 'LEFT') @@ -343,6 +350,8 @@ 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') + ->group_by('movie.season_id') ->limit(30) ; }); diff --git a/fuel/app/classes/model/server.php b/fuel/app/classes/model/server.php index e54741a..af00de3 100755 --- a/fuel/app/classes/model/server.php +++ b/fuel/app/classes/model/server.php @@ -57,6 +57,9 @@ class Model_Server extends Model_Overwrite foreach ($servers as $server) { + if($server->disable) + continue; + $curl = Request::forge('http://' . $server->url . ($server->port? ':' . $server->port : '') . '/?X-Plex-Token=' . $server->token, 'curl'); $curl->execute();