| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432 |
- <?php
- trait SickRageHomepageItem
- {
- public function sickrageSettingsArray($infoOnly = false)
- {
- $homepageInformation = [
- 'name' => 'SickRage',
- 'enabled' => strpos('personal', $this->config['license']) !== false,
- 'image' => 'plugins/images/tabs/sickrage.png',
- 'category' => 'PVR',
- 'settingsArray' => __FUNCTION__
- ];
- if ($infoOnly) {
- return $homepageInformation;
- }
- $homepageSettings = [
- 'debug' => true,
- 'settings' => [
- 'Enable' => [
- $this->settingsOption('enable', 'homepageSickrageEnabled'),
- $this->settingsOption('auth', 'homepageSickrageAuth'),
- ],
- 'Connection' => [
- $this->settingsOption('url', 'sickrageURL'),
- $this->settingsOption('token', 'sickrageToken'),
- $this->settingsOption('disable-cert-check', 'sickrageDisableCertCheck'),
- $this->settingsOption('use-custom-certificate', 'sickrageUseCustomCertificate'),
- ],
- 'Calendar' => [
- $this->settingsOption('calendar-starting-day', 'calendarFirstDay'),
- $this->settingsOption('calendar-default-view', 'calendarDefault'),
- $this->settingsOption('calendar-time-format', 'calendarTimeFormat'),
- $this->settingsOption('calendar-locale', 'calendarLocale'),
- $this->settingsOption('calendar-limit', 'calendarLimit'),
- $this->settingsOption('refresh', 'calendarRefresh'),
- ],
- 'Test Connection' => [
- $this->settingsOption('blank', null, ['label' => 'Please Save before Testing']),
- $this->settingsOption('test', 'sickrage'),
- ]
- ]
- ];
- return array_merge($homepageInformation, $homepageSettings);
- }
- 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 {
- $options = $this->requestOptions($value['url'], null, $this->config['sickrageDisableCertCheck'], $this->config['sickrageUseCustomCertificate']);
- $downloader = new Kryptonit3\SickRage\SickRage($value['url'], $value['token'], null, null, $options);
- $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->setLoggerChannel('SickRage')->error($e);
- }
- }
- 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'
- ]
- ]
- ];
- return $this->homepageCheckKeyPermissions($key, $permissions);
- }
- 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 {
- $options = $this->requestOptions($value['url'], null, $this->config['sickrageDisableCertCheck'], $this->config['sickrageUseCustomCertificate']);
- $downloader = new Kryptonit3\SickRage\SickRage($value['url'], $value['token'], null, null, $options);
- $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->setLoggerChannel('SickRage')->error($e);
- }
- }
- $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 . 'data' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
- $cacheFile = $cacheDirectory . $seriesID . '.jpg';
- $fanart = "/plugins/images/homepage/no-np.png";
- if (file_exists($cacheFile)) {
- $fanart = 'data/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 . 'data' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
- $cacheFile = $cacheDirectory . $seriesID . '.jpg';
- $fanart = "/plugins/images/homepage/no-np.png";
- if (file_exists($cacheFile)) {
- $fanart = 'data/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 . 'data' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
- $cacheFile = $cacheDirectory . $seriesID . '.jpg';
- $fanart = "/plugins/images/homepage/no-np.png";
- if (file_exists($cacheFile)) {
- $fanart = 'data/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 . 'data' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
- $cacheFile = $cacheDirectory . $seriesID . '.jpg';
- $fanart = "/plugins/images/homepage/no-np.png";
- if (file_exists($cacheFile)) {
- $fanart = 'data/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 . 'data' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR;
- $cacheFile = $cacheDirectory . $seriesID . '.jpg';
- $fanart = "/plugins/images/homepage/no-np.png";
- if (file_exists($cacheFile)) {
- $fanart = 'data/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;
- }
- }
|