Fix PKC not connecting due to changed IP
This commit is contained in:
parent
27b2d4cbf2
commit
1f5eae8267
4 changed files with 45 additions and 30 deletions
|
@ -24,9 +24,9 @@ def init(entrypoint=False):
|
||||||
instances
|
instances
|
||||||
"""
|
"""
|
||||||
global ACCOUNT, APP, CONN, SYNC, PLAYSTATE
|
global ACCOUNT, APP, CONN, SYNC, PLAYSTATE
|
||||||
ACCOUNT = Account(entrypoint)
|
|
||||||
APP = App(entrypoint)
|
APP = App(entrypoint)
|
||||||
CONN = Connection(entrypoint)
|
CONN = Connection(entrypoint)
|
||||||
|
ACCOUNT = Account(entrypoint)
|
||||||
SYNC = Sync(entrypoint)
|
SYNC = Sync(entrypoint)
|
||||||
if not entrypoint:
|
if not entrypoint:
|
||||||
PLAYSTATE = PlayState()
|
PLAYSTATE = PlayState()
|
||||||
|
|
|
@ -21,15 +21,20 @@ class Account(object):
|
||||||
def set_authenticated(self):
|
def set_authenticated(self):
|
||||||
self.authenticated = True
|
self.authenticated = True
|
||||||
utils.window('plex_authenticated', value='true')
|
utils.window('plex_authenticated', value='true')
|
||||||
# Start download session
|
|
||||||
from .. import downloadutils
|
|
||||||
self._session = downloadutils.DownloadUtils()
|
|
||||||
self._session.startSession(reset=True)
|
|
||||||
|
|
||||||
def set_unauthenticated(self):
|
def set_unauthenticated(self):
|
||||||
self.authenticated = False
|
self.authenticated = False
|
||||||
utils.window('plex_authenticated', clear=True)
|
utils.window('plex_authenticated', clear=True)
|
||||||
|
|
||||||
|
def reset_session(self):
|
||||||
|
try:
|
||||||
|
self._session.stopSession()
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
|
from .. import downloadutils
|
||||||
|
self._session = downloadutils.DownloadUtils()
|
||||||
|
self._session.startSession(reset=True)
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
LOG.debug('Loading account settings')
|
LOG.debug('Loading account settings')
|
||||||
# User name we used to sign in to plex.tv
|
# User name we used to sign in to plex.tv
|
||||||
|
@ -59,6 +64,10 @@ class Account(object):
|
||||||
utils.window('plex_token', value=self.plex_token or '')
|
utils.window('plex_token', value=self.plex_token or '')
|
||||||
utils.window('pms_token', value=self.pms_token or '')
|
utils.window('pms_token', value=self.pms_token or '')
|
||||||
utils.window('plexAvatar', value=self.avatar or '')
|
utils.window('plexAvatar', value=self.avatar or '')
|
||||||
|
|
||||||
|
# Start download session
|
||||||
|
self.reset_session()
|
||||||
|
|
||||||
LOG.debug('Loaded user %s, %s with plex token %s... and pms token %s...',
|
LOG.debug('Loaded user %s, %s with plex token %s... and pms token %s...',
|
||||||
self.plex_username, self.plex_user_id,
|
self.plex_username, self.plex_user_id,
|
||||||
self.plex_token[:5] if self.plex_token else None,
|
self.plex_token[:5] if self.plex_token else None,
|
||||||
|
@ -77,7 +86,7 @@ class Account(object):
|
||||||
self.restricted_user = None
|
self.restricted_user = None
|
||||||
self.authenticated = False
|
self.authenticated = False
|
||||||
try:
|
try:
|
||||||
self._session.close()
|
self._session.stopSession()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
self._session = None
|
self._session = None
|
||||||
|
@ -105,7 +114,7 @@ class Account(object):
|
||||||
self.plex_login = None
|
self.plex_login = None
|
||||||
self.plex_login_id = None
|
self.plex_login_id = None
|
||||||
try:
|
try:
|
||||||
self._session.close()
|
self._session.stopSession()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
self._session = None
|
self._session = None
|
||||||
|
|
|
@ -26,24 +26,6 @@ if not path_ops.exists(v.EXTERNAL_SUBTITLE_TEMP_PATH):
|
||||||
path_ops.makedirs(v.EXTERNAL_SUBTITLE_TEMP_PATH)
|
path_ops.makedirs(v.EXTERNAL_SUBTITLE_TEMP_PATH)
|
||||||
|
|
||||||
|
|
||||||
def _write_pms_settings(url, token):
|
|
||||||
"""
|
|
||||||
Sets certain settings for server by asking for the PMS' settings
|
|
||||||
Call with url: scheme://ip:port
|
|
||||||
"""
|
|
||||||
xml = PF.get_PMS_settings(url, token)
|
|
||||||
try:
|
|
||||||
xml.attrib
|
|
||||||
except AttributeError:
|
|
||||||
LOG.error('Could not get PMS settings for %s', url)
|
|
||||||
return
|
|
||||||
for entry in xml:
|
|
||||||
if entry.attrib.get('id', '') == 'allowMediaDeletion':
|
|
||||||
value = 'true' if entry.get('value', '1') == '1' else 'false'
|
|
||||||
utils.settings('plex_allows_mediaDeletion', value=value)
|
|
||||||
utils.window('plex_allows_mediaDeletion', value=value)
|
|
||||||
|
|
||||||
|
|
||||||
class InitialSetup(object):
|
class InitialSetup(object):
|
||||||
"""
|
"""
|
||||||
Will load Plex PMS settings (e.g. address) and token
|
Will load Plex PMS settings (e.g. address) and token
|
||||||
|
@ -69,6 +51,24 @@ class InitialSetup(object):
|
||||||
utils.settings('userid', value=self.plex_login_id or '')
|
utils.settings('userid', value=self.plex_login_id or '')
|
||||||
utils.settings('plexToken', value=self.plex_token or '')
|
utils.settings('plexToken', value=self.plex_token or '')
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def save_pms_settings(url, token):
|
||||||
|
"""
|
||||||
|
Sets certain settings for server by asking for the PMS' settings
|
||||||
|
Call with url: scheme://ip:port
|
||||||
|
"""
|
||||||
|
xml = PF.get_PMS_settings(url, token)
|
||||||
|
try:
|
||||||
|
xml.attrib
|
||||||
|
except AttributeError:
|
||||||
|
LOG.error('Could not get PMS settings for %s', url)
|
||||||
|
return
|
||||||
|
for entry in xml:
|
||||||
|
if entry.attrib.get('id', '') == 'allowMediaDeletion':
|
||||||
|
value = 'true' if entry.get('value', '1') == '1' else 'false'
|
||||||
|
utils.settings('plex_allows_mediaDeletion', value=value)
|
||||||
|
utils.window('plex_allows_mediaDeletion', value=value)
|
||||||
|
|
||||||
def enter_new_pms_address(self):
|
def enter_new_pms_address(self):
|
||||||
# "Enter your Plex Media Server's IP or URL. Examples are:"
|
# "Enter your Plex Media Server's IP or URL. Examples are:"
|
||||||
utils.messageDialog(utils.lang(29999),
|
utils.messageDialog(utils.lang(29999),
|
||||||
|
@ -261,8 +261,6 @@ class InitialSetup(object):
|
||||||
server = self._user_pick_pms()
|
server = self._user_pick_pms()
|
||||||
else:
|
else:
|
||||||
server = self._auto_pick_pms()
|
server = self._auto_pick_pms()
|
||||||
if server is not None:
|
|
||||||
_write_pms_settings(server['baseURL'], server['token'])
|
|
||||||
return server
|
return server
|
||||||
|
|
||||||
def _auto_pick_pms(self):
|
def _auto_pick_pms(self):
|
||||||
|
@ -389,6 +387,7 @@ class InitialSetup(object):
|
||||||
utils.settings('plex_servername', server['name'])
|
utils.settings('plex_servername', server['name'])
|
||||||
utils.settings('plex_serverowned',
|
utils.settings('plex_serverowned',
|
||||||
'true' if server['owned'] else 'false')
|
'true' if server['owned'] else 'false')
|
||||||
|
utils.settings('accessToken', server['token'])
|
||||||
# Careful to distinguish local from remote PMS
|
# Careful to distinguish local from remote PMS
|
||||||
if server['local']:
|
if server['local']:
|
||||||
scheme = server['scheme']
|
scheme = server['scheme']
|
||||||
|
@ -486,7 +485,6 @@ class InitialSetup(object):
|
||||||
migration.check_migration()
|
migration.check_migration()
|
||||||
# Reload the server IP cause we might've deleted it during migration
|
# Reload the server IP cause we might've deleted it during migration
|
||||||
app.CONN.load()
|
app.CONN.load()
|
||||||
app.CONN.server = app.CONN.server
|
|
||||||
|
|
||||||
# Display a warning if Kodi puts ALL movies into the queue, basically
|
# Display a warning if Kodi puts ALL movies into the queue, basically
|
||||||
# breaking playback reporting for PKC
|
# breaking playback reporting for PKC
|
||||||
|
@ -512,7 +510,7 @@ class InitialSetup(object):
|
||||||
if self.check_existing_pms():
|
if self.check_existing_pms():
|
||||||
LOG.info("Using PMS %s with machineIdentifier %s",
|
LOG.info("Using PMS %s with machineIdentifier %s",
|
||||||
app.CONN.server, app.CONN.machine_identifier)
|
app.CONN.server, app.CONN.machine_identifier)
|
||||||
_write_pms_settings(app.CONN.server, self.pms_token)
|
self.save_pms_settings(app.CONN.server, self.pms_token)
|
||||||
if reboot is True:
|
if reboot is True:
|
||||||
utils.reboot_kodi()
|
utils.reboot_kodi()
|
||||||
return
|
return
|
||||||
|
@ -525,6 +523,7 @@ class InitialSetup(object):
|
||||||
server = self.pick_pms()
|
server = self.pick_pms()
|
||||||
if server is not None:
|
if server is not None:
|
||||||
# Write our chosen server to Kodi settings file
|
# Write our chosen server to Kodi settings file
|
||||||
|
self.save_pms_settings(server['baseURL'], server['token'])
|
||||||
self.write_pms_to_settings(server)
|
self.write_pms_to_settings(server)
|
||||||
|
|
||||||
# User already answered the installation questions
|
# User already answered the installation questions
|
||||||
|
|
|
@ -115,8 +115,11 @@ class Service():
|
||||||
self.connection_check_counter = 0
|
self.connection_check_counter = 0
|
||||||
server = self.setup.pick_pms()
|
server = self.setup.pick_pms()
|
||||||
if server:
|
if server:
|
||||||
|
LOG.debug('Found server: %s', server)
|
||||||
|
self.setup.save_pms_settings(server['baseURL'], server['token'])
|
||||||
self.setup.write_pms_to_settings(server)
|
self.setup.write_pms_to_settings(server)
|
||||||
app.CONN.load()
|
app.CONN.load()
|
||||||
|
app.ACCOUNT.reset_session()
|
||||||
else:
|
else:
|
||||||
# Server is online
|
# Server is online
|
||||||
self.connection_check_counter = 0
|
self.connection_check_counter = 0
|
||||||
|
@ -169,19 +172,22 @@ class Service():
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
server = self.setup.pick_pms(showDialog=True)
|
server = self.setup.pick_pms(showDialog=True)
|
||||||
if server is None:
|
if not server:
|
||||||
LOG.info('We did not connect to a new PMS, aborting')
|
LOG.info('We did not connect to a new PMS, aborting')
|
||||||
return False
|
return False
|
||||||
LOG.info("User chose server %s", server['name'])
|
LOG.info("User chose server %s", server['name'])
|
||||||
if server['baseURL'] == app.CONN.server:
|
if server['baseURL'] == app.CONN.server:
|
||||||
LOG.info('User chose old PMS to connect to')
|
LOG.info('User chose old PMS to connect to')
|
||||||
return False
|
return False
|
||||||
|
# Save changes to to file
|
||||||
|
self.setup.save_pms_settings(server['baseURL'], server['token'])
|
||||||
self.setup.write_pms_to_settings(server)
|
self.setup.write_pms_to_settings(server)
|
||||||
if not self.log_out():
|
if not self.log_out():
|
||||||
return False
|
return False
|
||||||
# Wipe Kodi and Plex database as well as playlists and video nodes
|
# Wipe Kodi and Plex database as well as playlists and video nodes
|
||||||
utils.wipe_database()
|
utils.wipe_database()
|
||||||
app.CONN.load()
|
app.CONN.load()
|
||||||
|
app.ACCOUNT.reset_session()
|
||||||
app.ACCOUNT.set_unauthenticated()
|
app.ACCOUNT.set_unauthenticated()
|
||||||
self.server_has_been_online = False
|
self.server_has_been_online = False
|
||||||
self.welcome_msg = False
|
self.welcome_msg = False
|
||||||
|
@ -235,6 +241,7 @@ class Service():
|
||||||
def enter_new_pms_address(self):
|
def enter_new_pms_address(self):
|
||||||
if self.setup.enter_new_pms_address():
|
if self.setup.enter_new_pms_address():
|
||||||
app.CONN.load()
|
app.CONN.load()
|
||||||
|
app.ACCOUNT.reset_session()
|
||||||
app.ACCOUNT.set_unauthenticated()
|
app.ACCOUNT.set_unauthenticated()
|
||||||
self.server_has_been_online = False
|
self.server_has_been_online = False
|
||||||
self.welcome_msg = False
|
self.welcome_msg = False
|
||||||
|
|
Loading…
Reference in a new issue