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
|
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)
|
||||||
PLAYSTATE = PlayState()
|
if not entrypoint:
|
||||||
|
PLAYSTATE = PlayState()
|
||||||
|
|
|
@ -9,12 +9,14 @@ 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.authenticated = False
|
self.load_entrypoint()
|
||||||
self._session = None
|
else:
|
||||||
utils.window('plex_authenticated', clear=True)
|
self.authenticated = False
|
||||||
self.load()
|
utils.window('plex_authenticated', clear=True)
|
||||||
|
self._session = None
|
||||||
|
self.load()
|
||||||
|
|
||||||
def set_authenticated(self):
|
def set_authenticated(self):
|
||||||
self.authenticated = True
|
self.authenticated = True
|
||||||
|
@ -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
|
||||||
|
|
|
@ -11,42 +11,46 @@ 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:
|
||||||
# Quit PKC?
|
self.load()
|
||||||
self.stop_pkc = False
|
# Quit PKC?
|
||||||
# Shall we completely suspend PKC and our threads?
|
self.stop_pkc = False
|
||||||
self.suspend = False
|
# Shall we completely suspend PKC and our threads?
|
||||||
# Shall we only suspend threads?
|
self.suspend = False
|
||||||
self._suspend_threads = False
|
# Shall we only suspend threads?
|
||||||
# Need to lock all methods and functions messing with Plex Companion subscribers
|
self._suspend_threads = False
|
||||||
self.lock_subscriber = RLock()
|
# Need to lock all methods and functions messing with Plex Companion subscribers
|
||||||
# Need to lock everything messing with Kodi/PKC playqueues
|
self.lock_subscriber = RLock()
|
||||||
self.lock_playqueues = RLock()
|
# Need to lock everything messing with Kodi/PKC playqueues
|
||||||
# Necessary to temporarily hold back librarysync/websocket listener when doing
|
self.lock_playqueues = RLock()
|
||||||
# a full sync
|
# Necessary to temporarily hold back librarysync/websocket listener when doing
|
||||||
self.lock_playlists = Lock()
|
# a full sync
|
||||||
|
self.lock_playlists = Lock()
|
||||||
|
|
||||||
# Plex Companion Queue()
|
# Plex Companion Queue()
|
||||||
self.companion_queue = Queue.Queue(maxsize=100)
|
self.companion_queue = Queue.Queue(maxsize=100)
|
||||||
# Command Pipeline Queue()
|
# Command Pipeline Queue()
|
||||||
self.command_pipeline_queue = Queue.Queue()
|
self.command_pipeline_queue = Queue.Queue()
|
||||||
# Websocket_client queue to communicate with librarysync
|
# Websocket_client queue to communicate with librarysync
|
||||||
self.websocket_queue = Queue.Queue()
|
self.websocket_queue = Queue.Queue()
|
||||||
# xbmc.Monitor() instance from kodimonitor.py
|
# xbmc.Monitor() instance from kodimonitor.py
|
||||||
self.monitor = None
|
self.monitor = None
|
||||||
# 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
|
||||||
|
|
|
@ -9,16 +9,17 @@ LOG = getLogger('PLEX.connection')
|
||||||
|
|
||||||
|
|
||||||
class Connection(object):
|
class Connection(object):
|
||||||
def __init__(self, only_reload_settings=False):
|
def __init__(self, entrypoint=False):
|
||||||
self.load_webserver()
|
if entrypoint:
|
||||||
self.load()
|
self.load_entrypoint()
|
||||||
if only_reload_settings:
|
else:
|
||||||
return
|
self.load_webserver()
|
||||||
# TODO: Delete
|
self.load()
|
||||||
self.pms_server = None
|
# TODO: Delete
|
||||||
# Token passed along, e.g. if playback initiated by Plex Companion. Might be
|
self.pms_server = None
|
||||||
# another user playing something! Token identifies user
|
# Token passed along, e.g. if playback initiated by Plex Companion. Might be
|
||||||
self.plex_transient_token = None
|
# another user playing something! Token identifies user
|
||||||
|
self.plex_transient_token = None
|
||||||
|
|
||||||
def load_webserver(self):
|
def load_webserver(self):
|
||||||
"""
|
"""
|
||||||
|
@ -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
|
||||||
|
|
|
@ -6,24 +6,25 @@ 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:
|
||||||
# Do we need to run a special library scan?
|
self.load()
|
||||||
self.run_lib_scan = None
|
# Do we need to run a special library scan?
|
||||||
# Set if user decided to cancel sync
|
self.run_lib_scan = None
|
||||||
self.stop_sync = False
|
# Set if user decided to cancel sync
|
||||||
# Set during media playback if PKC should not do any syncs. Will NOT
|
self.stop_sync = False
|
||||||
# suspend synching of playstate progress
|
# Set during media playback if PKC should not do any syncs. Will NOT
|
||||||
self.suspend_sync = False
|
# suspend synching of playstate progress
|
||||||
# Could we access the paths?
|
self.suspend_sync = False
|
||||||
self.path_verified = False
|
# Could we access the paths?
|
||||||
# Set if a Plex-Kodi DB sync is being done - along with
|
self.path_verified = False
|
||||||
# window('plex_dbScan') set to 'true'
|
# Set if a Plex-Kodi DB sync is being done - along with
|
||||||
self.db_scan = False
|
# window('plex_dbScan') set to 'true'
|
||||||
|
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
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue