Fix widgets not receiving PKC information
This commit is contained in:
parent
0fe2de1705
commit
a149d8de27
6 changed files with 112 additions and 75 deletions
|
@ -18,10 +18,15 @@ SYNC = 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
|
||||
ACCOUNT = Account()
|
||||
APP = App()
|
||||
CONN = Connection()
|
||||
SYNC = Sync()
|
||||
ACCOUNT = Account(entrypoint)
|
||||
APP = App(entrypoint)
|
||||
CONN = Connection(entrypoint)
|
||||
SYNC = Sync(entrypoint)
|
||||
if not entrypoint:
|
||||
PLAYSTATE = PlayState()
|
||||
|
|
|
@ -9,11 +9,13 @@ LOG = getLogger('PLEX.account')
|
|||
|
||||
|
||||
class Account(object):
|
||||
def __init__(self):
|
||||
# Along with window('plex_authenticated')
|
||||
def __init__(self, entrypoint=False):
|
||||
if entrypoint:
|
||||
self.load_entrypoint()
|
||||
else:
|
||||
self.authenticated = False
|
||||
self._session = None
|
||||
utils.window('plex_authenticated', clear=True)
|
||||
self._session = None
|
||||
self.load()
|
||||
|
||||
def set_authenticated(self):
|
||||
|
@ -46,8 +48,7 @@ class Account(object):
|
|||
self.myplexlogin = utils.settings('myplexlogin') == 'true'
|
||||
|
||||
# Plex home user? Then "False"
|
||||
self.restricted_user = True \
|
||||
if utils.settings('plex_restricteduser') == 'true' else False
|
||||
self.restricted_user = utils.settings('plex_restricteduser') == 'true'
|
||||
# Force user to enter Pin if set?
|
||||
self.force_login = utils.settings('enforceUserLogin') == 'true'
|
||||
|
||||
|
@ -64,6 +65,9 @@ class Account(object):
|
|||
self.pms_token[:5] if self.pms_token else None)
|
||||
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):
|
||||
LOG.debug('Logging-out user %s', self.plex_username)
|
||||
self.plex_username = None
|
||||
|
|
|
@ -11,10 +11,11 @@ class App(object):
|
|||
"""
|
||||
This class is used to store variables across PKC modules
|
||||
"""
|
||||
def __init__(self, only_reload_settings=False):
|
||||
self.load_settings()
|
||||
if only_reload_settings:
|
||||
return
|
||||
def __init__(self, entrypoint=False):
|
||||
if entrypoint:
|
||||
self.load_entrypoint()
|
||||
else:
|
||||
self.load()
|
||||
# Quit PKC?
|
||||
self.stop_pkc = False
|
||||
# Shall we completely suspend PKC and our threads?
|
||||
|
@ -40,13 +41,16 @@ class App(object):
|
|||
# xbmc.Player() instance
|
||||
self.player = None
|
||||
|
||||
def load_settings(self):
|
||||
def load(self):
|
||||
# Number of items to fetch and display in widgets
|
||||
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
|
||||
# before
|
||||
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
|
||||
def suspend_threads(self):
|
||||
return self._suspend_threads or self.suspend
|
||||
|
|
|
@ -9,11 +9,12 @@ LOG = getLogger('PLEX.connection')
|
|||
|
||||
|
||||
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()
|
||||
if only_reload_settings:
|
||||
return
|
||||
# TODO: Delete
|
||||
self.pms_server = None
|
||||
# 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',
|
||||
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):
|
||||
LOG.debug('Clearing connection settings')
|
||||
self.machine_identifier = None
|
||||
|
|
|
@ -6,10 +6,11 @@ from .. import utils
|
|||
|
||||
|
||||
class Sync(object):
|
||||
def __init__(self, only_reload_settings=False):
|
||||
self.load_settings()
|
||||
if only_reload_settings:
|
||||
return
|
||||
def __init__(self, entrypoint=False):
|
||||
if entrypoint:
|
||||
self.load_entrypoint()
|
||||
else:
|
||||
self.load()
|
||||
# Do we need to run a special library scan?
|
||||
self.run_lib_scan = None
|
||||
# Set if user decided to cancel sync
|
||||
|
@ -23,7 +24,7 @@ class Sync(object):
|
|||
# window('plex_dbScan') set to 'true'
|
||||
self.db_scan = False
|
||||
|
||||
def load_settings(self):
|
||||
def load(self):
|
||||
# Direct Paths (True) or Addon Paths (False)?
|
||||
self.direct_paths = utils.settings('useDirectPaths') == '1'
|
||||
# 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
|
||||
# to sync)
|
||||
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
|
||||
|
|
|
@ -14,7 +14,6 @@ from xbmcgui import ListItem
|
|||
|
||||
from . import utils
|
||||
from . import path_ops
|
||||
from . import initialsetup
|
||||
from .downloadutils import DownloadUtils as DU
|
||||
from .plex_api import API
|
||||
from . import plex_functions as PF
|
||||
|
@ -376,7 +375,7 @@ def get_video_files(plex_id, params):
|
|||
if plex_id is None:
|
||||
LOG.info('No Plex ID found, abort getting Extras')
|
||||
return xbmcplugin.endOfDirectory(int(argv[1]))
|
||||
|
||||
app.init(entrypoint=True)
|
||||
item = PF.GetPlexMetadata(plex_id)
|
||||
try:
|
||||
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):
|
||||
# Download the images to the cache directory
|
||||
path_ops.makedirs(fanart_dir)
|
||||
app.init(entrypoint=True)
|
||||
xml = PF.GetPlexMetadata(plex_id)
|
||||
if xml is None:
|
||||
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
|
||||
if not _wait_for_auth():
|
||||
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)
|
||||
if xml in (None, 401):
|
||||
LOG.error('Could not download PMS xml for view %s', viewid)
|
||||
xbmcplugin.endOfDirectory(int(argv[1]), False)
|
||||
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
|
||||
for item in xml:
|
||||
api = API(item)
|
||||
|
@ -619,6 +617,7 @@ def playlists(content_type):
|
|||
if not _wait_for_auth():
|
||||
return
|
||||
xbmcplugin.setContent(int(argv[1]), 'files')
|
||||
app.init(entrypoint=True)
|
||||
from .playlists.pms import all_playlists
|
||||
xml = all_playlists()
|
||||
if xml is None:
|
||||
|
@ -650,6 +649,7 @@ def hub(content_type):
|
|||
content_type:
|
||||
audio, video, image
|
||||
"""
|
||||
app.init(entrypoint=True)
|
||||
xml = PF.get_plex_hub()
|
||||
try:
|
||||
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
|
||||
"""
|
||||
LOG.debug('Browsing to key %s, section %s', key, plex_section_id)
|
||||
app.init(entrypoint=True)
|
||||
if key:
|
||||
xml = DU().downloadUrl('{server}%s' % key)
|
||||
else:
|
||||
|
@ -878,6 +879,7 @@ def extras(plex_id):
|
|||
Lists all extras for plex_id
|
||||
"""
|
||||
xbmcplugin.setContent(int(argv[1]), 'movies')
|
||||
app.init(entrypoint=True)
|
||||
xml = PF.GetPlexMetadata(plex_id)
|
||||
try:
|
||||
xml[0].attrib
|
||||
|
|
Loading…
Reference in a new issue