More rewiring of connections
This commit is contained in:
parent
72910d79e9
commit
473f6fe58a
8 changed files with 422 additions and 245 deletions
|
@ -48,7 +48,6 @@ class Main:
|
|||
xbmc.log("PlexKodiConnect - Full sys.argv received: %s" % sys.argv)
|
||||
base_url = sys.argv[0]
|
||||
params = urlparse.parse_qs(sys.argv[2][1:])
|
||||
xbmc.log("PlexKodiConnect - Parameter string: %s" % sys.argv[2])
|
||||
try:
|
||||
mode = params['mode'][0]
|
||||
itemid = params.get('id', '')
|
||||
|
@ -80,12 +79,13 @@ class Main:
|
|||
'companion': entrypoint.plexCompanion,
|
||||
'switchuser': entrypoint.switchPlexUser,
|
||||
'deviceid': entrypoint.resetDeviceId,
|
||||
'reConnect': entrypoint.reConnect,
|
||||
'delete': entrypoint.deleteItem,
|
||||
'browseplex': entrypoint.BrowsePlexContent,
|
||||
'ondeck': entrypoint.getOnDeck,
|
||||
'chooseServer': entrypoint.chooseServer,
|
||||
'watchlater': entrypoint.watchlater
|
||||
'watchlater': entrypoint.watchlater,
|
||||
'enterPMS': entrypoint.enterPMS,
|
||||
'togglePlexTV': entrypoint.togglePlexTV
|
||||
}
|
||||
|
||||
if "/extrafanart" in sys.argv[0]:
|
||||
|
|
|
@ -367,7 +367,8 @@
|
|||
<string id="39021">[COLOR yellow]Sync Emby Theme Media to Kodi[/COLOR]</string>
|
||||
<string id="39022">local</string>
|
||||
<string id="39023">Failed to authenticate. Did you login to plex.tv?</string>
|
||||
<string id="39024">[COLOR yellow]Reset PMS and plex.tv connections to re-login[/COLOR]</string>
|
||||
|
||||
|
||||
<string id="39025">Automatically log into plex.tv on startup</string>
|
||||
<string id="39026">Enable constant background sync</string>
|
||||
<string id="39027">Playback Mode</string>
|
||||
|
@ -411,6 +412,11 @@
|
|||
<string id="39064">Recently Added: Also show already watched episodes</string>
|
||||
<string id="39065">Force Transcode HEVC</string>
|
||||
<string id="39066">Recently Added: Also show already watched movies (Refresh Plex playlist/nodes!)</string>
|
||||
<string id="39067">Your current Plex Media Server:</string>
|
||||
<string id="39068">[COLOR yellow]Manually enter Plex Media Server address[/COLOR]</string>
|
||||
<string id="39069">Current address:</string>
|
||||
<string id="39070">Current port:</string>
|
||||
<string id="39071">Current plex.tv status:</string>
|
||||
|
||||
<!-- Plex Entrypoint.py -->
|
||||
<string id="39200">Log-out Plex Home User </string>
|
||||
|
@ -421,10 +427,19 @@
|
|||
<string id="39205">Unable to run the sync, the add-on is not connected to a Plex server.</string>
|
||||
<string id="39206">Plex might lock your account if you fail to log in too many times. Proceed anyway?</string>
|
||||
<string id="39207">Resetting PMS connections, please wait</string>
|
||||
<string id="39208">Failed to reset PMS and plex.tv connects. Try to restart Kodi.</string>
|
||||
<string id="39209">[COLOR yellow]Log-in to plex.tv[/COLOR]</string>
|
||||
<string id="39208">Failed to reset PKC. Try to restart Kodi.</string>
|
||||
<string id="39209">[COLOR yellow]Toggle plex.tv login (sign in or sign out)[/COLOR]</string>
|
||||
<string id="39210">Not yet connected to Plex Server</string>
|
||||
<string id="39211">Watch later</string>
|
||||
<string id="39213">is offline</string>
|
||||
<string id="39214">Even though we signed in to plex.tv, we could not authorize for PMS</string>
|
||||
<string id="39215">Enter your Plex Media Server's IP or URL, Examples are:</string>
|
||||
|
||||
<string id="39217">Does your Plex Media Server support SSL connections? (https instead of http)?</string>
|
||||
<string id="39218">Error contacting PMS</string>
|
||||
<string id="39219">Abort (Yes) or save address anyway (No)?</string>
|
||||
<string id="39220">connected</string>
|
||||
<string id="39221">plex.tv toggle successful</string>
|
||||
|
||||
|
||||
<!-- Plex Artwork.py -->
|
||||
|
|
|
@ -306,7 +306,8 @@
|
|||
<string id="39021">[COLOR yellow]Plex Themes zu Kodi synchronisieren[/COLOR]</string>
|
||||
<string id="39022">lokal</string>
|
||||
<string id="39023">Plex Media Server Authentifizierung fehlgeschlagen. Haben Sie sich bei plex.tv eingeloggt?</string>
|
||||
<string id="39024">[COLOR yellow]PMS und plex.tv Verbindungen zurücksetzen für erneuten Login[/COLOR]</string>
|
||||
|
||||
|
||||
<string id="39025">Automatisch beim Starten bei plex.tv einloggen</string>
|
||||
<string id="39026">Laufende Synchronisierung im Hintergrund aktivieren</string>
|
||||
<string id="39027">Playback Modus</string>
|
||||
|
@ -350,6 +351,10 @@
|
|||
<string id="39064">"Zuletzt hinzugefügt": gesehene Folgen anzeigen</string>
|
||||
<string id="39065">HEVC Codec Transkodierung erzwingen</string>
|
||||
<string id="39066">"Zuletzt hinzugefügt": gesehene Filme anzeigen (Plex Playlisten und Nodes zurücksetzen!)</string>
|
||||
<string id="39067">Aktueller Plex Media Server:</string>
|
||||
<string id="39068">[COLOR yellow]Plex Media Server Adresse manuell eingeben[/COLOR]</string>
|
||||
<string id="39069">Aktuelle Adresse:</string>
|
||||
<string id="39070">Aktueller Port:</string>
|
||||
|
||||
<!-- Plex Entrypoint.py -->
|
||||
<string id="39200">Plex Home Benutzer abmelden: </string>
|
||||
|
@ -360,10 +365,19 @@
|
|||
<string id="39205">Plex Bibliothek kann nicht gescannt werden, da keine Verbindung mit einem Plex Server besteht.</string>
|
||||
<string id="39206">Plex könnte möglicherweise Ihren Account sperren, wenn Sie zu oft versuchen, sich erfolglos anzumelden. Trotzdem fortfahren?</string>
|
||||
<string id="39207">PMS Verbindungen werden zurückgesetzt</string>
|
||||
<string id="39208">PMS und plex.tv Verbindungen konnten nicht zurückgesetzt werden. Bitte versuchen Sie, Kodi neu zu starten, um das Problem zu beheben.</string>
|
||||
<string id="39209">[COLOR yellow]Bei plex.tv einloggen[/COLOR]</string>
|
||||
<string id="39208">PKC konnte nicht zurückgesetzt werden. Bitte versuchen Sie, Kodi neu zu starten, um das Problem zu beheben.</string>
|
||||
<string id="39209">[COLOR yellow]plex.tv Login wechseln (ein- resp. ausloggen)[/COLOR]</string>
|
||||
<string id="39210">Noch nicht mit Plex Server verbunden</string>
|
||||
<string id="39211">Später ansehen</string>
|
||||
<string id="39213">ist offline</string>
|
||||
<string id="39214">Obwohl mit plex.tv verbunden, konnte keine Verbindung hergestellt werden mit</string>
|
||||
<string id="39215">Plex Media Server IP oder URL eingeben. Zum Beispiel:</string>
|
||||
|
||||
<string id="39217">Unterstützt der Plex Media Server sichere SSL Verbindungen (https anstelle von http)?</string>
|
||||
<string id="39218">Error beim Verbinden mit PMS</string>
|
||||
<string id="39219">Abbrechen (Ja) oder PMS Adresse trotzdem speichern (Nein)?</string>
|
||||
<string id="39220">verbunden</string>
|
||||
<string id="39221">plex.tv wechsel OK</string>
|
||||
|
||||
<!-- Plex Artwork.py -->
|
||||
<string id="39250">Alle Plex Bilder in Kodi zwischenzuspeichern kann sehr lange dauern. Möchten Sie wirklich fortfahren?</string>
|
||||
|
|
|
@ -206,6 +206,7 @@ class PlexAPI():
|
|||
utils.settings('plexHomeSize', homeSize)
|
||||
# Let Kodi log into plex.tv on startup from now on
|
||||
utils.settings('myplexlogin', 'true')
|
||||
utils.settings('plex_status', value='Logged in to plex.tv')
|
||||
return result
|
||||
|
||||
def CheckPlexTvSignin(self, identifier):
|
||||
|
@ -290,7 +291,8 @@ class PlexAPI():
|
|||
answer = self.doUtils(url,
|
||||
authenticate=False,
|
||||
headerOptions=headerOptions,
|
||||
verifySSL=verifySSL)
|
||||
verifySSL=verifySSL,
|
||||
timeout=4)
|
||||
if answer is None:
|
||||
self.logMsg("Could not connect to %s" % url, 0)
|
||||
count += 1
|
||||
|
@ -459,8 +461,6 @@ class PlexAPI():
|
|||
while True:
|
||||
try:
|
||||
data, server = GDM.recvfrom(1024)
|
||||
# dprint(__name__, 1, "Received data from {0}", server)
|
||||
# dprint(__name__, 1, "Data received:\n {0}", data)
|
||||
returnData.append({'from': server,
|
||||
'data': data})
|
||||
except socket.timeout:
|
||||
|
@ -469,31 +469,31 @@ class PlexAPI():
|
|||
GDM.close()
|
||||
|
||||
pmsList = {}
|
||||
|
||||
for response in returnData:
|
||||
update = {'ip': response.get('from')[0]}
|
||||
# Check if we had a positive HTTP response
|
||||
if "200 OK" in response.get('data'):
|
||||
for each in response.get('data').split('\n'):
|
||||
# decode response data
|
||||
update['discovery'] = "auto"
|
||||
# update['owned']='1'
|
||||
# update['master']= 1
|
||||
# update['role']='master'
|
||||
if "200 OK" not in response.get('data'):
|
||||
continue
|
||||
for each in response.get('data').split('\n'):
|
||||
# decode response data
|
||||
update['discovery'] = "auto"
|
||||
# update['owned']='1'
|
||||
# update['master']= 1
|
||||
# update['role']='master'
|
||||
|
||||
if "Content-Type:" in each:
|
||||
update['content-type'] = each.split(':')[1].strip()
|
||||
elif "Resource-Identifier:" in each:
|
||||
update['uuid'] = each.split(':')[1].strip()
|
||||
elif "Name:" in each:
|
||||
update['serverName'] = utils.tryDecode(each.split(
|
||||
':')[1].strip())
|
||||
elif "Port:" in each:
|
||||
update['port'] = each.split(':')[1].strip()
|
||||
elif "Updated-At:" in each:
|
||||
update['updated'] = each.split(':')[1].strip()
|
||||
elif "Version:" in each:
|
||||
update['version'] = each.split(':')[1].strip()
|
||||
if "Content-Type:" in each:
|
||||
update['content-type'] = each.split(':')[1].strip()
|
||||
elif "Resource-Identifier:" in each:
|
||||
update['uuid'] = each.split(':')[1].strip()
|
||||
elif "Name:" in each:
|
||||
update['serverName'] = utils.tryDecode(each.split(
|
||||
':')[1].strip())
|
||||
elif "Port:" in each:
|
||||
update['port'] = each.split(':')[1].strip()
|
||||
elif "Updated-At:" in each:
|
||||
update['updated'] = each.split(':')[1].strip()
|
||||
elif "Version:" in each:
|
||||
update['version'] = each.split(':')[1].strip()
|
||||
pmsList[update['uuid']] = update
|
||||
|
||||
return pmsList
|
||||
|
@ -530,6 +530,8 @@ class PlexAPI():
|
|||
for uuid in pmsList:
|
||||
PMS = pmsList[uuid]
|
||||
if PMS['uuid'] in self.g_PMS:
|
||||
self.logMsg('We already know of PMS %s from plex.tv'
|
||||
% PMS['serverName'], 1)
|
||||
continue
|
||||
self.declarePMS(PMS['uuid'], PMS['serverName'], 'http',
|
||||
PMS['ip'], PMS['port'])
|
||||
|
@ -574,7 +576,7 @@ class PlexAPI():
|
|||
|
||||
import Queue
|
||||
queue = Queue.Queue()
|
||||
threads = []
|
||||
threadQueue = []
|
||||
|
||||
maxAgeSeconds = 2*60*60*24
|
||||
for Dir in xml.findall('Device'):
|
||||
|
@ -613,11 +615,30 @@ class PlexAPI():
|
|||
if Con.get('local') != '1':
|
||||
PMS['connections'].append(Con)
|
||||
|
||||
# poke PMS, own thread for each poke
|
||||
t = Thread(target=self.pokePMS,
|
||||
args=(PMS, queue))
|
||||
t.start()
|
||||
threads.append(t)
|
||||
threadQueue.append(t)
|
||||
|
||||
maxThreads = int(utils.settings('imageCacheLimit'))
|
||||
threads = []
|
||||
# poke PMS, own thread for each PMS
|
||||
while(True):
|
||||
# Remove finished threads
|
||||
for t in threads:
|
||||
if not t.isAlive():
|
||||
threads.remove(t)
|
||||
if len(threads) < maxThreads:
|
||||
try:
|
||||
t = threadQueue.pop()
|
||||
except IndexError:
|
||||
# We have done our work
|
||||
break
|
||||
else:
|
||||
t.start()
|
||||
threads.append(t)
|
||||
else:
|
||||
self.logMsg('Waiting for queue spot to poke PMS', 1)
|
||||
xbmc.sleep(50)
|
||||
|
||||
# wait for requests being answered
|
||||
for t in threads:
|
||||
|
@ -628,7 +649,6 @@ class PlexAPI():
|
|||
PMS = queue.get()
|
||||
self.declarePMS(PMS['uuid'], PMS['name'],
|
||||
PMS['protocol'], PMS['ip'], PMS['port'])
|
||||
# dflt: token='', local, owned - updated later
|
||||
self.updatePMSProperty(
|
||||
PMS['uuid'], 'accesstoken', PMS['token'])
|
||||
self.updatePMSProperty(
|
||||
|
@ -643,13 +663,14 @@ class PlexAPI():
|
|||
queue.task_done()
|
||||
|
||||
def pokePMS(self, PMS, queue):
|
||||
if PMS['connections'][0].get('local') == '1':
|
||||
protocol = PMS['connections'][0].get('protocol')
|
||||
address = PMS['connections'][0].get('address')
|
||||
port = PMS['connections'][0].get('port')
|
||||
data = PMS['connections'][0].attrib
|
||||
if data['local'] == '1':
|
||||
protocol = data['protocol']
|
||||
address = data['address']
|
||||
port = data['port']
|
||||
url = '%s://%s:%s' % (protocol, address, port)
|
||||
else:
|
||||
url = PMS['connections'][0].get('uri')
|
||||
url = data['uri']
|
||||
protocol, address, port = url.split(':')
|
||||
address = address.replace('/', '')
|
||||
|
||||
|
@ -659,8 +680,8 @@ class PlexAPI():
|
|||
verifySSL=False,
|
||||
timeout=3)
|
||||
try:
|
||||
xml.attrib
|
||||
except AttributeError:
|
||||
xml.attrib['machineIdentifier']
|
||||
except (AttributeError, KeyError):
|
||||
# No connection, delete the one we just tested
|
||||
del PMS['connections'][0]
|
||||
if len(PMS['connections']) > 0:
|
||||
|
|
|
@ -450,7 +450,8 @@ def GetMachineIdentifier(url):
|
|||
"""
|
||||
xml = downloadutils.DownloadUtils().downloadUrl('%s/identity' % url,
|
||||
authenticate=False,
|
||||
verifySSL=False)
|
||||
verifySSL=False,
|
||||
timeout=4)
|
||||
try:
|
||||
machineIdentifier = xml.attrib['machineIdentifier']
|
||||
except (AttributeError, KeyError):
|
||||
|
|
|
@ -74,52 +74,13 @@ def plexCompanion(fullurl, params):
|
|||
|
||||
def chooseServer():
|
||||
"""
|
||||
Lets user choose from list of PMS (signs out & signs in)
|
||||
Lets user choose from list of PMS
|
||||
"""
|
||||
string = xbmcaddon.Addon().getLocalizedString
|
||||
utils.logMsg(title, "Choosing PMS server requested, starting", 1)
|
||||
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 5 seconds for all lib scans to shutdown
|
||||
counter = 0
|
||||
while utils.window('emby_dbScan') == 'true':
|
||||
if counter > 100:
|
||||
# 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", 1)
|
||||
|
||||
# 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 PMS", -1)
|
||||
return
|
||||
counter += 1
|
||||
xbmc.sleep(50)
|
||||
# Suspend the user client during procedure
|
||||
utils.window('suspend_Userclient', value='true')
|
||||
|
||||
import initialsetup
|
||||
setup = initialsetup.InitialSetup()
|
||||
server = setup.PickPMS()
|
||||
server = setup.PickPMS(showDialog=True)
|
||||
if server is None:
|
||||
utils.logMsg('We did not connect to a new PMS, aborting', -1)
|
||||
utils.window('suspend_Userclient', clear=True)
|
||||
|
@ -127,85 +88,45 @@ def chooseServer():
|
|||
return
|
||||
|
||||
setup.WritePMStoSettings(server)
|
||||
# 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)
|
||||
# And do NOT clear suspend_LibraryThread flag, that needs to be done in
|
||||
# service.py
|
||||
|
||||
if not __LogOut():
|
||||
return
|
||||
|
||||
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(
|
||||
# Log in again
|
||||
__LogIn()
|
||||
utils.logMsg(title, "Choosing new PMS complete", 1)
|
||||
# '<PMS> connected'
|
||||
xbmcgui.Dialog().notification(
|
||||
heading=addonName,
|
||||
message=string(39207),
|
||||
message='%s %s' % (server['name'],
|
||||
xbmcaddon.Addon().getLocalizedString(39220)),
|
||||
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")
|
||||
utils.settings('plexLogin', value="")
|
||||
utils.settings('plexToken', value=""),
|
||||
utils.settings('plexid', value="")
|
||||
utils.settings('plexHomeSize', value="1")
|
||||
utils.settings('plexAvatar', value="")
|
||||
def togglePlexTV():
|
||||
if utils.settings('plexToken'):
|
||||
utils.logMsg(title, 'Reseting plex.tv credentials in settings', 1)
|
||||
utils.settings('plexLogin', value="")
|
||||
utils.settings('plexToken', value=""),
|
||||
utils.settings('plexid', value="")
|
||||
utils.settings('plexHomeSize', value="1")
|
||||
utils.settings('plexAvatar', value="")
|
||||
utils.settings('plex_status', value="Not logged in to plex.tv")
|
||||
|
||||
# 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(forcePlexTV=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, "Complete reconnection to plex.tv and PMS complete", 0)
|
||||
utils.window('plex_token', clear=True)
|
||||
utils.window('plex_username', clear=True)
|
||||
else:
|
||||
utils.logMsg(title, 'Login to plex.tv', 1)
|
||||
import initialsetup
|
||||
initialsetup.InitialSetup().PlexTVSignIn()
|
||||
xbmcgui.Dialog().notification(
|
||||
heading=addonName,
|
||||
message=xbmcaddon.Addon().getLocalizedString(39221),
|
||||
icon="special://home/addons/plugin.video.plexkodiconnect/icon.png",
|
||||
time=3000,
|
||||
sound=False)
|
||||
|
||||
|
||||
def PassPlaylist(xml, resume=None):
|
||||
|
@ -565,30 +486,15 @@ def switchPlexUser():
|
|||
# Delete any userimages. Since there's always only 1 user: position = 0
|
||||
# position = 0
|
||||
# utils.window('EmbyAdditionalUserImage.%s' % position, clear=True)
|
||||
utils.logMsg("entrypoint switchPlexUser",
|
||||
"Plex home user switch requested", 0)
|
||||
# Pause library sync thread - user needs to be auth in order to sync
|
||||
utils.window('suspend_LibraryThread', value='true')
|
||||
# Wait to ensure that any sync already going on has finished
|
||||
counter = 0
|
||||
while utils.window('emby_dbScan') == 'true':
|
||||
if counter > 100:
|
||||
# Something went wrong, aborting
|
||||
# Resuming threads, just in case
|
||||
utils.window('suspend_LibraryThread', clear=True)
|
||||
# Abort reConnection
|
||||
return
|
||||
counter += 1
|
||||
xbmc.sleep(50)
|
||||
utils.logMsg(title, "Plex home user switch requested", 0)
|
||||
if not __LogOut(user=True):
|
||||
return
|
||||
|
||||
# First remove playlists
|
||||
# First remove playlists of old user
|
||||
utils.deletePlaylists()
|
||||
# Remove video nodes
|
||||
utils.deleteNodes()
|
||||
# Log out currently signed in user:
|
||||
utils.window('emby_serverStatus', value="401")
|
||||
# Request lib sync to get user view data (e.g. watched/unwatched)
|
||||
utils.window('plex_runLibScan', value='full')
|
||||
__LogIn()
|
||||
|
||||
|
||||
##### THEME MUSIC/VIDEOS #####
|
||||
|
@ -1707,3 +1613,122 @@ def watchlater():
|
|||
handle=int(sys.argv[1]),
|
||||
cacheToDisc=True if utils.settings('enableTextureCache') == 'true'
|
||||
else False)
|
||||
|
||||
|
||||
def enterPMS():
|
||||
"""
|
||||
Opens dialogs for the user the plug in the PMS details
|
||||
"""
|
||||
dialog = xbmcgui.Dialog()
|
||||
string = xbmcaddon.Addon().getLocalizedString
|
||||
# "Enter your Plex Media Server's IP or URL. Examples are:"
|
||||
dialog.ok(addonName,
|
||||
string(39215),
|
||||
'192.168.1.2',
|
||||
'plex.myServer.org')
|
||||
ip = dialog.input("Enter PMS IP or URL")
|
||||
if ip == '':
|
||||
return
|
||||
port = dialog.input("Enter PMS port", '32400', xbmcgui.INPUT_NUMERIC)
|
||||
if port == '':
|
||||
return
|
||||
url = '%s:%s' % (ip, port)
|
||||
# "Does your Plex Media Server support SSL connections?
|
||||
# (https instead of http)"
|
||||
https = dialog.yesno(addonName, string(39217))
|
||||
if https:
|
||||
url = 'https://%s' % url
|
||||
else:
|
||||
url = 'http://%s' % url
|
||||
https = 'true' if https else 'false'
|
||||
|
||||
machineIdentifier = PlexFunctions.GetMachineIdentifier(url)
|
||||
if machineIdentifier is None:
|
||||
# "Error contacting url
|
||||
# Abort (Yes) or save address anyway (No)"
|
||||
if dialog.yesno(addonName, '%s %s. %s'
|
||||
% (string(39218), url, string(39219))):
|
||||
return
|
||||
else:
|
||||
utils.settings('plex_machineIdentifier', '')
|
||||
else:
|
||||
utils.settings('plex_machineIdentifier', machineIdentifier)
|
||||
utils.logMsg(title, 'Setting new PMS to: https %s, ip %s, port %s, '
|
||||
'machineIdentifier: %s'
|
||||
% (https, ip, port, machineIdentifier), 1)
|
||||
utils.settings('https', value=https)
|
||||
utils.settings('ipaddress', value=ip)
|
||||
utils.settings('port', value=port)
|
||||
|
||||
# Sign out to trigger new login
|
||||
if __LogOut():
|
||||
# Only login again if logout was successful
|
||||
__LogIn()
|
||||
|
||||
|
||||
def __LogIn(user=False):
|
||||
"""
|
||||
Resets (clears) window properties to enable (re-)login:
|
||||
suspend_Userclient
|
||||
plex_runLibScan: set to 'full' to trigger lib sync
|
||||
|
||||
user=False: user has NOT been signed out before
|
||||
suspend_LibraryThread is cleared in service.py if user was signed out!
|
||||
"""
|
||||
utils.window('plex_runLibScan', value='full')
|
||||
# Restart user client
|
||||
utils.window('suspend_Userclient', clear=True)
|
||||
if user is False:
|
||||
utils.window('suspend_LibraryThread', clear=True)
|
||||
|
||||
|
||||
def __LogOut(user=False):
|
||||
"""
|
||||
Finishes lib scans, logs out user. The following window attributes are set:
|
||||
suspend_LibraryThread: 'true'
|
||||
If user=True, then the user will also be logged out
|
||||
suspend_Userclient: 'true'
|
||||
|
||||
Returns True if successfully signed out, False otherwise
|
||||
"""
|
||||
string = xbmcaddon.Addon().getLocalizedString
|
||||
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
|
||||
utils.window('suspend_LibraryThread', value='true')
|
||||
# Wait max for 10 seconds for all lib scans to shutdown
|
||||
counter = 0
|
||||
while utils.window('emby_dbScan') == 'true':
|
||||
if counter > 200:
|
||||
# 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 False
|
||||
counter += 1
|
||||
xbmc.sleep(50)
|
||||
utils.logMsg(title, "Successfully stopped library sync", 1)
|
||||
|
||||
if user:
|
||||
# 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:
|
||||
# 'Failed to reset PKC. Try to restart Kodi.'
|
||||
dialog.ok(addonName, string(39208))
|
||||
utils.logMsg(title, "Could not sign out user, aborting", -1)
|
||||
return False
|
||||
counter += 1
|
||||
xbmc.sleep(50)
|
||||
# Suspend the user client during procedure
|
||||
utils.window('suspend_Userclient', value='true')
|
||||
return True
|
||||
|
|
|
@ -59,25 +59,31 @@ class InitialSetup():
|
|||
def CheckPlexTVSignIn(self):
|
||||
"""
|
||||
Checks existing connection to plex.tv. If not, triggers sign in
|
||||
|
||||
Returns True if signed in, False otherwise
|
||||
"""
|
||||
chk = self.plx.CheckConnection('plex.tv', self.plexToken)
|
||||
answer = True
|
||||
chk = self.plx.CheckConnection('plex.tv', token=self.plexToken)
|
||||
if chk in (401, 403):
|
||||
# HTTP Error: unauthorized. Token is no longer valid
|
||||
self.logMsg('plex.tv connection returned HTTP %s' % chk, 1)
|
||||
self.logMsg('plex.tv connection returned HTTP %s' % str(chk), 1)
|
||||
# Delete token in the settings
|
||||
utils.settings('plexToken', value='')
|
||||
utils.settings('plexLogin', value='')
|
||||
# Could not login, please try again
|
||||
self.dialog.ok(self.addonName,
|
||||
self.string(39009))
|
||||
self.PlexTVSignIn()
|
||||
answer = self.PlexTVSignIn()
|
||||
elif chk is False or chk >= 400:
|
||||
# Problems connecting to plex.tv. Network or internet issue?
|
||||
self.logMsg('plex.tv connection returned HTTP %s'
|
||||
% str(chk), 1)
|
||||
self.logMsg('Problems connecting to plex.tv; connection returned '
|
||||
'HTTP %s' % str(chk), 1)
|
||||
self.dialog.ok(self.addonName,
|
||||
self.string(39010))
|
||||
answer = False
|
||||
else:
|
||||
self.logMsg('plex.tv connection with token successful', 1)
|
||||
utils.settings('plex_status', value='Logged in to plex.tv')
|
||||
# Refresh the info from Plex.tv
|
||||
xml = self.doUtils('https://plex.tv/users/account',
|
||||
authenticate=False,
|
||||
|
@ -94,6 +100,7 @@ class InitialSetup():
|
|||
utils.settings(
|
||||
'plexHomeSize', value=xml.attrib.get('homeSize', '1'))
|
||||
self.logMsg('Updated Plex info from plex.tv', 1)
|
||||
return answer
|
||||
|
||||
def CheckPMS(self):
|
||||
"""
|
||||
|
@ -106,7 +113,8 @@ class InitialSetup():
|
|||
not set before
|
||||
"""
|
||||
answer = True
|
||||
chk = self.plx.CheckConnection(self.server, verifySSL=False)
|
||||
chk = self.plx.CheckConnection(self.server,
|
||||
verifySSL=False)
|
||||
if chk is False:
|
||||
self.logMsg('Could not reach PMS %s' % self.server, -1)
|
||||
answer = False
|
||||
|
@ -129,9 +137,41 @@ class InitialSetup():
|
|||
answer = False
|
||||
return answer
|
||||
|
||||
def PickPMS(self):
|
||||
def __getServerList(self):
|
||||
"""
|
||||
Searches for PMS and lets user pick one
|
||||
Returns a list of servers from GDM and possibly plex.tv
|
||||
"""
|
||||
self.plx.discoverPMS(xbmc.getIPAddress(),
|
||||
plexToken=self.plexToken)
|
||||
serverlist = self.plx.returnServerList(self.plx.g_PMS)
|
||||
self.logMsg('PMS serverlist: %s' % serverlist, 2)
|
||||
return serverlist
|
||||
|
||||
def __checkServerCon(self, server):
|
||||
"""
|
||||
Checks for server's connectivity. Returns CheckConnection result
|
||||
"""
|
||||
# Re-direct via plex if remote - will lead to the correct SSL
|
||||
# certificate
|
||||
if server['local'] == '1':
|
||||
url = '%s://%s:%s' \
|
||||
% (server['scheme'], server['ip'], server['port'])
|
||||
# Deactive SSL verification if the server is local!
|
||||
verifySSL = False
|
||||
else:
|
||||
url = server['baseURL']
|
||||
verifySSL = None
|
||||
chk = self.plx.CheckConnection(url,
|
||||
token=server['accesstoken'],
|
||||
verifySSL=verifySSL)
|
||||
return chk
|
||||
|
||||
def PickPMS(self, showDialog=False):
|
||||
"""
|
||||
Searches for PMS in local Lan and optionally (if self.plexToken set)
|
||||
also on plex.tv
|
||||
showDialog=True: let the user pick one
|
||||
showDialog=False: automatically pick PMS based on machineIdentifier
|
||||
|
||||
Returns the picked PMS' detail as a dict:
|
||||
{
|
||||
|
@ -150,24 +190,98 @@ class InitialSetup():
|
|||
|
||||
or None if unsuccessful
|
||||
"""
|
||||
server = None
|
||||
# If no server is set, let user choose one
|
||||
if not self.server or not self.serverid:
|
||||
showDialog = True
|
||||
if showDialog is True:
|
||||
server = self.__UserPickPMS()
|
||||
else:
|
||||
server = self.__AutoPickPMS()
|
||||
return server
|
||||
|
||||
def __AutoPickPMS(self):
|
||||
"""
|
||||
Will try to pick PMS based on machineIdentifier saved in file settings
|
||||
but only once
|
||||
|
||||
Returns server or None if unsuccessful
|
||||
"""
|
||||
httpsUpdated = False
|
||||
checkedPlexTV = False
|
||||
server = None
|
||||
while True:
|
||||
if httpsUpdated is False:
|
||||
serverlist = self.__getServerList()
|
||||
for item in serverlist:
|
||||
if item.get('machineIdentifier') == self.serverid:
|
||||
server = item
|
||||
if server is None:
|
||||
name = utils.settings('plex_servername')
|
||||
self.logMsg('The PMS you have used before with a unique '
|
||||
'machineIdentifier of %s and name %s is '
|
||||
'offline' % (self.serverid, name), -1)
|
||||
# "PMS xyz offline"
|
||||
self.dialog.notification(self.addonName,
|
||||
'%s %s'
|
||||
% (name, self.string(39213)),
|
||||
xbmcgui.NOTIFICATION_ERROR,
|
||||
7000,
|
||||
False)
|
||||
return
|
||||
chk = self.__checkServerCon(server)
|
||||
if chk == 504 and httpsUpdated is False:
|
||||
# Not able to use HTTP, try HTTPs for now
|
||||
server['scheme'] = 'https'
|
||||
httpsUpdated = True
|
||||
continue
|
||||
if chk == 401:
|
||||
self.logMsg('Not yet authorized for Plex server %s'
|
||||
% server['name'], -1)
|
||||
if self.CheckPlexTVSignIn() is True:
|
||||
if checkedPlexTV is False:
|
||||
# Try again
|
||||
checkedPlexTV = True
|
||||
httpsUpdated = False
|
||||
continue
|
||||
else:
|
||||
self.logMsg('Not authorized even though we are signed '
|
||||
' in to plex.tv correctly', -1)
|
||||
self.dialog.ok(self.addonName, '%s %s'
|
||||
% self.string(39214) + server['name'])
|
||||
return
|
||||
else:
|
||||
return
|
||||
# Problems connecting
|
||||
elif chk >= 400 or chk is False:
|
||||
self.logMsg('Problems connecting to server %s. chk is %s'
|
||||
% (server['name'], chk), -1)
|
||||
return
|
||||
self.logMsg('We found a server to automatically connect to: %s'
|
||||
% server['name'], 1)
|
||||
return server
|
||||
|
||||
def __UserPickPMS(self):
|
||||
"""
|
||||
Lets user pick his/her PMS from a list
|
||||
|
||||
Returns server or None if unsuccessful
|
||||
"""
|
||||
httpsUpdated = False
|
||||
while True:
|
||||
if httpsUpdated is False:
|
||||
# Populate g_PMS variable with the found Plex servers
|
||||
self.plx.discoverPMS(xbmc.getIPAddress(),
|
||||
plexToken=self.plexToken)
|
||||
serverlist = self.plx.returnServerList(self.plx.g_PMS)
|
||||
self.logMsg('PMS serverlist: %s' % serverlist, 2)
|
||||
serverlist = self.__getServerList()
|
||||
# Exit if no servers found
|
||||
if len(serverlist) == 0:
|
||||
self.logMsg('No plex media servers found!', -1)
|
||||
self.dialog.ok(self.addonName, self.string(39011))
|
||||
server = None
|
||||
break
|
||||
return
|
||||
# Get a nicer list
|
||||
dialoglist = []
|
||||
for server in serverlist:
|
||||
if server['local'] == '1':
|
||||
# server is in the same network as client. Add "local"
|
||||
# server is in the same network as client.
|
||||
# Add"local"
|
||||
msg = self.string(39022)
|
||||
else:
|
||||
# Add 'remote'
|
||||
|
@ -183,22 +297,9 @@ class InitialSetup():
|
|||
% (server['name'], msg))
|
||||
# Let user pick server from a list
|
||||
resp = self.dialog.select(self.string(39012), dialoglist)
|
||||
|
||||
server = serverlist[resp]
|
||||
# Re-direct via plex if remote - will lead to the correct SSL
|
||||
# certificate
|
||||
if server['local'] == '1':
|
||||
url = '%s://%s:%s' \
|
||||
% (server['scheme'], server['ip'], server['port'])
|
||||
else:
|
||||
url = server['baseURL']
|
||||
# Deactive SSL verification if the server is local!
|
||||
if server['local'] == '1':
|
||||
verifySSL = False
|
||||
else:
|
||||
verifySSL = None
|
||||
chk = self.plx.CheckConnection(url,
|
||||
server['accesstoken'],
|
||||
verifySSL=verifySSL)
|
||||
chk = self.__checkServerCon(server)
|
||||
if chk == 504 and httpsUpdated is False:
|
||||
# Not able to use HTTP, try HTTPs for now
|
||||
serverlist[resp]['scheme'] = 'https'
|
||||
|
@ -206,15 +307,15 @@ class InitialSetup():
|
|||
continue
|
||||
httpsUpdated = False
|
||||
if chk == 401:
|
||||
# Not yet authorized for Plex server
|
||||
self.logMsg('Not yet authorized for Plex server %s'
|
||||
% server['name'], -1)
|
||||
# Please sign in to plex.tv
|
||||
self.dialog.ok(self.addonName,
|
||||
self.string(39013) + server['name'],
|
||||
self.string(39014))
|
||||
if self.PlexTVSignIn() is False:
|
||||
# Exit while loop if user cancels
|
||||
server = None
|
||||
break
|
||||
return
|
||||
# Problems connecting
|
||||
elif chk >= 400 or chk is False:
|
||||
# Problems connecting to server. Pick another server?
|
||||
|
@ -222,12 +323,10 @@ class InitialSetup():
|
|||
self.string(39015))
|
||||
# Exit while loop if user chooses No
|
||||
if not answ:
|
||||
server = None
|
||||
break
|
||||
return
|
||||
# Otherwise: connection worked!
|
||||
else:
|
||||
break
|
||||
return server
|
||||
return server
|
||||
|
||||
def WritePMStoSettings(self, server):
|
||||
"""
|
||||
|
@ -278,7 +377,7 @@ class InitialSetup():
|
|||
% (server['machineIdentifier'], server['ip'],
|
||||
server['port'], server['scheme']), 0)
|
||||
|
||||
def setup(self, forcePlexTV=False, chooseServer=False):
|
||||
def setup(self):
|
||||
"""
|
||||
Initial setup. Run once upon startup.
|
||||
|
||||
|
@ -291,17 +390,18 @@ class InitialSetup():
|
|||
|
||||
# Optionally sign into plex.tv. Will not be called on very first run
|
||||
# as plexToken will be ''
|
||||
utils.settings('plex_status', value='Not logged in to plex.tv')
|
||||
if self.plexToken and self.myplexlogin:
|
||||
self.CheckPlexTVSignIn()
|
||||
|
||||
# If a Plex server IP has already been set
|
||||
# return only if the right machine identifier is found
|
||||
getNewPMS = False
|
||||
getNewIP = False
|
||||
if self.server:
|
||||
self.logMsg("PMS is already set: %s. Checking now..."
|
||||
% self.server, 0)
|
||||
getNewPMS = not self.CheckPMS()
|
||||
if getNewPMS is False:
|
||||
getNewIP = not self.CheckPMS()
|
||||
if getNewIP is False:
|
||||
self.logMsg("Using PMS %s with machineIdentifier %s"
|
||||
% (self.server, self.serverid), 0)
|
||||
return
|
||||
|
@ -312,16 +412,21 @@ class InitialSetup():
|
|||
self.PlexTVSignIn()
|
||||
|
||||
server = self.PickPMS()
|
||||
if server is None:
|
||||
# Enter Kodi settings instead
|
||||
xbmc.executebuiltin('Addon.OpenSettings(%s)' % self.addonId)
|
||||
if server is not None:
|
||||
goToSettings = False
|
||||
# Write our chosen server to Kodi settings file
|
||||
self.WritePMStoSettings(server)
|
||||
else:
|
||||
goToSettings = True
|
||||
|
||||
# User already answered the installation questions
|
||||
if utils.settings('InstallQuestionsAnswered') == 'true':
|
||||
if goToSettings:
|
||||
xbmc.executebuiltin(
|
||||
'Addon.OpenSettings(plugin.video.plexkodiconnect)')
|
||||
return
|
||||
|
||||
# Write our chosen server to Kodi settings file
|
||||
self.WritePMStoSettings(server)
|
||||
|
||||
# Additional settings where the user needs to choose
|
||||
goToSettings = False
|
||||
# Direct paths (\\NAS\mymovie.mkv) or addon (http)?
|
||||
if dialog.yesno(self.addonName,
|
||||
string(39027),
|
||||
|
@ -365,10 +470,13 @@ class InitialSetup():
|
|||
|
||||
# Download additional art from FanArtTV
|
||||
if dialog.yesno(heading=self.addonName,
|
||||
line1=string(39016)):
|
||||
line1=string(39061)):
|
||||
self.logMsg("User opted to use FanArtTV", 1)
|
||||
utils.settings('FanartTV', value="true")
|
||||
|
||||
# Make sure that we only ask these questions upon first installation
|
||||
utils.settings('InstallQuestionsAnswered', value='true')
|
||||
|
||||
if goToSettings is False:
|
||||
# Open Settings page now? You will need to restart!
|
||||
goToSettings = dialog.yesno(heading=self.addonName,
|
||||
|
|
|
@ -1,37 +1,30 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<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 label="39068" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect?mode=enterPMS)" option="close" /><!-- Manually enter Plex Media Server IP -->
|
||||
<setting id="plex_servername" label="39067" type="text" default="" enable="false" /><!-- Your current PMS server: -->
|
||||
<setting id="ipaddress" label="39069" type="text" default="" enable="false" /><!-- Current address: -->
|
||||
<setting id="port" label="39070" type="text" default="" enable="false" /><!-- Current port: -->
|
||||
<setting id="plex_serverowned" label="30031" type="bool" default="true" /><!-- I own this PMS -->
|
||||
<setting id="https" label="30243" type="bool" default="false" />
|
||||
<setting id="sslverify" subsetting="true" label="30500" type="bool" default="false" visible="eq(-1,true)" />
|
||||
<setting id="sslcert" subsetting="true" label="30501" type="file" default="None" visible="eq(-2,true)" />
|
||||
<!-- Secondary address -->
|
||||
<setting id="altip" label="30502" type="bool" default="false" visible="false"/>
|
||||
<setting id="secondipaddress" subsetting="true" label="30503" type="text" default="" visible="eq(-1,true)" />
|
||||
<setting id="secondport" subsetting="true" label="30030" type="number" default="8096" visible="eq(-2,true)" />
|
||||
<setting id="secondhttps" subsetting="true" label="30243" type="bool" default="false" visible="eq(-3,true)" />
|
||||
<setting id="secondsslverify" subsetting="true" label="30500" type="bool" default="false" visible="eq(-1,true)" />
|
||||
<setting id="secondsslcert" subsetting="true" label="30501" type="file" default="None" visible="eq(-2,true)" />
|
||||
<!-- User settings -->
|
||||
<setting type="sep" />
|
||||
|
||||
<setting type="sep" text=""/>
|
||||
|
||||
<setting id="enforceUserLogin" label="30536" type="bool" default="false" />
|
||||
|
||||
<setting label="30505" type="action" visible="eq(1,) + !eq(-15,)" action="RunPlugin(plugin://plugin.video.plexkodiconnect?mode=resetauth)" option="close" />
|
||||
<setting label="30517" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect?mode=passwords)" option="close" /><!-- Network credentials -->
|
||||
<setting label="30505" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect?mode=resetauth)" option="close" /><!-- reset connection attempts -->
|
||||
<setting id="accessToken" type="text" visible="false" default="" />
|
||||
<setting id="pathsub" type="bool" visible="false" default="false" />
|
||||
<setting label="39024" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect?mode=reConnect)" option="close" />
|
||||
</category>
|
||||
|
||||
<category label="plex.tv"><!-- plex.tv -->
|
||||
<!-- Primary address -->
|
||||
<setting id="plex_status" label="39071" type="text" default="Not logged in to plex.tv" enable="false" /><!-- Current plex.tv status: -->
|
||||
<setting type="sep" text=""/>
|
||||
|
||||
<setting id="myplexlogin" label="39025" type="bool" default="true" /> <!-- Log into plex.tv on startup -->
|
||||
<setting label="39209" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect?mode=reConnect)" option="close" />
|
||||
<setting label="39209" type="action" action="RunPlugin(plugin://plugin.video.plexkodiconnect?mode=togglePlexTV)" option="close" />
|
||||
|
||||
<setting id="plexLogin" label="plex.tv username" type="text" default="" visible="false" />
|
||||
<setting id="plexhome" label="Plex home in use" type="bool" default="" visible="false" />
|
||||
|
|
Loading…
Reference in a new issue