New Setting: Choose Plex Server from a list

This commit is contained in:
tomkat83 2016-03-24 12:34:39 +01:00
parent eca710f2a9
commit 8abd987d2b
7 changed files with 93 additions and 22 deletions

View file

@ -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]:

View file

@ -392,6 +392,7 @@
<string id="39047">On Deck: Append show title to episode</string>
<string id="39048">On Deck: Append season- and episode-number (e.g. S3E2)</string>
<string id="39049">Nothing works? Try a full reset!</string>
<string id="39050">[COLOR yellow]Choose Plex Server from a list[/COLOR]</string>
<!-- Plex Entrypoint.py -->

View file

@ -330,6 +330,7 @@
<string id="39047">"Aktuell": Serien- an Episoden-Titel anfügen</string>
<string id="39048">"Aktuell": Staffel und Episode anfügen (z.B. S3E2)</string>
<string id="39049">Nichts funktioniert? Setze mal alles zurück!</string>
<string id="39050">[COLOR yellow]Plex Server aus Liste auswählen[/COLOR]</string>
<!-- Plex Entrypoint.py -->
<string id="39200">Plex Home Benutzer abmelden: </string>

View file

@ -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'

View file

@ -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):

View file

@ -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

View file

@ -2,6 +2,7 @@
<settings>
<category label="30014"><!-- Connection -->
<!-- Primary address -->
<setting label="39050" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect?mode=chooseServer)" option="close" /><!-- Choose Plex Server from a list -->
<setting id="ipaddress" label="30000" type="text" default="" />
<setting id="port" label="30030" type="number" default="32400" />
<setting id="https" label="30243" type="bool" default="false" />