Sfoglia il codice sorgente

Added Lidarr
Edited Sonarr Class to allow Lidarr due to v1 in url
Fix Emby URL #874

causefx 8 anni fa
parent
commit
7a57cb2d9c

+ 4 - 0
api/config/default.php

@@ -43,6 +43,8 @@ return array(
 	'sonarrURL' => '',
 	'sonarrUnmonitored' => false,
 	'sonarrToken' => '',
+	'lidarrURL' => '',
+	'lidarrToken' => '',
 	'radarrURL' => '',
 	'radarrToken' => '',
 	'couchpotatoURL' => '',
@@ -83,6 +85,8 @@ return array(
 	'homepageSabnzbdAuth' => '1',
 	'homepageSonarrEnabled' => false,
 	'homepageSonarrAuth' => '1',
+	'homepageLidarrEnabled' => false,
+	'homepageLidarrAuth' => '1',
 	'homepageCouchpotatoEnabled' => false,
 	'homepageCouchpotatoAuth' => '1',
 	'homepageSickrageEnabled' => false,

+ 113 - 1
api/functions/homepage-connect-functions.php

@@ -185,7 +185,7 @@ function resolveEmbyItem($itemDetails)
 	$embyItem['user'] = ($GLOBALS['homepageShowStreamNames'] && qualifyRequest($GLOBALS['homepageShowStreamNamesAuth'])) ? @(string)$itemDetails['UserName'] : "";
 	$embyItem['userThumb'] = '';
 	$embyItem['userAddress'] = (isset($itemDetails['RemoteEndPoint']) ? $itemDetails['RemoteEndPoint'] : "x.x.x.x");
-	$embyItem['address'] = $GLOBALS['embyTabURL'] ? '' : '';
+	$embyItem['address'] = $GLOBALS['embyTabURL'] ? rtrim($GLOBALS['embyTabURL'], '/') . "/web/itemdetails.html?id=" . $embyItem['uid'] : "https://app.emby.media/itemdetails.html?id=" . $embyItem['uid'] . "&serverId=" . $embyItem['id'];
 	$embyItem['nowPlayingOriginalImage'] = 'api/?v1/image&source=emby&type=' . $embyItem['nowPlayingImageType'] . '&img=' . $embyItem['nowPlayingThumb'] . '&height=' . $nowPlayingHeight . '&width=' . $nowPlayingWidth . '&key=' . $embyItem['nowPlayingKey'] . '$' . randString();
 	$embyItem['originalImage'] = 'api/?v1/image&source=emby&type=' . $embyItem['imageType'] . '&img=' . $embyItem['thumb'] . '&height=' . $height . '&width=' . $width . '&key=' . $embyItem['key'] . '$' . randString();
 	$embyItem['openTab'] = $GLOBALS['embyTabURL'] && $GLOBALS['embyTabName'] ? true : false;
@@ -852,6 +852,31 @@ function getCalendar()
 			}
 		}
 	}
+	// LIDARR CONNECT
+	if ($GLOBALS['homepageLidarrEnabled'] && qualifyRequest($GLOBALS['homepageLidarrAuth']) && !empty($GLOBALS['lidarrURL']) && !empty($GLOBALS['lidarrToken'])) {
+		$lidarrs = array();
+		$lidarrURLList = explode(',', $GLOBALS['lidarrURL']);
+		$lidarrTokenList = explode(',', $GLOBALS['lidarrToken']);
+		if (count($lidarrURLList) == count($lidarrTokenList)) {
+			foreach ($lidarrURLList as $key => $value) {
+				$lidarrs[$key] = array(
+					'url' => $value,
+					'token' => $lidarrTokenList[$key]
+				);
+			}
+			foreach ($lidarrs as $key => $value) {
+				try {
+					$lidarr = new Kryptonit3\Sonarr\Sonarr($value['url'], $value['token'], true);
+					$lidarrCalendar = getLidarrCalendar($lidarr->getCalendar($startDate, $endDate), $key);
+				} catch (Exception $e) {
+					writeLog('error', 'Lidarr Connect Function - Error: ' . $e->getMessage(), 'SYSTEM');
+				}
+				if (!empty($lidarrCalendar)) {
+					$calendarItems = array_merge($calendarItems, $lidarrCalendar);
+				}
+			}
+		}
+	}
 	// RADARR CONNECT
 	if ($GLOBALS['homepageRadarrEnabled'] && qualifyRequest($GLOBALS['homepageRadarrAuth']) && !empty($GLOBALS['radarrURL']) && !empty($GLOBALS['radarrToken'])) {
 		$radarrs = array();
@@ -1064,6 +1089,67 @@ function getSonarrCalendar($array, $number)
 	return false;
 }
 
+function getLidarrCalendar($array, $number)
+{
+	$array = json_decode($array, true);
+	$gotCalendar = array();
+	$i = 0;
+	foreach ($array as $child) {
+		$i++;
+		$albumName = $child['title'];
+		$artistName = $child['artist']['artistName'];
+		$albumID = '';
+		$releaseDate = $child['releaseDate'];
+		$releaseDate = strtotime($releaseDate);
+		$releaseDate = date("Y-m-d H:i:s", $releaseDate);
+		if (new DateTime() < new DateTime($releaseDate)) {
+			$unaired = true;
+		}
+		$downloaded = ($child['statistics']['percentOfEpisodes'] !== '100.0') ? '0' : '1';
+		if ($downloaded == "0" && isset($unaired)) {
+			$downloaded = "text-info";
+		} elseif ($downloaded == "1") {
+			$downloaded = "text-success";
+		} else {
+			$downloaded = "text-danger";
+		}
+		$fanart = "/plugins/images/cache/no-np.png";
+		foreach ($child['artist']['images'] as $image) {
+			if ($image['coverType'] == "fanart") {
+				$fanart = str_replace('http://', 'https://', $image['url']);
+			}
+		}
+		$details = array(
+			"seasonCount" => '',
+			"status" => '',
+			"topTitle" => $albumName,
+			"bottomTitle" => $artistName,
+			"overview" => isset($child['artist']['overview']) ? $child['artist']['overview'] : '',
+			"runtime" => '',
+			"image" => $fanart,
+			"ratings" => $child['artist']['ratings']['value'],
+			"videoQuality" => "unknown",
+			"audioChannels" => "unknown",
+			"audioCodec" => "unknown",
+			"videoCodec" => "unknown",
+			"size" => "unknown",
+			"genres" => $child['genres'],
+		);
+		array_push($gotCalendar, array(
+			"id" => "Lidarr-" . $number . "-" . $i,
+			"title" => $artistName,
+			"start" => $child['releaseDate'],
+			"className" => "bg-calendar calendar-item musicID--",
+			"imagetype" => "music " . $downloaded,
+			"details" => $details
+		));
+	}
+	if ($i != 0) {
+		return $gotCalendar;
+	}
+	return false;
+}
+
 function getRadarrCalendar($array, $number, $url)
 {
 	$array = json_decode($array, true);
@@ -1775,6 +1861,32 @@ function testAPIConnection($array)
 				return 'URL/s and/or Token/s not setup';
 			}
 			break;
+		case 'lidarr':
+			if (!empty($GLOBALS['lidarrURL']) && !empty($GLOBALS['lidarrToken'])) {
+				$sonarrs = array();
+				$sonarrURLList = explode(',', $GLOBALS['lidarrURL']);
+				$sonarrTokenList = explode(',', $GLOBALS['lidarrToken']);
+				if (count($sonarrURLList) == count($sonarrTokenList)) {
+					foreach ($sonarrURLList as $key => $value) {
+						$sonarrs[$key] = array(
+							'url' => $value,
+							'token' => $sonarrTokenList[$key]
+						);
+					}
+					foreach ($sonarrs as $key => $value) {
+						try {
+							$sonarr = new Kryptonit3\Sonarr\Sonarr($value['url'], $value['token'], true);
+							$sonarr->getSystemStatus();
+							return true;
+						} catch (Exception $e) {
+							return $e->getMessage();
+						}
+					}
+				}
+			} else {
+				return 'URL/s and/or Token/s not setup';
+			}
+			break;
 		case 'radarr':
 			if (!empty($GLOBALS['radarrURL']) && !empty($GLOBALS['radarrToken'])) {
 				$sonarrs = array();

+ 103 - 0
api/functions/homepage-functions.php

@@ -1230,6 +1230,109 @@ function getHomepageList()
 				)
 			)
 		),
+		array(
+			'name' => 'Lidarr',
+			'enabled' => (strpos('personal', $GLOBALS['license']) !== false) ? true : false,
+			'image' => 'plugins/images/tabs/lidarr.png',
+			'category' => 'PMR',
+			'settings' => array(
+				'Enable' => array(
+					array(
+						'type' => 'switch',
+						'name' => 'homepageLidarrEnabled',
+						'label' => 'Enable',
+						'value' => $GLOBALS['homepageLidarrEnabled']
+					),
+					array(
+						'type' => 'select',
+						'name' => 'homepageLidarrAuth',
+						'label' => 'Minimum Authentication',
+						'value' => $GLOBALS['homepageLidarrAuth'],
+						'options' => $groups
+					)
+				),
+				'Connection' => array(
+					array(
+						'type' => 'input',
+						'name' => 'lidarrURL',
+						'label' => 'URL',
+						'value' => $GLOBALS['lidarrURL'],
+						'placeholder' => 'http(s)://hostname:port'
+					),
+					array(
+						'type' => 'password-alt',
+						'name' => 'lidarrToken',
+						'label' => 'Token',
+						'value' => $GLOBALS['lidarrToken']
+					)
+				),
+				'Misc Options' => array(
+					array(
+						'type' => 'number',
+						'name' => 'calendarStart',
+						'label' => '# of Days Before',
+						'value' => $GLOBALS['calendarStart'],
+						'placeholder' => ''
+					),
+					array(
+						'type' => 'number',
+						'name' => 'calendarEnd',
+						'label' => '# of Days After',
+						'value' => $GLOBALS['calendarEnd'],
+						'placeholder' => ''
+					),
+					array(
+						'type' => 'select',
+						'name' => 'calendarFirstDay',
+						'label' => 'Start Day',
+						'value' => $GLOBALS['calendarFirstDay'],
+						'options' => $day
+					),
+					array(
+						'type' => 'select',
+						'name' => 'calendarDefault',
+						'label' => 'Default View',
+						'value' => $GLOBALS['calendarDefault'],
+						'options' => $calendarDefault
+					),
+					array(
+						'type' => 'select',
+						'name' => 'calendarTimeFormat',
+						'label' => 'Time Format',
+						'value' => $GLOBALS['calendarTimeFormat'],
+						'options' => $timeFormat
+					),
+					array(
+						'type' => 'select',
+						'name' => 'calendarLimit',
+						'label' => 'Items Per Day',
+						'value' => $GLOBALS['calendarLimit'],
+						'options' => $limit
+					),
+					array(
+						'type' => 'select',
+						'name' => 'calendarRefresh',
+						'label' => 'Refresh Seconds',
+						'value' => $GLOBALS['calendarRefresh'],
+						'options' => optionTime()
+					),
+				),
+				'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(\'lidarr\')"'
+					),
+				)
+			)
+		),
 		array(
 			'name' => 'Radarr',
 			'enabled' => (strpos('personal', $GLOBALS['license']) !== false) ? true : false,

+ 13 - 10
api/vendor/kryptonit3/sonarr/src/Sonarr.php

@@ -11,10 +11,11 @@ class Sonarr
     protected $httpAuthUsername;
     protected $httpAuthPassword;
 
-    public function __construct($url, $apiKey, $httpAuthUsername = null, $httpAuthPassword = null)
+    public function __construct($url, $apiKey, $lidarr = false, $httpAuthUsername = null, $httpAuthPassword = null)
     {
         $this->url = rtrim($url, '/\\'); // Example: http://127.0.0.1:8989 (no trailing forward-backward slashes)
-        $this->apiKey = $apiKey;
+	    $this->apiKey = $apiKey;
+	    $this->lidarr = $lidarr;
         $this->httpAuthUsername = $httpAuthUsername;
         $this->httpAuthPassword = $httpAuthPassword;
     }
@@ -63,9 +64,11 @@ class Sonarr
         }
         if ( $sonarrUnmonitored == 'true' ) {
             $uriData['unmonitored'] = 'true';
-	}
-            
-        $response = [
+		}
+	    if ( $this->lidarr == true ) {
+		    $uriData['includeArtist'] = 'true';
+	    }
+	    $response = [
             'uri' => 'calendar',
             'type' => 'get',
             'data' => $uriData
@@ -603,29 +606,29 @@ class Sonarr
                 $this->httpAuthPassword
             ];
         }
-
+	    $lidarr = ( $this->lidarr == true ) ? 'v1/' : '';
         if ( $params['type'] == 'get' ) {
-            $url = $this->url . '/api/' . $params['uri'] . '?' . http_build_query($params['data']);
+            $url = $this->url . '/api/' . $lidarr . $params['uri'] . '?' . http_build_query($params['data']);
 
             return $client->get($url, $options);
         }
 
         if ( $params['type'] == 'put' ) {
-            $url = $this->url . '/api/' . $params['uri'];
+            $url = $this->url . '/api/' . $lidarr . $params['uri'];
             $options['json'] = $params['data'];
 
             return $client->put($url, $options);
         }
 
         if ( $params['type'] == 'post' ) {
-            $url = $this->url . '/api/' . $params['uri'];
+            $url = $this->url . '/api/' . $lidarr . $params['uri'];
             $options['json'] = $params['data'];
 
             return $client->post($url, $options);
         }
 
         if ( $params['type'] == 'delete' ) {
-            $url = $this->url . '/api/' . $params['uri'] . '?' . http_build_query($params['data']);
+            $url = $this->url . '/api/' . $lidarr . $params['uri'] . '?' . http_build_query($params['data']);
 
             return $client->delete($url, $options);
         }