From 63955c846f1e6b2b5ce8b33caf25052149c50c86 Mon Sep 17 00:00:00 2001 From: Tony B Date: Tue, 30 Aug 2016 22:11:56 -0700 Subject: [PATCH] Better handling of PlexToken, removed pref for port --- Contents/Code/__init__.py | 21 ++++++++++++++------- Contents/Code/plexshufflebyalbum.py | 3 ++- Contents/DefaultPrefs.json | 6 ------ 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index f7e518a..a5e67ee 100644 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -18,15 +18,22 @@ def Start(): DirectoryObject.thumb = R(ICON) Dict['server_ip'] = 'localhost' - Dict['plextoken'] = os.environ['PLEXTOKEN'] - + Dict['server_port'] = os.environ['PLEXSERVERPORT'] + + if 'PLEXTOKEN' in os.environ: + Dict['plextoken'] = os.environ['PLEXTOKEN'] + else: + Dict['plextoken'] = None + + Log("Plex Token: {}".format(Dict['token'])) + HTTP.CacheTime = 0 #################################################################################################### def MainMenu(): - Dict['music_sections'] = get_music_sections(Dict['server_ip'], Prefs['server_port'], Dict['plextoken']) - clients = get_clients(Dict['server_ip'], Prefs['server_port'], Dict['plextoken']) + Dict['music_sections'] = get_music_sections(Dict['server_ip'], Dict['server_port'], Dict['plextoken']) + clients = get_clients(Dict['server_ip'], Dict['server_port'], Dict['plextoken']) # Plex web clients don't seem to work clients2 = [] @@ -56,7 +63,7 @@ def GeneratePlaylist(): return section_selection_menu() else: Dict['playlist'] = generate_playlist(Dict['server_ip'], - Prefs['server_port'], + Dict['server_port'], Dict['plextoken'], Dict['music_sections'][0], Prefs['playlist_name'], @@ -96,7 +103,7 @@ def SectionSelection(idx): idx=int(idx) Dict['playlist'] = generate_playlist(Dict['server_ip'], - Prefs['server_port'], + Dict['server_port'], Dict['plextoken'], Dict['music_sections'][idx], Prefs['playlist_name'], @@ -109,7 +116,7 @@ def ClientSelection(idx): #TODO: figure out server IP?? Log.Debug("ShuffleByAlbum: Going to play on client #{} {})".format(idx, Dict['clients'][idx]['address'])) play_on_client(Dict['server_ip'], - Prefs['server_port'], + Dict['server_port'], Dict['plextoken'], Dict['clients'][idx], Dict['playlist']) diff --git a/Contents/Code/plexshufflebyalbum.py b/Contents/Code/plexshufflebyalbum.py index 0b6e3de..7eaf772 100644 --- a/Contents/Code/plexshufflebyalbum.py +++ b/Contents/Code/plexshufflebyalbum.py @@ -35,7 +35,8 @@ def query(self, path, method): headers = dict() headers['Accept'] = 'application/json' headers['X-Plex-Client-Identifier'] = '77777777-abab-4bc3-86a6-809c4901fb87' - headers['X-Plex-Token'] = self.token + if self.token: + headers['X-Plex-Token'] = self.token r = http_comm(url, method, headers) diff --git a/Contents/DefaultPrefs.json b/Contents/DefaultPrefs.json index c9b14ae..5a68e22 100644 --- a/Contents/DefaultPrefs.json +++ b/Contents/DefaultPrefs.json @@ -10,11 +10,5 @@ "type": "text", "label": "Playlist Name", "default": "ShuffleByAlbum", - }, - { - "id": "server_port", - "type": "text", - "label": "Server Port", - "default": "32400" } ]