Browse Source

Added functionality to override name with JSON input

Henry Whitaker 5 năm trước cách đây
mục cha
commit
41b97547fa
4 tập tin đã thay đổi với 76 bổ sung16 xóa
  1. 2 0
      api/config/default.php
  2. 54 15
      api/homepage/plex.php
  3. 20 1
      js/custom.js
  4. 0 0
      js/custom.min.js

+ 2 - 0
api/config/default.php

@@ -221,6 +221,8 @@ return array(
 	'homepageOrderJackett' => '31',
 	'homepageShowStreamNames' => false,
 	'homepageShowStreamNamesAuth' => '1',
+	'homepageUseCustomStreamNames' => false,
+	'homepageCustomStreamNames' => '',
 	'homepageStreamRefresh' => '60000',
 	'homepageRecentRefresh' => '60000',
 	'homepageDownloadRefresh' => '60000',

+ 54 - 15
api/homepage/plex.php

@@ -2,7 +2,7 @@
 
 trait PlexHomepageItem
 {
-	
+
 	public function plexSettingsArray()
 	{
 		return array(
@@ -205,6 +205,28 @@ trait PlexHomepageItem
 								'value' => '3'
 							)
 						)
+					),
+					array(
+						'type' => 'switch',
+						'name' => 'homepageUseCustomStreamNames',
+						'label' => 'Use custom names for users',
+						'value' => $this->config['homepageUseCustomStreamNames']
+					),
+					array(
+						'type' => 'html',
+						'name' => 'homepageCustomStreamNamesAce',
+						'class' => 'jsonTextarea hidden',
+						'label' => 'Custom definitions for user names (JSON Object, with the key being the plex name, and the value what you want to override with)',
+						'override' => 12,
+						'html' => '<div id="homepageCustomStreamNamesAce" style="height: 300px;">' . htmlentities($this->config['homepageCustomStreamNames']) . '</div>',
+					),
+					array(
+						'type' => 'textbox',
+						'name' => 'homepageCustomStreamNames',
+						'class' => 'jsonTextarea hidden',
+						'id' => 'homepageCustomStreamNamesText',
+						'label' => '',
+						'value' => $this->config['homepageCustomStreamNames'],
 					)
 				),
 				'Test Connection' => array(
@@ -224,7 +246,7 @@ trait PlexHomepageItem
 			)
 		);
 	}
-	
+
 	public function testConnectionPlex()
 	{
 		if (!empty($this->config['plexURL']) && !empty($this->config['plexToken'])) {
@@ -249,7 +271,7 @@ trait PlexHomepageItem
 			return 'URL and/or Token not setup';
 		}
 	}
-	
+
 	public function plexHomepagePermissions($key = null)
 	{
 		$permissions = [
@@ -335,7 +357,7 @@ trait PlexHomepageItem
 			return [];
 		}
 	}
-	
+
 	public function homepageOrderplexnowplaying()
 	{
 		if ($this->homepageItemPermissions($this->plexHomepagePermissions('streams'))) {
@@ -351,7 +373,7 @@ trait PlexHomepageItem
 				';
 		}
 	}
-	
+
 	public function homepageOrderplexrecent()
 	{
 		if ($this->homepageItemPermissions($this->plexHomepagePermissions('recent'))) {
@@ -367,7 +389,7 @@ trait PlexHomepageItem
 				';
 		}
 	}
-	
+
 	public function homepageOrderplexplaylist()
 	{
 		if ($this->homepageItemPermissions($this->plexHomepagePermissions('playlists'))) {
@@ -383,7 +405,7 @@ trait PlexHomepageItem
 				';
 		}
 	}
-	
+
 	public function getPlexHomepageStreams()
 	{
 		if (!$this->homepageItemPermissions($this->plexHomepagePermissions('streams'), true)) {
@@ -412,7 +434,7 @@ trait PlexHomepageItem
 			return $api;
 		}
 	}
-	
+
 	public function getPlexHomepageRecent()
 	{
 		if (!$this->homepageItemPermissions($this->plexHomepagePermissions('recent'), true)) {
@@ -454,7 +476,7 @@ trait PlexHomepageItem
 		$this->setAPIResponse('success', null, 200, $api);
 		return $api;
 	}
-	
+
 	public function getPlexHomepagePlaylists()
 	{
 		if (!$this->homepageItemPermissions($this->plexHomepagePermissions('playlists'), true)) {
@@ -494,9 +516,8 @@ trait PlexHomepageItem
 			$this->setAPIResponse('error', 'Plex API error', 500);
 			return false;
 		}
-		
 	}
-	
+
 	public function getPlexHomepageMetadata($array)
 	{
 		if (!$this->homepageItemPermissions($this->plexHomepagePermissions('metadata'), true)) {
@@ -530,7 +551,7 @@ trait PlexHomepageItem
 			return $api;
 		}
 	}
-	
+
 	public function getPlexHomepageSearch($query)
 	{
 		if (!$this->homepageItemPermissions($this->plexHomepagePermissions('search'), true)) {
@@ -564,7 +585,7 @@ trait PlexHomepageItem
 			return $api;
 		}
 	}
-	
+
 	public function resolvePlexItem($item)
 	{
 		// Static Height & Width
@@ -674,7 +695,7 @@ trait PlexHomepageItem
 		$plexItem['bandwidthType'] = (string)$item->Session['location'];
 		$plexItem['sessionType'] = isset($item->TranscodeSession['progress']) ? 'Transcoding' : 'Direct Playing';
 		$plexItem['state'] = (((string)$item->Player['state'] == "paused") ? "pause" : "play");
-		$plexItem['user'] = ($this->config['homepageShowStreamNames'] && $this->qualifyRequest($this->config['homepageShowStreamNamesAuth'])) ? (string)$item->User['title'] : "";
+		$plexItem['user'] = $this->formatPlexUserName($item);
 		$plexItem['userThumb'] = ($this->config['homepageShowStreamNames'] && $this->qualifyRequest($this->config['homepageShowStreamNamesAuth'])) ? (string)$item->User['thumb'] : "";
 		$plexItem['userAddress'] = ($this->config['homepageShowStreamNames'] && $this->qualifyRequest($this->config['homepageShowStreamNamesAuth'])) ? (string)$item->Player['address'] : "x.x.x.x";
 		$plexItem['address'] = $this->config['plexTabURL'] ? $this->config['plexTabURL'] . "/web/index.html#!/server/" . $this->config['plexID'] . "/details?key=/library/metadata/" . $item['ratingKey'] : "https://app.plex.tv/web/app#!/server/" . $this->config['plexID'] . "/details?key=/library/metadata/" . $item['ratingKey'];
@@ -757,4 +778,22 @@ trait PlexHomepageItem
 		}
 		return $plexItem;
 	}
-}
+
+	private function formatPlexUserName($item)
+	{
+		$name = ($this->config['homepageShowStreamNames'] && $this->qualifyRequest($this->config['homepageShowStreamNamesAuth'])) ? (string)$item->User['title'] : "";
+
+		try {
+			if ($this->config['homepageUseCustomStreamNames']) {
+				$customNames = json_decode($this->config['homepageCustomStreamNames'], true);
+				if (array_key_exists($name, $customNames)) {
+					$name = $customNames[$name];
+				}
+			}
+		} catch (Exception $e) {
+			// don't do anythig if it goes wrong, like if the JSON is badly formatted
+		}
+
+		return $name;
+	}
+}

+ 20 - 1
js/custom.js

@@ -1861,4 +1861,23 @@ $(document).on('click', '.imageManagerItem', function() {
 $(document).on('click', '.close-editHomepageItemDiv',function () {
 	$('body').removeAttr('style');
 	$('html').removeAttr('style');
-})
+})
+// Control init of custom plex JSON editor
+$(document).on('click', 'li a[aria-controls="Misc Options"]', function() {
+    var resizeEditor = function(jsonEditor) {
+        const aceEditor = jsonEditor;
+        const newHeight = aceEditor.getSession().getScreenLength() * (aceEditor.renderer.lineHeight + aceEditor.renderer.scrollBar.getWidth());
+        aceEditor.container.style.height = `${newHeight}px`;
+        aceEditor.resize();
+    }
+
+    jsonEditor = ace.edit("homepageCustomStreamNamesAce");
+    var JsonMode = ace.require("ace/mode/javascript").Mode;
+    jsonEditor.session.setMode(new JsonMode());
+    jsonEditor.setTheme("ace/theme/idle_fingers");
+    jsonEditor.setShowPrintMargin(false);
+    jsonEditor.session.on('change', function(delta) {
+        $('#homepageCustomStreamNamesText').val(jsonEditor.getValue());
+        $('#customize-appearance-form-save').removeClass('hidden');
+    });
+}); 

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
js/custom.min.js


Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác