| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496 |
- <?php
- trait SickRageHomepageItem
- {
- public function sickrageSettingsArray()
- {
- return array(
- 'name' => 'SickRage',
- 'enabled' => strpos('personal', $this->config['license']) !== false,
- 'image' => 'plugins/images/tabs/sickrage.png',
- 'category' => 'PVR',
- 'settings' => array(
- 'Enable' => array(
- array(
- 'type' => 'switch',
- 'name' => 'homepageSickrageEnabled',
- 'label' => 'Enable',
- 'value' => $this->config['homepageSickrageEnabled']
- ),
- array(
- 'type' => 'select',
- 'name' => 'homepageSickrageAuth',
- 'label' => 'Minimum Authentication',
- 'value' => $this->config['homepageSickrageAuth'],
- 'options' => $this->groupOptions
- )
- ),
- 'Connection' => array(
- array(
- 'type' => 'input',
- 'name' => 'sickrageURL',
- 'label' => 'URL',
- 'value' => $this->config['sickrageURL'],
- 'help' => 'Please make sure to use local IP address and port - You also may use local dns name too.',
- 'placeholder' => 'http(s)://hostname:port'
- ),
- array(
- 'type' => 'password-alt',
- 'name' => 'sickrageToken',
- 'label' => 'Token',
- 'value' => $this->config['sickrageToken']
- )
- ),
- 'Misc Options' => array(
- array(
- 'type' => 'select',
- 'name' => 'calendarFirstDay',
- 'label' => 'Start Day',
- 'value' => $this->config['calendarFirstDay'],
- 'options' => $this->daysOptions()
- ),
- array(
- 'type' => 'select',
- 'name' => 'calendarDefault',
- 'label' => 'Default View',
- 'value' => $this->config['calendarDefault'],
- 'options' => $this->calendarDefaultOptions()
- ),
- array(
- 'type' => 'select',
- 'name' => 'calendarTimeFormat',
- 'label' => 'Time Format',
- 'value' => $this->config['calendarTimeFormat'],
- 'options' => $this->timeFormatOptions()
- ),
- array(
- 'type' => 'select',
- 'name' => 'calendarLocale',
- 'label' => 'Locale',
- 'value' => $this->config['calendarLocale'],
- 'options' => $this->calendarLocaleOptions()
- ),
- array(
- 'type' => 'select',
- 'name' => 'calendarLimit',
- 'label' => 'Items Per Day',
- 'value' => $this->config['calendarLimit'],
- 'options' => $this->limitOptions()
- ),
- array(
- 'type' => 'select',
- 'name' => 'calendarRefresh',
- 'label' => 'Refresh Seconds',
- 'value' => $this->config['calendarRefresh'],
- 'options' => $this->timeOptions()
- )
- ),
- 'Test Connection' => array(
- array(
- 'type' => 'blank',
- 'label' => 'Please Save before Testing'
- ),
- array(
- 'type' => 'button',
- 'label' => '',
- 'icon' => 'fa fa-flask',
- 'class' => 'pull-right',
- 'text' => 'Test Connection',
- 'attr' => 'onclick="testAPIConnection(\'sickrage\')"'
- ),
- )
- )
- );
- }
-
- public function testConnectionSickRage()
- {
- if (empty($this->config['sickrageURL'])) {
- $this->setAPIResponse('error', 'SickRage URL is not defined', 422);
- return false;
- }
- if (empty($this->config['sickrageToken'])) {
- $this->setAPIResponse('error', 'SickRage Token is not defined', 422);
- return false;
- }
- $failed = false;
- $errors = '';
- $list = $this->csvHomepageUrlToken($this->config['sickrageURL'], $this->config['sickrageToken']);
- foreach ($list as $key => $value) {
- try {
- $downloader = new Kryptonit3\SickRage\SickRage($value['url'], $value['token']);
- $results = $downloader->sb();
- $downloadList = json_decode($results, true);
- if (is_array($downloadList) || is_object($downloadList)) {
- $queue = (array_key_exists('error', $downloadList)) ? $downloadList['error']['msg'] : $downloadList;
- if (!is_array($queue)) {
- $ip = $value['url'];
- $errors .= $ip . ': ' . $queue;
- $failed = true;
- }
- } else {
- $ip = $value['url'];
- $errors .= $ip . ': Response was not JSON';
- $failed = true;
- }
-
- } catch (Exception $e) {
- $failed = true;
- $ip = $value['url'];
- $errors .= $ip . ': ' . $e->getMessage();
- $this->writeLog('error', 'SickRage Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
- }
- }
- if ($failed) {
- $this->setAPIResponse('error', $errors, 500);
- return false;
- } else {
- $this->setAPIResponse('success', null, 200);
- return true;
- }
- }
-
- public function sickrageHomepagePermissions($key = null)
- {
- $permissions = [
- 'calendar' => [
- 'enabled' => [
- 'homepageSickrageEnabled'
- ],
- 'auth' => [
- 'homepageSickrageAuth'
- ],
- 'not_empty' => [
- 'sickrageURL',
- 'sickrageToken'
- ]
- ]
- ];
- if (array_key_exists($key, $permissions)) {
- return $permissions[$key];
- } elseif ($key == 'all') {
- return $permissions;
- } else {
- return [];
- }
- }
-
- public function getSickRageCalendar($startDate = null, $endDate = null)
- {
- if (!$this->homepageItemPermissions($this->sickrageHomepagePermissions('calendar'), true)) {
- return false;
- }
- $calendarItems = array();
- $list = $this->csvHomepageUrlToken($this->config['sickrageURL'], $this->config['sickrageToken']);
- foreach ($list as $key => $value) {
- try {
- $downloader = new Kryptonit3\SickRage\SickRage($value['url'], $value['token']);
- $sickrageFuture = $this->formatSickrageCalendarWanted($downloader->future(), $key);
- $sickrageHistory = $this->formatSickrageCalendarHistory($downloader->history("100", "downloaded"), $key);
- if (!empty($sickrageFuture)) {
- $calendarItems = array_merge($calendarItems, $sickrageFuture);
- }
- if (!empty($sickrageHistory)) {
- $calendarItems = array_merge($calendarItems, $sickrageHistory);
- }
- } catch (Exception $e) {
- $this->writeLog('error', 'SickRage Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
- }
- }
- $this->setAPIResponse('success', null, 200, $calendarItems);
- return $calendarItems;
- }
-
- public function formatSickrageCalendarWanted($array, $number)
- {
- $array = json_decode($array, true);
- $gotCalendar = array();
- $i = 0;
- foreach ($array['data']['missed'] as $child) {
- $i++;
- $seriesName = $child['show_name'];
- $seriesID = $child['tvdbid'];
- $episodeID = $child['tvdbid'];
- $episodeAirDate = $child['airdate'];
- $episodeAirDateTime = explode(" ", $child['airs']);
- $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1] . $episodeAirDateTime[2]));
- $episodeAirDate = strtotime($episodeAirDate . $episodeAirDateTime);
- $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
- if (new DateTime() < new DateTime($episodeAirDate)) {
- $unaired = true;
- }
- $downloaded = "0";
- if ($downloaded == "0" && isset($unaired)) {
- $downloaded = "text-info";
- } elseif ($downloaded == "1") {
- $downloaded = "text-success";
- } else {
- $downloaded = "text-danger";
- }
- $bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']) . ' - ' . $child['ep_name'];
- $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
- $cacheFile = $cacheDirectory . $seriesID . '.jpg';
- $fanart = "/plugins/images/cache/no-np.png";
- if (file_exists($cacheFile)) {
- $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
- unset($cacheFile);
- }
- $details = array(
- "seasonCount" => "",
- "status" => $child['show_status'],
- "topTitle" => $seriesName,
- "bottomTitle" => $bottomTitle,
- "overview" => isset($child['ep_plot']) ? $child['ep_plot'] : '',
- "runtime" => "",
- "image" => $fanart,
- "ratings" => "",
- "videoQuality" => isset($child["quality"]) ? $child["quality"] : "",
- "audioChannels" => "",
- "audioCodec" => "",
- "videoCodec" => "",
- "size" => "",
- "genres" => "",
- );
- array_push($gotCalendar, array(
- "id" => "Sick-" . $number . "-Miss-" . $i,
- "title" => $seriesName,
- "start" => $episodeAirDate,
- "className" => "inline-popups bg-calendar calendar-item tvID--" . $episodeID,
- "imagetype" => "tv " . $downloaded,
- "imagetypeFilter" => "tv",
- "downloadFilter" => $downloaded,
- "bgColor" => str_replace('text', 'bg', $downloaded),
- "details" => $details,
- ));
- }
- foreach ($array['data']['today'] as $child) {
- $i++;
- $seriesName = $child['show_name'];
- $seriesID = $child['tvdbid'];
- $episodeID = $child['tvdbid'];
- $episodeAirDate = $child['airdate'];
- $episodeAirDateTime = explode(" ", $child['airs']);
- $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1] . $episodeAirDateTime[2]));
- $episodeAirDate = strtotime($episodeAirDate . $episodeAirDateTime);
- $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
- if (new DateTime() < new DateTime($episodeAirDate)) {
- $unaired = true;
- }
- $downloaded = "0";
- if ($downloaded == "0" && isset($unaired)) {
- $downloaded = "text-info";
- } elseif ($downloaded == "1") {
- $downloaded = "text-success";
- } else {
- $downloaded = "text-danger";
- }
- $bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']) . ' - ' . $child['ep_name'];
- $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
- $cacheFile = $cacheDirectory . $seriesID . '.jpg';
- $fanart = "/plugins/images/cache/no-np.png";
- if (file_exists($cacheFile)) {
- $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
- unset($cacheFile);
- }
- $details = array(
- "seasonCount" => "",
- "status" => $child['show_status'],
- "topTitle" => $seriesName,
- "bottomTitle" => $bottomTitle,
- "overview" => isset($child['ep_plot']) ? $child['ep_plot'] : '',
- "runtime" => "",
- "image" => $fanart,
- "ratings" => "",
- "videoQuality" => isset($child["quality"]) ? $child["quality"] : "",
- "audioChannels" => "",
- "audioCodec" => "",
- "videoCodec" => "",
- "size" => "",
- "genres" => "",
- );
- array_push($gotCalendar, array(
- "id" => "Sick-" . $number . "-Today-" . $i,
- "title" => $seriesName,
- "start" => $episodeAirDate,
- "className" => "inline-popups bg-calendar calendar-item tvID--" . $episodeID,
- "imagetype" => "tv " . $downloaded,
- "imagetypeFilter" => "tv",
- "downloadFilter" => $downloaded,
- "bgColor" => str_replace('text', 'bg', $downloaded),
- "details" => $details,
- ));
- }
- foreach ($array['data']['soon'] as $child) {
- $i++;
- $seriesName = $child['show_name'];
- $seriesID = $child['tvdbid'];
- $episodeID = $child['tvdbid'];
- $episodeAirDate = $child['airdate'];
- $episodeAirDateTime = explode(" ", $child['airs']);
- $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1] . $episodeAirDateTime[2]));
- $episodeAirDate = strtotime($episodeAirDate . $episodeAirDateTime);
- $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
- if (new DateTime() < new DateTime($episodeAirDate)) {
- $unaired = true;
- }
- $downloaded = "0";
- if ($downloaded == "0" && isset($unaired)) {
- $downloaded = "text-info";
- } elseif ($downloaded == "1") {
- $downloaded = "text-success";
- } else {
- $downloaded = "text-danger";
- }
- $bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']) . ' - ' . $child['ep_name'];
- $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
- $cacheFile = $cacheDirectory . $seriesID . '.jpg';
- $fanart = "/plugins/images/cache/no-np.png";
- if (file_exists($cacheFile)) {
- $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
- unset($cacheFile);
- }
- $details = array(
- "seasonCount" => "",
- "status" => $child['show_status'],
- "topTitle" => $seriesName,
- "bottomTitle" => $bottomTitle,
- "overview" => isset($child['ep_plot']) ? $child['ep_plot'] : '',
- "runtime" => "",
- "image" => $fanart,
- "ratings" => "",
- "videoQuality" => isset($child["quality"]) ? $child["quality"] : "",
- "audioChannels" => "",
- "audioCodec" => "",
- "videoCodec" => "",
- "size" => "",
- "genres" => "",
- );
- array_push($gotCalendar, array(
- "id" => "Sick-" . $number . "-Soon-" . $i,
- "title" => $seriesName,
- "start" => $episodeAirDate,
- "className" => "inline-popups bg-calendar calendar-item tvID--" . $episodeID,
- "imagetype" => "tv " . $downloaded,
- "imagetypeFilter" => "tv",
- "downloadFilter" => $downloaded,
- "bgColor" => str_replace('text', 'bg', $downloaded),
- "details" => $details,
- ));
- }
- foreach ($array['data']['later'] as $child) {
- $i++;
- $seriesName = $child['show_name'];
- $seriesID = $child['tvdbid'];
- $episodeID = $child['tvdbid'];
- $episodeAirDate = $child['airdate'];
- $episodeAirDateTime = explode(" ", $child['airs']);
- $episodeAirDateTime = date("H:i:s", strtotime($episodeAirDateTime[1] . $episodeAirDateTime[2]));
- $episodeAirDate = strtotime($episodeAirDate . $episodeAirDateTime);
- $episodeAirDate = date("Y-m-d H:i:s", $episodeAirDate);
- if (new DateTime() < new DateTime($episodeAirDate)) {
- $unaired = true;
- }
- $downloaded = "0";
- if ($downloaded == "0" && isset($unaired)) {
- $downloaded = "text-info";
- } elseif ($downloaded == "1") {
- $downloaded = "text-success";
- } else {
- $downloaded = "text-danger";
- }
- $bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']) . ' - ' . $child['ep_name'];
- $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
- $cacheFile = $cacheDirectory . $seriesID . '.jpg';
- $fanart = "/plugins/images/cache/no-np.png";
- if (file_exists($cacheFile)) {
- $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
- unset($cacheFile);
- }
- $details = array(
- "seasonCount" => "",
- "status" => $child['show_status'],
- "topTitle" => $seriesName,
- "bottomTitle" => $bottomTitle,
- "overview" => isset($child['ep_plot']) ? $child['ep_plot'] : '',
- "runtime" => "",
- "image" => $fanart,
- "ratings" => "",
- "videoQuality" => isset($child["quality"]) ? $child["quality"] : "",
- "audioChannels" => "",
- "audioCodec" => "",
- "videoCodec" => "",
- "size" => "",
- "genres" => "",
- );
- array_push($gotCalendar, array(
- "id" => "Sick-" . $number . "-Later-" . $i,
- "title" => $seriesName,
- "start" => $episodeAirDate,
- "className" => "inline-popups bg-calendar calendar-item tvID--" . $episodeID,
- "imagetype" => "tv " . $downloaded,
- "imagetypeFilter" => "tv",
- "downloadFilter" => $downloaded,
- "bgColor" => str_replace('text', 'bg', $downloaded),
- "details" => $details,
- ));
- }
- if ($i != 0) {
- return $gotCalendar;
- }
- return false;
- }
-
- public function formatSickrageCalendarHistory($array, $number)
- {
- $array = json_decode($array, true);
- $gotCalendar = array();
- $i = 0;
- foreach ($array['data'] as $child) {
- $i++;
- $seriesName = $child['show_name'];
- $seriesID = $child['tvdbid'];
- $episodeID = $child['tvdbid'];
- $episodeAirDate = $child['date'];
- $downloaded = "text-success";
- $bottomTitle = 'S' . sprintf("%02d", $child['season']) . 'E' . sprintf("%02d", $child['episode']);
- $cacheDirectory = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
- $cacheFile = $cacheDirectory . $seriesID . '.jpg';
- $fanart = "/plugins/images/cache/no-np.png";
- if (file_exists($cacheFile)) {
- $fanart = 'plugins/images/cache/' . $seriesID . '.jpg';
- unset($cacheFile);
- }
- $details = array(
- "seasonCount" => "",
- "status" => $child['status'],
- "topTitle" => $seriesName,
- "bottomTitle" => $bottomTitle,
- "overview" => '',
- "runtime" => isset($child['series']['runtime']) ? $child['series']['runtime'] : 30,
- "image" => $fanart,
- "ratings" => isset($child['series']['ratings']['value']) ? $child['series']['ratings']['value'] : "unknown",
- "videoQuality" => isset($child["quality"]) ? $child['quality'] : "unknown",
- "audioChannels" => "",
- "audioCodec" => "",
- "videoCodec" => "",
- "size" => "",
- "genres" => "",
- );
- array_push($gotCalendar, array(
- "id" => "Sick-" . $number . "-History-" . $i,
- "title" => $seriesName,
- "start" => $episodeAirDate,
- "className" => "inline-popups bg-calendar calendar-item tvID--" . $episodeID,
- "imagetype" => "tv " . $downloaded,
- "imagetypeFilter" => "tv",
- "downloadFilter" => $downloaded,
- "bgColor" => str_replace('text', 'bg', $downloaded),
- "details" => $details,
- ));
- }
- if ($i != 0) {
- return $gotCalendar;
- }
- return false;
- }
- }
|