Fix widgets not receiving PKC information

This commit is contained in:
croneter 2018-11-26 07:19:34 +01:00
parent 0fe2de1705
commit a149d8de27
6 changed files with 112 additions and 75 deletions

View file

@ -18,10 +18,15 @@ SYNC = None
PLAYSTATE = None PLAYSTATE = None
def init(): def init(entrypoint=False):
"""
entrypoint=True initiates only the bare minimum - for other PKC python
instances
"""
global ACCOUNT, APP, CONN, SYNC, PLAYSTATE global ACCOUNT, APP, CONN, SYNC, PLAYSTATE
ACCOUNT = Account() ACCOUNT = Account(entrypoint)
APP = App() APP = App(entrypoint)
CONN = Connection() CONN = Connection(entrypoint)
SYNC = Sync() SYNC = Sync(entrypoint)
if not entrypoint:
PLAYSTATE = PlayState() PLAYSTATE = PlayState()

View file

@ -9,11 +9,13 @@ LOG = getLogger('PLEX.account')
class Account(object): class Account(object):
def __init__(self): def __init__(self, entrypoint=False):
# Along with window('plex_authenticated') if entrypoint:
self.load_entrypoint()
else:
self.authenticated = False self.authenticated = False
self._session = None
utils.window('plex_authenticated', clear=True) utils.window('plex_authenticated', clear=True)
self._session = None
self.load() self.load()
def set_authenticated(self): def set_authenticated(self):
@ -46,8 +48,7 @@ class Account(object):
self.myplexlogin = utils.settings('myplexlogin') == 'true' self.myplexlogin = utils.settings('myplexlogin') == 'true'
# Plex home user? Then "False" # Plex home user? Then "False"
self.restricted_user = True \ self.restricted_user = utils.settings('plex_restricteduser') == 'true'
if utils.settings('plex_restricteduser') == 'true' else False
# Force user to enter Pin if set? # Force user to enter Pin if set?
self.force_login = utils.settings('enforceUserLogin') == 'true' self.force_login = utils.settings('enforceUserLogin') == 'true'
@ -64,6 +65,9 @@ class Account(object):
self.pms_token[:5] if self.pms_token else None) self.pms_token[:5] if self.pms_token else None)
LOG.debug('User is restricted Home user: %s', self.restricted_user) LOG.debug('User is restricted Home user: %s', self.restricted_user)
def load_entrypoint(self):
self.pms_token = utils.settings('accessToken') or None
def log_out(self): def log_out(self):
LOG.debug('Logging-out user %s', self.plex_username) LOG.debug('Logging-out user %s', self.plex_username)
self.plex_username = None self.plex_username = None

View file

@ -11,10 +11,11 @@ class App(object):
""" """
This class is used to store variables across PKC modules This class is used to store variables across PKC modules
""" """
def __init__(self, only_reload_settings=False): def __init__(self, entrypoint=False):
self.load_settings() if entrypoint:
if only_reload_settings: self.load_entrypoint()
return else:
self.load()
# Quit PKC? # Quit PKC?
self.stop_pkc = False self.stop_pkc = False
# Shall we completely suspend PKC and our threads? # Shall we completely suspend PKC and our threads?
@ -40,13 +41,16 @@ class App(object):
# xbmc.Player() instance # xbmc.Player() instance
self.player = None self.player = None
def load_settings(self): def load(self):
# Number of items to fetch and display in widgets # Number of items to fetch and display in widgets
self.fetch_pms_item_number = int(utils.settings('fetch_pms_item_number')) self.fetch_pms_item_number = int(utils.settings('fetch_pms_item_number'))
# Hack to force Kodi widget for "in progress" to show up if it was empty # Hack to force Kodi widget for "in progress" to show up if it was empty
# before # before
self.force_reload_skin = utils.settings('forceReloadSkinOnPlaybackStop') == 'true' self.force_reload_skin = utils.settings('forceReloadSkinOnPlaybackStop') == 'true'
def load_entrypoint(self):
self.fetch_pms_item_number = int(utils.settings('fetch_pms_item_number'))
@property @property
def suspend_threads(self): def suspend_threads(self):
return self._suspend_threads or self.suspend return self._suspend_threads or self.suspend

View file

@ -9,11 +9,12 @@ LOG = getLogger('PLEX.connection')
class Connection(object): class Connection(object):
def __init__(self, only_reload_settings=False): def __init__(self, entrypoint=False):
if entrypoint:
self.load_entrypoint()
else:
self.load_webserver() self.load_webserver()
self.load() self.load()
if only_reload_settings:
return
# TODO: Delete # TODO: Delete
self.pms_server = None self.pms_server = None
# Token passed along, e.g. if playback initiated by Plex Companion. Might be # Token passed along, e.g. if playback initiated by Plex Companion. Might be
@ -59,6 +60,21 @@ class Connection(object):
LOG.debug('Set server %s (%s) to %s', LOG.debug('Set server %s (%s) to %s',
self.server_name, self.machine_identifier, self.server) self.server_name, self.machine_identifier, self.server)
def load_entrypoint(self):
self.verify_ssl_cert = None if utils.settings('sslverify') == 'true' \
else False
self.ssl_cert_path = utils.settings('sslcert') \
if utils.settings('sslcert') != 'None' else None
self.https = utils.settings('https') == 'true'
self.host = utils.settings('ipaddress') or None
self.port = int(utils.settings('port')) if utils.settings('port') else None
if not self.host:
self.server = None
elif self.https:
self.server = 'https://%s:%s' % (self.host, self.port)
else:
self.server = 'http://%s:%s' % (self.host, self.port)
def clear(self): def clear(self):
LOG.debug('Clearing connection settings') LOG.debug('Clearing connection settings')
self.machine_identifier = None self.machine_identifier = None

View file

@ -6,10 +6,11 @@ from .. import utils
class Sync(object): class Sync(object):
def __init__(self, only_reload_settings=False): def __init__(self, entrypoint=False):
self.load_settings() if entrypoint:
if only_reload_settings: self.load_entrypoint()
return else:
self.load()
# Do we need to run a special library scan? # Do we need to run a special library scan?
self.run_lib_scan = None self.run_lib_scan = None
# Set if user decided to cancel sync # Set if user decided to cancel sync
@ -23,7 +24,7 @@ class Sync(object):
# window('plex_dbScan') set to 'true' # window('plex_dbScan') set to 'true'
self.db_scan = False self.db_scan = False
def load_settings(self): def load(self):
# Direct Paths (True) or Addon Paths (False)? # Direct Paths (True) or Addon Paths (False)?
self.direct_paths = utils.settings('useDirectPaths') == '1' self.direct_paths = utils.settings('useDirectPaths') == '1'
# Is synching of Plex music enabled? # Is synching of Plex music enabled?
@ -68,3 +69,8 @@ class Sync(object):
# Shall Kodi show dialogs for syncing/caching images? (e.g. images left # Shall Kodi show dialogs for syncing/caching images? (e.g. images left
# to sync) # to sync)
self.image_sync_notifications = utils.settings('imageSyncNotifications') == 'true' self.image_sync_notifications = utils.settings('imageSyncNotifications') == 'true'
def load_entrypoint(self):
self.direct_paths = utils.settings('useDirectPaths') == '1'
self.indicate_media_versions = utils.settings('indicate_media_versions') == "true"
self.path_verified = True

View file

@ -14,7 +14,6 @@ from xbmcgui import ListItem
from . import utils from . import utils
from . import path_ops from . import path_ops
from . import initialsetup
from .downloadutils import DownloadUtils as DU from .downloadutils import DownloadUtils as DU
from .plex_api import API from .plex_api import API
from . import plex_functions as PF from . import plex_functions as PF
@ -376,7 +375,7 @@ def get_video_files(plex_id, params):
if plex_id is None: if plex_id is None:
LOG.info('No Plex ID found, abort getting Extras') LOG.info('No Plex ID found, abort getting Extras')
return xbmcplugin.endOfDirectory(int(argv[1])) return xbmcplugin.endOfDirectory(int(argv[1]))
app.init(entrypoint=True)
item = PF.GetPlexMetadata(plex_id) item = PF.GetPlexMetadata(plex_id)
try: try:
path = utils.try_decode(item[0][0][0].attrib['file']) path = utils.try_decode(item[0][0][0].attrib['file'])
@ -436,6 +435,7 @@ def extra_fanart(plex_id, plex_path):
if not path_ops.exists(fanart_dir): if not path_ops.exists(fanart_dir):
# Download the images to the cache directory # Download the images to the cache directory
path_ops.makedirs(fanart_dir) path_ops.makedirs(fanart_dir)
app.init(entrypoint=True)
xml = PF.GetPlexMetadata(plex_id) xml = PF.GetPlexMetadata(plex_id)
if xml is None: if xml is None:
LOG.error('Could not download metadata for %s', plex_id) LOG.error('Could not download metadata for %s', plex_id)
@ -504,15 +504,13 @@ def on_deck_episodes(viewid, tagname, limit):
# Wait till we've connected to a PMS. At most 30s # Wait till we've connected to a PMS. At most 30s
if not _wait_for_auth(): if not _wait_for_auth():
return return
# We're using another python instance - need to load some vars
app.init(entrypoint=True)
xml = DU().downloadUrl('{server}/library/sections/%s/onDeck' % viewid) xml = DU().downloadUrl('{server}/library/sections/%s/onDeck' % viewid)
if xml in (None, 401): if xml in (None, 401):
LOG.error('Could not download PMS xml for view %s', viewid) LOG.error('Could not download PMS xml for view %s', viewid)
xbmcplugin.endOfDirectory(int(argv[1]), False) xbmcplugin.endOfDirectory(int(argv[1]), False)
return return
# We're using another python instance - need to load some vars
app.init()
# Let's NOT check paths for widgets!
app.SYNC.path_verified = True
counter = 0 counter = 0
for item in xml: for item in xml:
api = API(item) api = API(item)
@ -619,6 +617,7 @@ def playlists(content_type):
if not _wait_for_auth(): if not _wait_for_auth():
return return
xbmcplugin.setContent(int(argv[1]), 'files') xbmcplugin.setContent(int(argv[1]), 'files')
app.init(entrypoint=True)
from .playlists.pms import all_playlists from .playlists.pms import all_playlists
xml = all_playlists() xml = all_playlists()
if xml is None: if xml is None:
@ -650,6 +649,7 @@ def hub(content_type):
content_type: content_type:
audio, video, image audio, video, image
""" """
app.init(entrypoint=True)
xml = PF.get_plex_hub() xml = PF.get_plex_hub()
try: try:
xml.attrib xml.attrib
@ -725,6 +725,7 @@ def browse_plex(key=None, plex_section_id=None):
be used directly for PMS url {server}<key>) or the plex_section_id be used directly for PMS url {server}<key>) or the plex_section_id
""" """
LOG.debug('Browsing to key %s, section %s', key, plex_section_id) LOG.debug('Browsing to key %s, section %s', key, plex_section_id)
app.init(entrypoint=True)
if key: if key:
xml = DU().downloadUrl('{server}%s' % key) xml = DU().downloadUrl('{server}%s' % key)
else: else:
@ -878,6 +879,7 @@ def extras(plex_id):
Lists all extras for plex_id Lists all extras for plex_id
""" """
xbmcplugin.setContent(int(argv[1]), 'movies') xbmcplugin.setContent(int(argv[1]), 'movies')
app.init(entrypoint=True)
xml = PF.GetPlexMetadata(plex_id) xml = PF.GetPlexMetadata(plex_id)
try: try:
xml[0].attrib xml[0].attrib