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
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()
PLAYSTATE = PlayState()
ACCOUNT = Account(entrypoint)
APP = App(entrypoint)
CONN = Connection(entrypoint)
SYNC = Sync(entrypoint)
if not entrypoint:
PLAYSTATE = PlayState()

View file

@ -9,12 +9,14 @@ LOG = getLogger('PLEX.account')
class Account(object):
def __init__(self):
# Along with window('plex_authenticated')
self.authenticated = False
self._session = None
utils.window('plex_authenticated', clear=True)
self.load()
def __init__(self, entrypoint=False):
if entrypoint:
self.load_entrypoint()
else:
self.authenticated = False
utils.window('plex_authenticated', clear=True)
self._session = None
self.load()
def set_authenticated(self):
self.authenticated = True
@ -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

View file

@ -11,42 +11,46 @@ 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
# Quit PKC?
self.stop_pkc = False
# Shall we completely suspend PKC and our threads?
self.suspend = False
# Shall we only suspend threads?
self._suspend_threads = False
# Need to lock all methods and functions messing with Plex Companion subscribers
self.lock_subscriber = RLock()
# Need to lock everything messing with Kodi/PKC playqueues
self.lock_playqueues = RLock()
# Necessary to temporarily hold back librarysync/websocket listener when doing
# a full sync
self.lock_playlists = Lock()
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?
self.suspend = False
# Shall we only suspend threads?
self._suspend_threads = False
# Need to lock all methods and functions messing with Plex Companion subscribers
self.lock_subscriber = RLock()
# Need to lock everything messing with Kodi/PKC playqueues
self.lock_playqueues = RLock()
# Necessary to temporarily hold back librarysync/websocket listener when doing
# a full sync
self.lock_playlists = Lock()
# Plex Companion Queue()
self.companion_queue = Queue.Queue(maxsize=100)
# Command Pipeline Queue()
self.command_pipeline_queue = Queue.Queue()
# Websocket_client queue to communicate with librarysync
self.websocket_queue = Queue.Queue()
# xbmc.Monitor() instance from kodimonitor.py
self.monitor = None
# xbmc.Player() instance
self.player = None
# Plex Companion Queue()
self.companion_queue = Queue.Queue(maxsize=100)
# Command Pipeline Queue()
self.command_pipeline_queue = Queue.Queue()
# Websocket_client queue to communicate with librarysync
self.websocket_queue = Queue.Queue()
# xbmc.Monitor() instance from kodimonitor.py
self.monitor = None
# 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

View file

@ -9,16 +9,17 @@ LOG = getLogger('PLEX.connection')
class Connection(object):
def __init__(self, only_reload_settings=False):
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
# another user playing something! Token identifies user
self.plex_transient_token = None
def __init__(self, entrypoint=False):
if entrypoint:
self.load_entrypoint()
else:
self.load_webserver()
self.load()
# TODO: Delete
self.pms_server = None
# Token passed along, e.g. if playback initiated by Plex Companion. Might be
# another user playing something! Token identifies user
self.plex_transient_token = None
def load_webserver(self):
"""
@ -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

View file

@ -6,24 +6,25 @@ from .. import utils
class Sync(object):
def __init__(self, only_reload_settings=False):
self.load_settings()
if only_reload_settings:
return
# Do we need to run a special library scan?
self.run_lib_scan = None
# Set if user decided to cancel sync
self.stop_sync = False
# Set during media playback if PKC should not do any syncs. Will NOT
# suspend synching of playstate progress
self.suspend_sync = False
# Could we access the paths?
self.path_verified = False
# Set if a Plex-Kodi DB sync is being done - along with
# window('plex_dbScan') set to 'true'
self.db_scan = False
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
self.stop_sync = False
# Set during media playback if PKC should not do any syncs. Will NOT
# suspend synching of playstate progress
self.suspend_sync = False
# Could we access the paths?
self.path_verified = False
# Set if a Plex-Kodi DB sync is being done - along with
# 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

View file

@ -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