Better inform the user if problems arise with manual PMS IP input
This commit is contained in:
parent
1071d75857
commit
01609e4d72
5 changed files with 119 additions and 39 deletions
|
@ -464,6 +464,11 @@ msgctxt "#30502"
|
||||||
msgid "Sync Plex artwork from the PMS (recommended)"
|
msgid "Sync Plex artwork from the PMS (recommended)"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
# Message shown if SSL HTTPS certificate fails
|
||||||
|
msgctxt "#30503"
|
||||||
|
msgid "SSL certificate failed to validate. Please check {0} for solutions."
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
# PKC Settings, category name
|
# PKC Settings, category name
|
||||||
msgctxt "#30506"
|
msgctxt "#30506"
|
||||||
msgid "Sync Options"
|
msgid "Sync Options"
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
from __future__ import absolute_import, division, unicode_literals
|
from __future__ import absolute_import, division, unicode_literals
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
import requests
|
import requests
|
||||||
|
import requests.exceptions as exceptions
|
||||||
|
|
||||||
from . import utils, clientinfo, app
|
from . import utils, clientinfo, app
|
||||||
|
|
||||||
|
@ -114,7 +115,7 @@ class DownloadUtils():
|
||||||
def downloadUrl(self, url, action_type="GET", postBody=None,
|
def downloadUrl(self, url, action_type="GET", postBody=None,
|
||||||
parameters=None, authenticate=True, headerOptions=None,
|
parameters=None, authenticate=True, headerOptions=None,
|
||||||
verifySSL=True, timeout=None, return_response=False,
|
verifySSL=True, timeout=None, return_response=False,
|
||||||
headerOverride=None):
|
headerOverride=None, reraise=False):
|
||||||
"""
|
"""
|
||||||
Override SSL check with verifySSL=False
|
Override SSL check with verifySSL=False
|
||||||
|
|
||||||
|
@ -172,39 +173,55 @@ class DownloadUtils():
|
||||||
r = self._doDownload(s, action_type, **kwargs)
|
r = self._doDownload(s, action_type, **kwargs)
|
||||||
|
|
||||||
# THE EXCEPTIONS
|
# THE EXCEPTIONS
|
||||||
except requests.exceptions.SSLError as e:
|
except exceptions.SSLError as e:
|
||||||
LOG.warn("Invalid SSL certificate for: %s", url)
|
LOG.warn("Invalid SSL certificate for: %s", url)
|
||||||
LOG.warn(e)
|
LOG.warn(e)
|
||||||
|
if reraise:
|
||||||
|
raise
|
||||||
|
|
||||||
except requests.exceptions.ConnectionError as e:
|
except exceptions.ConnectionError as e:
|
||||||
# Connection error
|
# Connection error
|
||||||
LOG.warn("Server unreachable at: %s", url)
|
LOG.warn("Server unreachable at: %s", url)
|
||||||
LOG.warn(e)
|
LOG.warn(e)
|
||||||
|
if reraise:
|
||||||
|
raise
|
||||||
|
|
||||||
except requests.exceptions.Timeout as e:
|
except exceptions.Timeout as e:
|
||||||
LOG.warn("Server timeout at: %s", url)
|
LOG.warn("Server timeout at: %s", url)
|
||||||
LOG.warn(e)
|
LOG.warn(e)
|
||||||
|
if reraise:
|
||||||
|
raise
|
||||||
|
|
||||||
except requests.exceptions.HTTPError as e:
|
except exceptions.HTTPError as e:
|
||||||
LOG.warn('HTTP Error at %s', url)
|
LOG.warn('HTTP Error at %s', url)
|
||||||
LOG.warn(e)
|
LOG.warn(e)
|
||||||
|
if reraise:
|
||||||
|
raise
|
||||||
|
|
||||||
except requests.exceptions.TooManyRedirects as e:
|
except exceptions.TooManyRedirects as e:
|
||||||
LOG.warn("Too many redirects connecting to: %s", url)
|
LOG.warn("Too many redirects connecting to: %s", url)
|
||||||
LOG.warn(e)
|
LOG.warn(e)
|
||||||
|
if reraise:
|
||||||
|
raise
|
||||||
|
|
||||||
except requests.exceptions.RequestException as e:
|
except exceptions.RequestException as e:
|
||||||
LOG.warn("Unknown error connecting to: %s", url)
|
LOG.warn("Unknown error connecting to: %s", url)
|
||||||
LOG.warn(e)
|
LOG.warn(e)
|
||||||
|
if reraise:
|
||||||
|
raise
|
||||||
|
|
||||||
except SystemExit:
|
except SystemExit:
|
||||||
LOG.info('SystemExit detected, aborting download')
|
LOG.info('SystemExit detected, aborting download')
|
||||||
self.stopSession()
|
self.stopSession()
|
||||||
|
if reraise:
|
||||||
|
raise
|
||||||
|
|
||||||
except:
|
except:
|
||||||
LOG.warn('Unknown error while downloading. Traceback:')
|
LOG.warn('Unknown error while downloading. Traceback:')
|
||||||
import traceback
|
import traceback
|
||||||
LOG.warn(traceback.format_exc())
|
LOG.warn(traceback.format_exc())
|
||||||
|
if reraise:
|
||||||
|
raise
|
||||||
|
|
||||||
# THE RESPONSE #####
|
# THE RESPONSE #####
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -9,7 +9,7 @@ from . import utils
|
||||||
from .utils import etree
|
from .utils import etree
|
||||||
from . import path_ops
|
from . import path_ops
|
||||||
from . import migration
|
from . import migration
|
||||||
from .downloadutils import DownloadUtils as DU
|
from .downloadutils import DownloadUtils as DU, exceptions
|
||||||
from . import plex_functions as PF
|
from . import plex_functions as PF
|
||||||
from . import plex_tv
|
from . import plex_tv
|
||||||
from . import json_rpc as js
|
from . import json_rpc as js
|
||||||
|
@ -92,28 +92,59 @@ class InitialSetup(object):
|
||||||
else:
|
else:
|
||||||
url = 'http://%s' % url
|
url = 'http://%s' % url
|
||||||
https = 'true' if https else 'false'
|
https = 'true' if https else 'false'
|
||||||
machine_identifier = PF.GetMachineIdentifier(url)
|
# Try to connect first
|
||||||
if machine_identifier is None:
|
error = False
|
||||||
LOG.error('Could not get machine identifier')
|
try:
|
||||||
# "Error contacting url
|
machine_identifier = PF.GetMachineIdentifier(url)
|
||||||
# Abort (Yes) or save address anyway (No)"
|
except exceptions.SSLError:
|
||||||
if utils.yesno_dialog(utils.lang(29999),
|
LOG.error('SSL cert error contacting %s', url)
|
||||||
'%s %s. %s' % (utils.lang(39218),
|
# "SSL certificate failed to validate. Please check {0}
|
||||||
url,
|
# for solutions."
|
||||||
utils.lang(39219))):
|
utils.messageDialog(utils.lang(29999),
|
||||||
return False
|
utils.lang(30503).format('github.com/croneter/PlexKodiConnect/issues'))
|
||||||
else:
|
return
|
||||||
LOG.info('Saving manual address anyway')
|
except Exception:
|
||||||
utils.settings('plex_machineIdentifier', '')
|
error = True
|
||||||
else:
|
if error or machine_identifier is None:
|
||||||
utils.settings('plex_machineIdentifier', machine_identifier)
|
LOG.error('Could not even get a machineIdentifier for %s', url)
|
||||||
LOG.info('Set new PMS to https %s, address %s, port %s, machineId %s',
|
# "Server is unreachable"
|
||||||
https, address, port, machine_identifier)
|
utils.messageDialog(utils.lang(29999), utils.lang(33002))
|
||||||
utils.settings('https', value=https)
|
return
|
||||||
utils.settings('ipaddress', value=address)
|
# Let's use the main account's token, not managed user token
|
||||||
utils.settings('port', value=port)
|
token = utils.settings('plexToken')
|
||||||
# Chances are this is a local PMS, so disable SSL certificate check
|
xml = PF.pms_root(url, token)
|
||||||
utils.settings('sslverify', value='false')
|
if xml == 401:
|
||||||
|
LOG.error('Not yet authorized for %s', url)
|
||||||
|
# "User is unauthorized for server {0}",
|
||||||
|
# "Please sign in to plex.tv."
|
||||||
|
utils.messageDialog(utils.lang(29999),
|
||||||
|
'%s. %s' % (utils.lang(33010).format(address),
|
||||||
|
utils.lang(39014)))
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
xml[0].attrib
|
||||||
|
except (IndexError, TypeError, AttributeError):
|
||||||
|
LOG.error('Could not get PMS root directory for %s', url)
|
||||||
|
# "Error contacting PMS"
|
||||||
|
utils.messageDialog(utils.lang(29999), utils.lang(39218))
|
||||||
|
return
|
||||||
|
pms = {
|
||||||
|
'baseURL': url,
|
||||||
|
'ip': address,
|
||||||
|
# Assume PMS is not local so we're not resetting verifyssl
|
||||||
|
'local': False,
|
||||||
|
'machineIdentifier': xml.get('machineIdentifier'),
|
||||||
|
'name': xml.get('friendlyName'),
|
||||||
|
# Assume that we own this PMS - no easy way to check
|
||||||
|
'owned': True,
|
||||||
|
'platform': xml.get('platform'),
|
||||||
|
'port': port,
|
||||||
|
# 'relay': True,
|
||||||
|
'scheme': 'https' if https else 'http',
|
||||||
|
'token': token,
|
||||||
|
'version': xml.get('version')
|
||||||
|
}
|
||||||
|
return pms
|
||||||
|
|
||||||
def plex_tv_sign_in(self):
|
def plex_tv_sign_in(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -834,7 +834,8 @@ def GetMachineIdentifier(url):
|
||||||
xml = DU().downloadUrl('%s/identity' % url,
|
xml = DU().downloadUrl('%s/identity' % url,
|
||||||
authenticate=False,
|
authenticate=False,
|
||||||
verifySSL=False,
|
verifySSL=False,
|
||||||
timeout=10)
|
timeout=10,
|
||||||
|
reraise=True)
|
||||||
try:
|
try:
|
||||||
machineIdentifier = xml.attrib['machineIdentifier']
|
machineIdentifier = xml.attrib['machineIdentifier']
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
|
@ -937,6 +938,17 @@ def delete_item_from_pms(plexid):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def pms_root(url, token):
|
||||||
|
"""
|
||||||
|
Retrieve the PMS' most basic settings by retrieving <url>/
|
||||||
|
"""
|
||||||
|
return DU().downloadUrl(
|
||||||
|
url,
|
||||||
|
authenticate=False,
|
||||||
|
verifySSL=True if v.KODIVERSION >= 18 else False,
|
||||||
|
headerOptions={'X-Plex-Token': token} if token else None)
|
||||||
|
|
||||||
|
|
||||||
def get_PMS_settings(url, token):
|
def get_PMS_settings(url, token):
|
||||||
"""
|
"""
|
||||||
Retrieve the PMS' settings via <url>/:/prefs
|
Retrieve the PMS' settings via <url>/:/prefs
|
||||||
|
|
|
@ -269,14 +269,29 @@ class Service():
|
||||||
self.auth_running = False
|
self.auth_running = False
|
||||||
|
|
||||||
def enter_new_pms_address(self):
|
def enter_new_pms_address(self):
|
||||||
if self.setup.enter_new_pms_address():
|
server = self.setup.enter_new_pms_address()
|
||||||
app.CONN.load()
|
if not server:
|
||||||
app.ACCOUNT.reset_session()
|
return
|
||||||
app.ACCOUNT.set_unauthenticated()
|
if not self.log_out():
|
||||||
self.server_has_been_online = False
|
return False
|
||||||
self.welcome_msg = False
|
# Save changes to to file
|
||||||
# Force a full sync
|
self.setup.save_pms_settings(server['baseURL'], server['token'])
|
||||||
app.SYNC.run_lib_scan = 'full'
|
self.setup.write_pms_to_settings(server)
|
||||||
|
if not v.KODIVERSION >= 18:
|
||||||
|
utils.settings('sslverify', value='false')
|
||||||
|
if not self.log_out():
|
||||||
|
return False
|
||||||
|
# Wipe Kodi and Plex database as well as playlists and video nodes
|
||||||
|
utils.wipe_database()
|
||||||
|
app.CONN.load()
|
||||||
|
app.ACCOUNT.reset_session()
|
||||||
|
app.ACCOUNT.set_unauthenticated()
|
||||||
|
self.server_has_been_online = False
|
||||||
|
self.welcome_msg = False
|
||||||
|
# Force a full sync
|
||||||
|
app.SYNC.run_lib_scan = 'full'
|
||||||
|
LOG.info("Choosing new PMS complete")
|
||||||
|
return True
|
||||||
|
|
||||||
def _do_auth(self):
|
def _do_auth(self):
|
||||||
LOG.info('Authenticating user')
|
LOG.info('Authenticating user')
|
||||||
|
|
Loading…
Reference in a new issue