Răsfoiți Sursa

Merge pull request #814 from rob1998/v2-develop

Details for Sonarr calendar items
causefx 8 ani în urmă
părinte
comite
9caacbfef6
1 a modificat fișierele cu 290 adăugiri și 229 ștergeri
  1. 290 229
      api/functions/homepage-connect-functions.php

+ 290 - 229
api/functions/homepage-connect-functions.php

@@ -1,16 +1,16 @@
 <?php
 
 function homepageConnect($array){
-	switch ($array['data']['action']) {
+    switch ($array['data']['action']) {
         case 'getPlexStreams':
-			return plexConnect('streams');
+            return plexConnect('streams');
             break;
-		case 'getPlexRecent':
+        case 'getPlexRecent':
             return plexConnect('recent');
-			break;
+            break;
         case 'getPlexMetadata':
             return plexConnect('metadata',$array['data']['key']);
-			break;
+            break;
         case 'getEmbyStreams':
             return embyConnect('streams');
             break;
@@ -32,9 +32,9 @@ function homepageConnect($array){
         case 'getqBittorrent':
             return qBittorrentConnect();
             break;
-		case 'getDeluge':
-			return delugeConnect();
-			break;
+        case 'getDeluge':
+            return delugeConnect();
+            break;
         case 'getCalendar':
             return getCalendar();
             break;
@@ -75,7 +75,7 @@ function resolveEmbyItem($itemDetails) {
     $nowPlayingWidth = 1200;
     $actorHeight = 450;
     $actorWidth = 300;
-	$widthOverride = 100;
+    $widthOverride = 100;
     // Cache Directories
     $cacheDirectory = dirname(__DIR__,2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR;
     $cacheDirectoryWeb = 'plugins/images/cache/';
@@ -84,7 +84,7 @@ function resolveEmbyItem($itemDetails) {
     $embyItem['array-itemdetails'] = $itemDetails;
 
     switch (@$item['Type']) {
-    	case 'Series':
+        case 'Series':
             $embyItem['type'] = 'tv';
             $embyItem['title'] = $item['Name'];
             $embyItem['summary'] = '';
@@ -155,7 +155,7 @@ function resolveEmbyItem($itemDetails) {
             break;
         default:
             return false;
-	}
+    }
     $embyItem['uid'] = $item['Id'];
     $embyItem['imageType'] = (isset($item['ImageTags']['Primary']) ? "Primary" : false);
     $embyItem['elapsed'] = isset($itemDetails['PlayState']['PositionTicks']) && $itemDetails['PlayState']['PositionTicks'] !== '0' ? (int)$itemDetails['PlayState']['PositionTicks'] : null;
@@ -242,7 +242,7 @@ function resolveEmbyItem($itemDetails) {
     }
     if(!$embyItem['nowPlayingThumb'] ){ $embyItem['nowPlayingOriginalImage']  = $embyItem['nowPlayingImageURL']  = "plugins/images/cache/no-np.png"; $embyItem['nowPlayingKey'] = "no-np"; }
     if(!$embyItem['thumb'] ){  $embyItem['originalImage'] = $embyItem['imageURL'] = "plugins/images/cache/no-list.png"; $embyItem['key'] = "no-list"; }
-	if(isset($useImage)){ $embyItem['useImage'] = $useImage; }
+    if(isset($useImage)){ $embyItem['useImage'] = $useImage; }
     return $embyItem;
 }
 function resolvePlexItem($item) {
@@ -251,13 +251,13 @@ function resolvePlexItem($item) {
     $width = 200;
     $nowPlayingHeight = 675;
     $nowPlayingWidth = 1200;
-	$widthOverride = 100;
+    $widthOverride = 100;
     // Cache Directories
     $cacheDirectory = dirname(__DIR__,2).DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'images'.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR;
     $cacheDirectoryWeb = 'plugins/images/cache/';
     // Types
     switch ($item['type']) {
-    	case 'season':
+        case 'season':
             $plexItem['type'] = 'tv';
             $plexItem['title'] = (string)$item['parentTitle'];
             $plexItem['summary'] = (string)$item['parentSummary'];
@@ -299,10 +299,10 @@ function resolvePlexItem($item) {
             $plexItem['type'] = 'music';
             $plexItem['title'] = (string)$item['parentTitle'];
             $plexItem['summary'] = (string)$item['title'];
-			$plexItem['ratingKey'] = (string)$item['parentRatingKey'];
+            $plexItem['ratingKey'] = (string)$item['parentRatingKey'];
             $plexItem['thumb'] = (string)$item['thumb'];
             $plexItem['key'] = (string)$item['ratingKey'] . "-list";
-			$plexItem['nowPlayingThumb'] = ($item['parentThumb']) ? (string)$item['parentThumb'] :  (string)$item['art'];
+            $plexItem['nowPlayingThumb'] = ($item['parentThumb']) ? (string)$item['parentThumb'] :  (string)$item['art'];
             $plexItem['nowPlayingKey'] = (string)$item['parentRatingKey'] . "-np";
             $plexItem['nowPlayingTitle'] = (string)$item['grandparentTitle'].' - '.(string)$item['title'];
             $plexItem['nowPlayingBottom'] = (string)$item['parentTitle'];
@@ -320,7 +320,7 @@ function resolvePlexItem($item) {
             $plexItem['nowPlayingTitle'] = (string)$item['title'];
             $plexItem['nowPlayingBottom'] = (string)$item['year'];
             $plexItem['metadataKey'] = (string)$item['ratingKey'];
-	}
+    }
     $plexItem['uid'] = (string)$item['ratingKey'];
     $plexItem['elapsed'] = isset($item['viewOffset']) && $item['viewOffset'] !== '0' ? (int)$item['viewOffset'] : null;
     $plexItem['duration'] = isset($item['duration']) ? (int)$item['duration'] : (int)$item->Media['duration'];
@@ -401,11 +401,11 @@ function resolvePlexItem($item) {
     }
     if(!$plexItem['nowPlayingThumb'] ){ $plexItem['nowPlayingOriginalImage']  = $plexItem['nowPlayingImageURL']  = "plugins/images/cache/no-np.png"; $plexItem['nowPlayingKey'] = "no-np"; }
     if(!$plexItem['thumb'] ){  $plexItem['originalImage'] = $plexItem['imageURL'] = "plugins/images/cache/no-list.png"; $plexItem['key'] = "no-list"; }
-	if(isset($useImage)){ $plexItem['useImage'] = $useImage; }
+    if(isset($useImage)){ $plexItem['useImage'] = $useImage; }
     return $plexItem;
 }
 function plexConnect($action,$key=null){
-	if($GLOBALS['homepagePlexEnabled'] && !empty($GLOBALS['plexURL']) && !empty($GLOBALS['plexToken']) && !empty($GLOBALS['plexID'] && qualifyRequest($GLOBALS['homepagePlexAuth']))){
+    if($GLOBALS['homepagePlexEnabled'] && !empty($GLOBALS['plexURL']) && !empty($GLOBALS['plexToken']) && !empty($GLOBALS['plexID'] && qualifyRequest($GLOBALS['homepagePlexAuth']))){
         $url = qualifyURL($GLOBALS['plexURL']);
         switch ($action) {
             case 'streams':
@@ -421,30 +421,30 @@ function plexConnect($action,$key=null){
                 # code...
                 break;
         }
-		try{
-			$options = (localURL($url)) ? array('verify' => false ) : array();
-			$response = Requests::get($url, array(), $options);
-			libxml_use_internal_errors(true);
-			if($response->success){
-				$items = array();
-				$plex = simplexml_load_string($response->body);
-				foreach($plex AS $child) {
-					$items[] = resolvePlexItem($child);
-				}
-				$api['content'] = $items;
-				$api['plexID'] = $GLOBALS['plexID'];
-				$api['showNames'] = true;
-				$api['group'] = '1';
-				return $api;
-			}
-		}catch( Requests_Exception $e ) {
-			writeLog('error', 'Plex Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
-		};
-	}
-	return false;
+        try{
+            $options = (localURL($url)) ? array('verify' => false ) : array();
+            $response = Requests::get($url, array(), $options);
+            libxml_use_internal_errors(true);
+            if($response->success){
+                $items = array();
+                $plex = simplexml_load_string($response->body);
+                foreach($plex AS $child) {
+                    $items[] = resolvePlexItem($child);
+                }
+                $api['content'] = $items;
+                $api['plexID'] = $GLOBALS['plexID'];
+                $api['showNames'] = true;
+                $api['group'] = '1';
+                return $api;
+            }
+        }catch( Requests_Exception $e ) {
+            writeLog('error', 'Plex Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
+        };
+    }
+    return false;
 }
 function embyConnect($action,$key=null,$skip=false){
-	if($GLOBALS['homepageEmbyEnabled'] && !empty($GLOBALS['embyURL']) && !empty($GLOBALS['embyToken']) && qualifyRequest($GLOBALS['homepageEmbyAuth'])){
+    if($GLOBALS['homepageEmbyEnabled'] && !empty($GLOBALS['embyURL']) && !empty($GLOBALS['embyToken']) && qualifyRequest($GLOBALS['homepageEmbyAuth'])){
         $url = qualifyURL($GLOBALS['embyURL']);
         switch ($action) {
             case 'streams':
@@ -459,10 +459,10 @@ function embyConnect($action,$key=null,$skip=false){
                 $userIds = $url."/Users?api_key=".$GLOBALS['embyToken'];
                 $showPlayed = true;
                 try{
-        			$options = (localURL($userIds)) ? array('verify' => false ) : array();
-        			$response = Requests::get($userIds, array(), $options);
-        			if($response->success){
-        				$emby = json_decode($response->body, true);
+                    $options = (localURL($userIds)) ? array('verify' => false ) : array();
+                    $response = Requests::get($userIds, array(), $options);
+                    if($response->success){
+                        $emby = json_decode($response->body, true);
                         foreach ($emby as $value) { // Scan for admin user
                             if (isset($value['Policy']) && isset($value['Policy']['IsAdministrator']) && $value['Policy']['IsAdministrator']) {
                                 $userId = $value['Id'];
@@ -473,10 +473,10 @@ function embyConnect($action,$key=null,$skip=false){
                                 break;
                             }
                         }
-        			}
-        		}catch( Requests_Exception $e ) {
-        			writeLog('error', 'Emby Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
-        		};
+                    }
+                }catch( Requests_Exception $e ) {
+                    writeLog('error', 'Emby Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
+                };
                 $url = $url.'/Users/'.$userId.'/Items/Latest?EnableImages=false&Limit=100&api_key='.$GLOBALS['embyToken'].($showPlayed?'':'&IsPlayed=false');
                 break;
             case 'metadata':
@@ -491,50 +491,50 @@ function embyConnect($action,$key=null,$skip=false){
             $api['content'] = $items;
             return $api;
         }
-		try{
-			$options = (localURL($url)) ? array('verify' => false ) : array();
-			$response = Requests::get($url, array(), $options);
-			if($response->success){
-				$items = array();
-				$emby = json_decode($response->body, true);
-				foreach($emby AS $child) {
+        try{
+            $options = (localURL($url)) ? array('verify' => false ) : array();
+            $response = Requests::get($url, array(), $options);
+            if($response->success){
+                $items = array();
+                $emby = json_decode($response->body, true);
+                foreach($emby AS $child) {
                     if (isset($child['NowPlayingItem']) || isset($child['Name'])) {
                         $items[] = resolveEmbyItem($child);
                     }
-				}
-				$api['content'] = array_filter($items);
-				return $api;
-			}
-		}catch( Requests_Exception $e ) {
-			writeLog('error', 'Emby Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
-		};
-	}
-	return false;
+                }
+                $api['content'] = array_filter($items);
+                return $api;
+            }
+        }catch( Requests_Exception $e ) {
+            writeLog('error', 'Emby Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
+        };
+    }
+    return false;
 }
 function sabnzbdConnect() {
     if($GLOBALS['homepageSabnzbdEnabled'] && !empty($GLOBALS['sabnzbdURL']) && !empty($GLOBALS['sabnzbdToken']) && qualifyRequest($GLOBALS['homepageSabnzbdAuth'])){
         $url = qualifyURL($GLOBALS['sabnzbdURL']);
         $url = $url.'/api?mode=queue&output=json&apikey='.$GLOBALS['sabnzbdToken'];
         try{
-			$options = (localURL($url)) ? array('verify' => false ) : array();
-			$response = Requests::get($url, array(), $options);
-			if($response->success){
-				$api['content']['queueItems'] = json_decode($response->body, true);
-			}
-		}catch( Requests_Exception $e ) {
-			writeLog('error', 'SabNZBd Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
-		};
+            $options = (localURL($url)) ? array('verify' => false ) : array();
+            $response = Requests::get($url, array(), $options);
+            if($response->success){
+                $api['content']['queueItems'] = json_decode($response->body, true);
+            }
+        }catch( Requests_Exception $e ) {
+            writeLog('error', 'SabNZBd Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
+        };
         $url = qualifyURL($GLOBALS['sabnzbdURL']);
         $url = $url.'/api?mode=history&output=json&apikey='.$GLOBALS['sabnzbdToken'];
         try{
-			$options = (localURL($url)) ? array('verify' => false ) : array();
-			$response = Requests::get($url, array(), $options);
-			if($response->success){
-				$api['content']['historyItems']= json_decode($response->body, true);
-			}
-		}catch( Requests_Exception $e ) {
-			writeLog('error', 'SabNZBd Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
-		};
+            $options = (localURL($url)) ? array('verify' => false ) : array();
+            $response = Requests::get($url, array(), $options);
+            if($response->success){
+                $api['content']['historyItems']= json_decode($response->body, true);
+            }
+        }catch( Requests_Exception $e ) {
+            writeLog('error', 'SabNZBd Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
+        };
         $api['content'] = isset($api['content']) ? $api['content'] : false;
         return $api;
     }
@@ -544,25 +544,25 @@ function nzbgetConnect() {
         $url = qualifyURL($GLOBALS['nzbgetURL']);
         $url = $url.'/'.$GLOBALS['nzbgetUsername'].':'.decrypt($GLOBALS['nzbgetPassword']).'/jsonrpc/listgroups';
         try{
-			$options = (localURL($url)) ? array('verify' => false ) : array();
-			$response = Requests::get($url, array(), $options);
-			if($response->success){
-				$api['content']['queueItems'] = json_decode($response->body, true);
-			}
-		}catch( Requests_Exception $e ) {
-			writeLog('error', 'NZBGet Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
-		};
+            $options = (localURL($url)) ? array('verify' => false ) : array();
+            $response = Requests::get($url, array(), $options);
+            if($response->success){
+                $api['content']['queueItems'] = json_decode($response->body, true);
+            }
+        }catch( Requests_Exception $e ) {
+            writeLog('error', 'NZBGet Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
+        };
         $url = qualifyURL($GLOBALS['nzbgetURL']);
         $url = $url.'/'.$GLOBALS['nzbgetUsername'].':'.decrypt($GLOBALS['nzbgetPassword']).'/jsonrpc/history';
         try{
-			$options = (localURL($url)) ? array('verify' => false ) : array();
-			$response = Requests::get($url, array(), $options);
-			if($response->success){
-				$api['content']['historyItems']= json_decode($response->body, true);
-			}
-		}catch( Requests_Exception $e ) {
-			writeLog('error', 'NZBGet Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
-		};
+            $options = (localURL($url)) ? array('verify' => false ) : array();
+            $response = Requests::get($url, array(), $options);
+            if($response->success){
+                $api['content']['historyItems']= json_decode($response->body, true);
+            }
+        }catch( Requests_Exception $e ) {
+            writeLog('error', 'NZBGet Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
+        };
         $api['content'] = isset($api['content']) ? $api['content'] : false;
         return $api;
     }
@@ -571,24 +571,24 @@ function transmissionConnect() {
     if($GLOBALS['homepageTransmissionEnabled'] && !empty($GLOBALS['transmissionURL']) && qualifyRequest($GLOBALS['homepageTransmissionAuth'])){
         $digest = qualifyURL($GLOBALS['transmissionURL'], true);
         $passwordInclude = ($GLOBALS['transmissionUsername'] != '' && $GLOBALS['transmissionPassword'] != '') ? $GLOBALS['transmissionUsername'].':'.decrypt($GLOBALS['transmissionPassword'])."@" : '';
-	    $url = $digest['scheme'].'://'.$passwordInclude.$digest['host'].$digest['port'].$digest['path'].'/rpc';
+        $url = $digest['scheme'].'://'.$passwordInclude.$digest['host'].$digest['port'].$digest['path'].'/rpc';
         try{
-			$options = (localURL($GLOBALS['transmissionURL'])) ? array('verify' => false ) : array();
-			$response = Requests::get($url, array(), $options);
-			if($response->headers['x-transmission-session-id']){
+            $options = (localURL($GLOBALS['transmissionURL'])) ? array('verify' => false ) : array();
+            $response = Requests::get($url, array(), $options);
+            if($response->headers['x-transmission-session-id']){
                 $headers = array(
-            		'X-Transmission-Session-Id' => $response->headers['x-transmission-session-id'],
-            		'Content-Type' => 'application/json'
-            	);
-            	$data = array(
-            		'method' => 'torrent-get',
-            		'arguments' => array(
-            			'fields' => array(
-            				"id", "name", "totalSize", "eta", "isFinished", "isStalled", "percentDone", "rateDownload", "status", "downloadDir","errorString"
-            			),
-            		),
-            		'tags' => ''
-            	);
+                    'X-Transmission-Session-Id' => $response->headers['x-transmission-session-id'],
+                    'Content-Type' => 'application/json'
+                );
+                $data = array(
+                    'method' => 'torrent-get',
+                    'arguments' => array(
+                        'fields' => array(
+                            "id", "name", "totalSize", "eta", "isFinished", "isStalled", "percentDone", "rateDownload", "status", "downloadDir","errorString"
+                        ),
+                    ),
+                    'tags' => ''
+                );
                 $response = Requests::post($url, $headers, json_encode($data), $options);
                 if($response->success){
                     $torrentList = json_decode($response->body, true)['arguments']['torrents'];
@@ -605,15 +605,15 @@ function transmissionConnect() {
                     }else{
                         $torrents = json_decode($response->body, true);
                     }
-    				$api['content']['queueItems'] = $torrents;
+                    $api['content']['queueItems'] = $torrents;
                     $api['content']['historyItems'] = false;
-    			}
-			}else{
+                }
+            }else{
                 writeLog('error', 'Transmission Connect Function - Error: Could not get session ID', 'SYSTEM');
             }
-		}catch( Requests_Exception $e ) {
-			writeLog('error', 'Transmission Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
-		};
+        }catch( Requests_Exception $e ) {
+            writeLog('error', 'Transmission Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
+        };
         $api['content'] = isset($api['content']) ? $api['content'] : false;
         return $api;
     }
@@ -635,7 +635,7 @@ function qBittorrentConnect() {
                 $headers = array(
                     'Cookie' => 'SID=' . $cookie['SID']->value
                 );
-				$reverse = $GLOBALS['qBittorrentReverseSorting'] ? 'true' : 'false';
+                $reverse = $GLOBALS['qBittorrentReverseSorting'] ? 'true' : 'false';
                 $url = $digest['scheme'].'://'.$digest['host'].$digest['port'].$digest['path'].'/query/torrents?sort=' . $GLOBALS['qBittorrentSortOrder'] . '&reverse=' . $reverse;
                 $response = Requests::get($url, $headers, $options);
                 if($response){
@@ -667,23 +667,23 @@ function qBittorrentConnect() {
     }
 }
 function delugeConnect(){
-	if($GLOBALS['homepageDelugeEnabled'] && !empty($GLOBALS['delugeURL']) && qualifyRequest($GLOBALS['homepageDelugeAuth'])){
-		try{
-			$deluge = new deluge($GLOBALS['delugeURL'], decrypt($GLOBALS['delugePassword']));
-			$torrents = $deluge->getTorrents(null, 'comment, download_payload_rate, eta, is_finished, is_seed, message, name, paused, progress, queue, state, total_size, upload_payload_rate');
-			$api['content']['queueItems'] = $torrents;
-			$api['content']['historyItems'] = false;
-		}catch( Excecption $e){
-			writeLog('error', 'Deluge Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
-		}
-	}
-	$api['content'] = isset($api['content']) ? $api['content'] : false;
-	return $api;
+    if($GLOBALS['homepageDelugeEnabled'] && !empty($GLOBALS['delugeURL']) && qualifyRequest($GLOBALS['homepageDelugeAuth'])){
+        try{
+            $deluge = new deluge($GLOBALS['delugeURL'], decrypt($GLOBALS['delugePassword']));
+            $torrents = $deluge->getTorrents(null, 'comment, download_payload_rate, eta, is_finished, is_seed, message, name, paused, progress, queue, state, total_size, upload_payload_rate');
+            $api['content']['queueItems'] = $torrents;
+            $api['content']['historyItems'] = false;
+        }catch( Excecption $e){
+            writeLog('error', 'Deluge Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
+        }
+    }
+    $api['content'] = isset($api['content']) ? $api['content'] : false;
+    return $api;
 }
 function getCalendar(){
-	$startDate = date('Y-m-d',strtotime("-".$GLOBALS['calendarStart']." days"));
-	$endDate = date('Y-m-d',strtotime("+".$GLOBALS['calendarEnd']." days"));
-	$calendarItems = array();
+    $startDate = date('Y-m-d',strtotime("-".$GLOBALS['calendarStart']." days"));
+    $endDate = date('Y-m-d',strtotime("+".$GLOBALS['calendarEnd']." days"));
+    $calendarItems = array();
     // SONARR CONNECT
     if($GLOBALS['homepageSonarrEnabled'] && qualifyRequest($GLOBALS['homepageSonarrAuth']) && !empty($GLOBALS['sonarrURL']) && !empty($GLOBALS['sonarrToken'])){
         $sonarrs = array();
@@ -722,7 +722,7 @@ function getCalendar(){
             foreach ($radarrs as $key => $value) {
                 try {
                     $radarr = new Kryptonit3\Sonarr\Sonarr($value['url'], $value['token']);
-                    $radarrCalendar = getRadarrCalendar($radarr->getCalendar($startDate, $endDate),$key);
+                    $radarrCalendar = getRadarrCalendar($radarr->getCalendar($startDate, $endDate),$key,$value['url']);
                 } catch (Exception $e) {
                     writeLog('error', 'Radarr Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
                 }
@@ -745,17 +745,17 @@ function getCalendar(){
             foreach ($sicks as $key => $value) {
                 try {
                     $sickrage = new Kryptonit3\SickRage\SickRage($value['url'], $value['token']);
-        			$sickrageFuture = getSickrageCalendarWanted($sickrage->future(),$key);
+                    $sickrageFuture = getSickrageCalendarWanted($sickrage->future(),$key);
                     $sickrageHistory = getSickrageCalendarHistory($sickrage->history("100","downloaded"),$key);
-        			if(!empty($sickrageFuture)) { $calendarItems = array_merge($calendarItems, $sickrageFuture); }
+                    if(!empty($sickrageFuture)) { $calendarItems = array_merge($calendarItems, $sickrageFuture); }
                     if(!empty($sickrageHistory)) { $calendarItems = array_merge($calendarItems, $sickrageHistory); }
-        		} catch (Exception $e) {
-        			writeLog('error', 'Sickrage Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
-        		}
+                } catch (Exception $e) {
+                    writeLog('error', 'Sickrage Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
+                }
             }
         }
     }
-	// COUCHPOTATO CONNECT
+    // COUCHPOTATO CONNECT
     if($GLOBALS['homepageCouchpotatoEnabled'] && qualifyRequest($GLOBALS['homepageCouchpotatoAuth']) && !empty($GLOBALS['couchpotatoURL']) && !empty($GLOBALS['couchpotatoToken'])){
         $couchs = array();
         $couchpotatoURLList = explode(',', $GLOBALS['couchpotatoURL']);
@@ -770,17 +770,16 @@ function getCalendar(){
             foreach ($couchs as $key => $value) {
                 try {
                     $couchpotato = new Kryptonit3\CouchPotato\CouchPotato($value['url'], $value['token']);
-        			$couchCalendar = getCouchCalendar($couchpotato->getMediaList(),$key);
-        			if(!empty($couchCalendar)) { $calendarItems = array_merge($calendarItems, $couchCalendar); }
-        		} catch (Exception $e) {
-        			writeLog('error', 'Sickrage Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
-        		}
+                    $couchCalendar = getCouchCalendar($couchpotato->getMediaList(),$key);
+                    if(!empty($couchCalendar)) { $calendarItems = array_merge($calendarItems, $couchCalendar); }
+                } catch (Exception $e) {
+                    writeLog('error', 'Sickrage Connect Function - Error: '.$e->getMessage(), 'SYSTEM');
+                }
             }
         }
     }
 
-
-	return ($calendarItems) ? $calendarItems : false;
+    return ($calendarItems) ? $calendarItems : false;
 }
 function getSonarrCalendar($array,$number){
     $array = json_decode($array, true);
@@ -799,17 +798,42 @@ function getSonarrCalendar($array,$number){
         if (new DateTime() < new DateTime($episodeAirDate)) { $unaired = true; }
         $downloaded = $child['hasFile'];
         if($downloaded == "0" && isset($unaired) && $episodePremier == "true"){ $downloaded = "text-primary"; }elseif($downloaded == "0" && isset($unaired)){ $downloaded = "text-info"; }elseif($downloaded == "1"){ $downloaded = "text-success"; }else{ $downloaded = "text-danger"; }
-		array_push($gotCalendar, array(
-			"id" => "Sonarr-".$number."-".$i,
-			"title" => $seriesName,
-			"start" => $child['airDateUtc'],
-			"className" => "bg-calendar tvID--".$episodeID,
-			"imagetype" => "tv ".$downloaded,
-		));
+
+        $fanart = "/plugins/images/cache/no-np.png";
+        foreach ($child['series']['images'] as $image) {
+            if($image['coverType'] == "fanart") {
+                $fanart = $image['url'];
+            }
+        }
+        $bottomTitle = 'S' . sprintf("%02d", $child['seasonNumber']) . 'E' . sprintf("%02d", $child['episodeNumber']) . ' - ' . $child['title'];
+        $details = array(
+                "seasonCount" => $child['series']['seasonCount'],
+                "status" => $child['series']['status'],
+                "topTitle" => $seriesName,
+                "bottomTitle" => $bottomTitle,
+                "overview" => $child['overview'],
+                "runtime" => $child['series']['runtime'],
+                "image" => $fanart,
+                "ratings" => $child['series']['ratings']['value'],
+                "videoQuality" => $child["hasFile"] ? $child['episodeFile']['quality']['quality']['name'] : "unknown",
+                "audioChannels" => $child["hasFile"] ? $child['episodeFile']['mediaInfo']['audioChannels'] : "unknown",
+                "audioCodec" => $child["hasFile"] ? $child['episodeFile']['mediaInfo']['audioCodec'] : "unknown",
+                "videoCodec" => $child["hasFile"] ? $child['episodeFile']['mediaInfo']['videoCodec'] : "unknown",
+                "size" => $child["hasFile"] ? $child['episodeFile']['size'] : "unknown",
+                "genres" => $child['series']['genres'],
+            );
+        array_push($gotCalendar, array(
+            "id" => "Sonarr-".$number."-".$i,
+            "title" => $seriesName,
+            "start" => $child['airDateUtc'],
+            "className" => "bg-calendar calendar-item tvID--".$episodeID,
+            "imagetype" => "tv ".$downloaded,
+            "details" => $details
+        ));
     }
     if ($i != 0){ return $gotCalendar; }
 }
-function getRadarrCalendar($array,$number){
+function getRadarrCalendar($array,$number, $url){
     $array = json_decode($array, true);
     $gotCalendar = array();
     $i = 0;
@@ -819,19 +843,56 @@ function getRadarrCalendar($array,$number){
             $movieName = $child['title'];
             $movieID = $child['tmdbId'];
             if(!isset($movieID)){ $movieID = ""; }
-			$physicalRelease = $child['physicalRelease'];
-			$physicalRelease = strtotime($physicalRelease);
-			$physicalRelease = date("Y-m-d", $physicalRelease);
-			if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
-			$downloaded = $child['hasFile'];
-			if($downloaded == "0" && $notReleased == "true"){ $downloaded = "text-info"; }elseif($downloaded == "1"){ $downloaded = "text-success"; }else{ $downloaded = "text-danger"; }
-			array_push($gotCalendar, array(
-				"id" => "Radarr-".$number."-".$i,
-				"title" => $movieName,
-				"start" => $physicalRelease,
-				"className" => "bg-calendar movieID--".$movieID,
-				"imagetype" => "film ".$downloaded,
-			));
+            $physicalRelease = $child['physicalRelease'];
+            $physicalRelease = strtotime($physicalRelease);
+            $physicalRelease = date("Y-m-d", $physicalRelease);
+            if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
+            $downloaded = $child['hasFile'];
+            if($downloaded == "0" && $notReleased == "true"){ $downloaded = "text-info"; }elseif($downloaded == "1"){ $downloaded = "text-success"; }else{ $downloaded = "text-danger"; }
+            $banner = "/plugins/images/cache/no-np.png";
+            foreach ($child['images'] as $image) {
+                if($image['coverType'] == "banner") {
+                    $url = rtrim($url, '/'); //remove trailing slash
+                    $imageUrl = $image['url'];
+                    $urlParts = explode("/", $url);
+                    $imageParts = explode("/", $image['url']);
+
+                    if ($imageParts[1] == end($urlParts)) {
+                        unset($imageParts[1]);
+                        $imageUrl = implode("/", $imageParts);
+                    }
+
+                    $banner = $url . $imageUrl;
+                }
+            }
+            $alternativeTitles = "";
+            foreach ($child['alternativeTitles'] as $alternative) {
+                $alternativeTitles .= $alternative['title'] + ', ';
+            }
+            $alternativeTitles = empty($child['alternativeTitles']) ? "" : substr($alternativeTitles, 0, -2);
+            $details = array(
+                    "topTitle" => $movieName,
+                    "bottomTitle" => $alternativeTitles,
+                    "status" => $child['status'],
+                    "overview" => $child['overview'],
+                    "runtime" => $child['runtime'],
+                    "image" => $banner,
+                    "ratings" => $child['ratings']['value'],
+                    "videoQuality" => $child["hasFile"] ? $child['movieFile']['quality']['quality']['name'] : "unknown",
+                    "audioChannels" => $child["hasFile"] ? $child['movieFile']['mediaInfo']['audioChannels'] : "unknown",
+                    "audioCodec" => $child["hasFile"] ? $child['movieFile']['mediaInfo']['audioFormat'] : "unknown",
+                    "videoCodec" => $child["hasFile"] ? $child['movieFile']['mediaInfo']['videoCodec'] : "unknown",
+                    "size" => $child["hasFile"] ? $child['movieFile']['size'] : "unknown",
+                    "genres" => $child['genres'],
+                );
+            array_push($gotCalendar, array(
+                "id" => "Radarr-".$number."-".$i,
+                "title" => $movieName,
+                "start" => $physicalRelease,
+                "className" => "bg-calendar movieID--".$movieID,
+                "imagetype" => "film ".$downloaded,
+                "details" => $details
+            ));
         }
     }
     if ($i != 0){ return $gotCalendar; }
@@ -840,30 +901,30 @@ function getCouchCalendar($array,$number){
     $api = json_decode($array, true);
     $gotCalendar = array();
     $i = 0;
-	foreach($api['movies'] AS $child) {
-		if($child['status'] == "active" || $child['status'] == "done" ){
-			$i++;
-			$movieName = $child['info']['original_title'];
-			$movieID = $child['info']['tmdb_id'];
-			if(!isset($movieID)){ $movieID = ""; }
-			$physicalRelease = (isset($child['info']['released']) ? $child['info']['released'] : null);
-			$backupRelease = (isset($child['info']['release_date']['theater']) ? $child['info']['release_date']['theater'] : null);
-			$physicalRelease = (isset($physicalRelease) ? $physicalRelease : $backupRelease);
-			$physicalRelease = strtotime($physicalRelease);
-			$physicalRelease = date("Y-m-d", $physicalRelease);
-			if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
-			$downloaded = ($child['status'] == "active") ? "0" : "1";
-			if($downloaded == "0" && $notReleased == "true"){ $downloaded = "text-info"; }elseif($downloaded == "1"){ $downloaded = "text-success"; }else{ $downloaded = "text-danger"; }
-			array_push($gotCalendar, array(
-				"id" => "CouchPotato-".$number."-".$i,
-				"title" => $movieName,
-				"start" => $physicalRelease,
-				"className" => "bg-calendar movieID--".$movieID,
-				"imagetype" => "film ".$downloaded,
-			));
-		}
-	}
-	if ($i != 0){ return $gotCalendar; }
+    foreach($api['movies'] AS $child) {
+        if($child['status'] == "active" || $child['status'] == "done" ){
+            $i++;
+            $movieName = $child['info']['original_title'];
+            $movieID = $child['info']['tmdb_id'];
+            if(!isset($movieID)){ $movieID = ""; }
+            $physicalRelease = (isset($child['info']['released']) ? $child['info']['released'] : null);
+            $backupRelease = (isset($child['info']['release_date']['theater']) ? $child['info']['release_date']['theater'] : null);
+            $physicalRelease = (isset($physicalRelease) ? $physicalRelease : $backupRelease);
+            $physicalRelease = strtotime($physicalRelease);
+            $physicalRelease = date("Y-m-d", $physicalRelease);
+            if (new DateTime() < new DateTime($physicalRelease)) { $notReleased = "true"; }else{ $notReleased = "false"; }
+            $downloaded = ($child['status'] == "active") ? "0" : "1";
+            if($downloaded == "0" && $notReleased == "true"){ $downloaded = "text-info"; }elseif($downloaded == "1"){ $downloaded = "text-success"; }else{ $downloaded = "text-danger"; }
+            array_push($gotCalendar, array(
+                "id" => "CouchPotato-".$number."-".$i,
+                "title" => $movieName,
+                "start" => $physicalRelease,
+                "className" => "bg-calendar calendar-item movieID--".$movieID,
+                "imagetype" => "film ".$downloaded,
+            ));
+        }
+    }
+    if ($i != 0){ return $gotCalendar; }
 }
 function getSickrageCalendarWanted($array,$number){
     $array = json_decode($array, true);
@@ -881,13 +942,13 @@ function getSickrageCalendarWanted($array,$number){
             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"; }
-			array_push($gotCalendar, array(
-				"id" => "Sick-".$number."-Miss-".$i,
-				"title" => $seriesName,
-				"start" => $episodeAirDate,
-				"className" => "bg-calendar tvID--".$episodeID,
-				"imagetype" => "tv ".$downloaded,
-			));
+            array_push($gotCalendar, array(
+                "id" => "Sick-".$number."-Miss-".$i,
+                "title" => $seriesName,
+                "start" => $episodeAirDate,
+                "className" => "bg-calendar calendar-item tvID--".$episodeID,
+                "imagetype" => "tv ".$downloaded,
+            ));
     }
     foreach($array['data']['today'] AS $child) {
             $i++;
@@ -901,13 +962,13 @@ function getSickrageCalendarWanted($array,$number){
             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"; }
-			array_push($gotCalendar, array(
-				"id" => "Sick-".$number."-Today-".$i,
-				"title" => $seriesName,
-				"start" => $episodeAirDate,
-				"className" => "bg-calendar tvID--".$episodeID,
-				"imagetype" => "tv ".$downloaded,
-			));
+            array_push($gotCalendar, array(
+                "id" => "Sick-".$number."-Today-".$i,
+                "title" => $seriesName,
+                "start" => $episodeAirDate,
+                "className" => "bg-calendar calendar-item tvID--".$episodeID,
+                "imagetype" => "tv ".$downloaded,
+            ));
     }
     foreach($array['data']['soon'] AS $child) {
             $i++;
@@ -921,13 +982,13 @@ function getSickrageCalendarWanted($array,$number){
             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"; }
-			array_push($gotCalendar, array(
-				"id" => "Sick-".$number."-Soon-".$i,
-				"title" => $seriesName,
-				"start" => $episodeAirDate,
-				"className" => "bg-calendar tvID--".$episodeID,
-				"imagetype" => "tv ".$downloaded,
-			));
+            array_push($gotCalendar, array(
+                "id" => "Sick-".$number."-Soon-".$i,
+                "title" => $seriesName,
+                "start" => $episodeAirDate,
+                "className" => "bg-calendar calendar-item tvID--".$episodeID,
+                "imagetype" => "tv ".$downloaded,
+            ));
     }
     foreach($array['data']['later'] AS $child) {
             $i++;
@@ -941,13 +1002,13 @@ function getSickrageCalendarWanted($array,$number){
             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"; }
-			array_push($gotCalendar, array(
-				"id" => "Sick-".$number."-Later-".$i,
-				"title" => $seriesName,
-				"start" => $episodeAirDate,
-				"className" => "bg-calendar tvID--".$episodeID,
-				"imagetype" => "tv ".$downloaded,
-			));
+            array_push($gotCalendar, array(
+                "id" => "Sick-".$number."-Later-".$i,
+                "title" => $seriesName,
+                "start" => $episodeAirDate,
+                "className" => "bg-calendar calendar-item tvID--".$episodeID,
+                "imagetype" => "tv ".$downloaded,
+            ));
     }
     if ($i != 0){ return $gotCalendar; }
 }
@@ -961,13 +1022,13 @@ function getSickrageCalendarHistory($array,$number){
             $episodeID = $child['tvdbid'];
             $episodeAirDate = $child['date'];
             $downloaded = "text-success";
-			array_push($gotCalendar, array(
-				"id" => "Sick-".$number."-History-".$i,
-				"title" => $seriesName,
-				"start" => $episodeAirDate,
-				"className" => "bg-calendar tvID--".$episodeID,
-				"imagetype" => "tv ".$downloaded,
-			));
+            array_push($gotCalendar, array(
+                "id" => "Sick-".$number."-History-".$i,
+                "title" => $seriesName,
+                "start" => $episodeAirDate,
+                "className" => "bg-calendar calendar-item tvID--".$episodeID,
+                "imagetype" => "tv ".$downloaded,
+            ));
     }
     if ($i != 0){ return $gotCalendar; }
 }