From 8abd987d2bf8de799f626ae89bac04ec03f51d97 Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Thu, 24 Mar 2016 12:34:39 +0100 Subject: [PATCH] New Setting: Choose Plex Server from a list --- default.py | 3 +- resources/language/English/strings.xml | 1 + resources/language/German/strings.xml | 1 + resources/lib/PlexAPI.py | 8 +-- resources/lib/entrypoint.py | 89 ++++++++++++++++++++++---- resources/lib/initialsetup.py | 12 ++-- resources/settings.xml | 1 + 7 files changed, 93 insertions(+), 22 deletions(-) diff --git a/default.py b/default.py index ddc36b00..2c067b39 100644 --- a/default.py +++ b/default.py @@ -70,7 +70,8 @@ class Main: 'reConnect': entrypoint.reConnect, 'delete': entrypoint.deleteItem, 'browseplex': entrypoint.BrowsePlexContent, - 'ondeck': entrypoint.getOnDeck + 'ondeck': entrypoint.getOnDeck, + 'chooseServer': entrypoint.chooseServer } if "/extrafanart" in sys.argv[0]: diff --git a/resources/language/English/strings.xml b/resources/language/English/strings.xml index ffd6f422..25c80998 100644 --- a/resources/language/English/strings.xml +++ b/resources/language/English/strings.xml @@ -392,6 +392,7 @@ On Deck: Append show title to episode On Deck: Append season- and episode-number (e.g. S3E2) Nothing works? Try a full reset! + [COLOR yellow]Choose Plex Server from a list[/COLOR] diff --git a/resources/language/German/strings.xml b/resources/language/German/strings.xml index 09450416..c13163ef 100644 --- a/resources/language/German/strings.xml +++ b/resources/language/German/strings.xml @@ -330,6 +330,7 @@ "Aktuell": Serien- an Episoden-Titel anfügen "Aktuell": Staffel und Episode anfügen (z.B. S3E2) Nichts funktioniert? Setze mal alles zurück! + [COLOR yellow]Plex Server aus Liste auswählen[/COLOR] Plex Home Benutzer abmelden: diff --git a/resources/lib/PlexAPI.py b/resources/lib/PlexAPI.py index a66b576e..81df5a42 100644 --- a/resources/lib/PlexAPI.py +++ b/resources/lib/PlexAPI.py @@ -2168,14 +2168,14 @@ class API(): transcodePath = self.server + \ '/video/:/transcode/universal/start.m3u8?' args = { - 'copyts': 1, + 'protocol': 'hls', # seen in the wild: 'dash', 'http', 'hls' + 'session': str(uuid4()), + 'fastSeek': 1, 'path': path, 'mediaIndex': 0, # Probably refering to XML reply sheme 'partIndex': self.part, - 'protocol': 'hls', # seen in the wild: 'dash', 'http', 'hls' - 'session': str(uuid4()), + # 'copyts': 1, # 'offset': 0, # Resume point - 'fastSeek': 1 } # Seem like PHT to let the PMS use the transcoding profile xargs['X-Plex-Device'] = 'Plex Home Theater' diff --git a/resources/lib/entrypoint.py b/resources/lib/entrypoint.py index ed8cfd31..9253d688 100644 --- a/resources/lib/entrypoint.py +++ b/resources/lib/entrypoint.py @@ -73,36 +73,100 @@ def plexCompanion(fullurl, params): title, "Not knowing what to do for now - no playQueue sent", -1) -def reConnect(): +def chooseServer(): """ - Triggers login to plex.tv and re-authorization + Lets user choose from list of PMS (signs out & signs in) """ string = xbmcaddon.Addon().getLocalizedString - utils.logMsg("entrypoint reConnect", - "Connection resets requested", 0) + utils.logMsg(title, "Choosing PMS server requested, starting", 0) dialog = xbmcgui.Dialog() # Resetting, please wait dialog.notification( heading=addonName, message=string(39207), icon="special://home/addons/plugin.video.plexkodiconnect/icon.png", - time=2000, + time=3000, sound=False) # Pause library sync thread - user needs to be auth in order to sync utils.window('suspend_LibraryThread', value='true') - # Wait max for 5 seconds for all lib scans to finish + # Wait max for 25 seconds for all lib scans to finish counter = 0 while utils.window('emby_dbScan') == 'true': if counter > 500: # Failed to reset PMS and plex.tv connects. Try to restart Kodi. - dialog.ok(heading=addonName, - message=string(39208)) + dialog.ok(addonName, + string(39208)) # Resuming threads, just in case utils.window('suspend_LibraryThread', clear=True) - # Abort reConnection + utils.logMsg(title, "Could not stop library sync, aborting", -1) return counter += 1 xbmc.sleep(50) + utils.logMsg(title, "Successfully stopped library sync", 0) + + # Reset connection details + utils.settings('plex_machineIdentifier', value="") + utils.settings('plex_servername', value="") + utils.settings('https', value="") + utils.settings('ipaddress', value="") + utils.settings('port', value="") + + # Log out currently signed in user: + utils.window('emby_serverStatus', value="401") + + # Above method needs to have run its course! Hence wait + counter = 0 + while utils.window('emby_serverStatus') == "401": + if counter > 100: + dialog.ok(addonName, + string(39208)) + utils.logMsg(title, "Could not sign out, aborting", -1) + return + counter += 1 + xbmc.sleep(50) + # Suspend the user client during procedure + utils.window('suspend_Userclient', value='true') + + import initialsetup + initialsetup.InitialSetup().setup(chooseServer=True) + # Request lib sync to get user view data (e.g. watched/unwatched) + utils.window('plex_runLibScan', value='full') + # Restart user client + utils.window('suspend_Userclient', clear=True) + utils.logMsg(title, "Choosing new PMS complete", 0) + + +def reConnect(): + """ + Triggers login to plex.tv and re-authorization + """ + string = xbmcaddon.Addon().getLocalizedString + utils.logMsg(title, "Connection resets requested", 0) + dialog = xbmcgui.Dialog() + # Resetting, please wait + dialog.notification( + heading=addonName, + message=string(39207), + icon="special://home/addons/plugin.video.plexkodiconnect/icon.png", + time=3000, + sound=False) + # Pause library sync thread - user needs to be auth in order to sync + utils.window('suspend_LibraryThread', value='true') + # Wait max for 25 seconds for all lib scans to finish + counter = 0 + while utils.window('emby_dbScan') == 'true': + if counter > 500: + # Failed to reset PMS and plex.tv connects. Try to restart Kodi. + dialog.ok(addonName, + string(39208)) + # Resuming threads, just in case + utils.window('suspend_LibraryThread', clear=True) + utils.logMsg(title, "Could not stop library sync, aborting", -1) + return + counter += 1 + xbmc.sleep(50) + + utils.logMsg(title, "Successfully stopped library sync", 0) # Delete plex credentials in settings utils.settings('myplexlogin', value="true") @@ -126,9 +190,9 @@ def reConnect(): counter = 0 while utils.window('emby_serverStatus') == "401": if counter > 100: - dialog.ok(heading=addonName, - message=string(39208)) - # Abort reConnection + dialog.ok(addonName, + string(39208)) + utils.logMsg(title, "Could not sign out, aborting", -1) return counter += 1 xbmc.sleep(50) @@ -141,6 +205,7 @@ def reConnect(): utils.window('plex_runLibScan', value='full') # Restart user client utils.window('suspend_Userclient', clear=True) + utils.logMsg(title, "Complete reconnection to plex.tv and PMS complete", 0) def PassPlaylist(xml, resume=None): diff --git a/resources/lib/initialsetup.py b/resources/lib/initialsetup.py index 7d1557a6..559fe2f1 100644 --- a/resources/lib/initialsetup.py +++ b/resources/lib/initialsetup.py @@ -26,7 +26,7 @@ class InitialSetup(): self.userClient = userclient.UserClient() self.plx = PlexAPI.PlexAPI() - def setup(self, forcePlexTV=False): + def setup(self, forcePlexTV=False, chooseServer=False): """ Initial setup. Run once upon startup. Check server, user, direct paths, music, direct stream if not direct @@ -51,7 +51,8 @@ class InitialSetup(): # Optionally sign into plex.tv. Will not be called on very first run # as plexToken will be '' - if (plexToken and myplexlogin == 'true' and forcePlexTV is False): + if (plexToken and myplexlogin == 'true' and forcePlexTV is False + and chooseServer is False): chk = self.plx.CheckConnection('plex.tv', plexToken) # HTTP Error: unauthorized. Token is no longer valid if chk == 401 or chk == 403: @@ -92,7 +93,7 @@ class InitialSetup(): self.logMsg('Failed to update Plex info from plex.tv', -1) # If a Plex server IP has already been set, return. - if server and forcePlexTV is False: + if server and forcePlexTV is False and chooseServer is False: self.logMsg("Server is already set.", 0) self.logMsg("url: %s, Plex machineIdentifier: %s" % (server, serverid), 0) @@ -100,7 +101,8 @@ class InitialSetup(): # If not already retrieved myplex info, optionally let user sign in # to plex.tv. This DOES get called on very first install run - if ((not plexToken and myplexlogin == 'true') or forcePlexTV): + if ((not plexToken and myplexlogin == 'true' and chooseServer is False) + or forcePlexTV): result = self.plx.PlexTvSignInWithPin() if result: plexLogin = result['username'] @@ -231,7 +233,7 @@ class InitialSetup(): # self.logMsg("User opted to use direct paths.", 1) # utils.settings('useDirectPaths', value="1") - if forcePlexTV: + if forcePlexTV is True or chooseServer is True: return goToSettings = False diff --git a/resources/settings.xml b/resources/settings.xml index 8703a687..329175ce 100644 --- a/resources/settings.xml +++ b/resources/settings.xml @@ -2,6 +2,7 @@ +