Speed up Plex API

This commit is contained in:
croneter 2018-11-07 12:08:35 +01:00
parent 8ef0af3ec7
commit 015451d2fd
3 changed files with 15 additions and 14 deletions

View file

@ -68,7 +68,6 @@ class API(object):
self.part = 0 self.part = 0
self.mediastream = None self.mediastream = None
self.collections = None self.collections = None
self.server = utils.window('pms_server')
def set_part_number(self, number=None): def set_part_number(self, number=None):
""" """
@ -220,16 +219,15 @@ class API(object):
extension not in v.KODI_SUPPORTED_IMAGES): extension not in v.KODI_SUPPORTED_IMAGES):
# Let Plex transcode # Let Plex transcode
# max width/height supported by plex image transcoder is 1920x1080 # max width/height supported by plex image transcoder is 1920x1080
path = self.server + PF.transcode_image_path( path = state.PMS_SERVER + PF.transcode_image_path(
self.item[0][0].get('key'), self.item[0][0].get('key'),
utils.window('pms_token'), state.PMS_TOKEN,
"%s%s" % (self.server, self.item[0][0].get('key')), "%s%s" % (state.PMS_SERVER, self.item[0][0].get('key')),
1920, 1920,
1080) 1080)
else: else:
path = self.attach_plex_token_to_url( path = self.attach_plex_token_to_url(
'%s%s' % (utils.window('pms_server'), '%s%s' % (state.PMS_SERVER, self.item[0][0].attrib['key']))
self.item[0][0].attrib['key']))
# Attach Plex id to url to let it be picked up by our playqueue agent # Attach Plex id to url to let it be picked up by our playqueue agent
# later # later
return utils.try_encode('%s&plex_id=%s' % (path, self.plex_id())) return utils.try_encode('%s&plex_id=%s' % (path, self.plex_id()))
@ -687,12 +685,12 @@ class API(object):
url may or may not already contain a '?' url may or may not already contain a '?'
""" """
if utils.window('pms_token') == '': if not state.PMS_TOKEN:
return url return url
if '?' not in url: if '?' not in url:
url = "%s?X-Plex-Token=%s" % (url, utils.window('pms_token')) url = "%s?X-Plex-Token=%s" % (url, state.PMS_TOKEN)
else: else:
url = "%s&X-Plex-Token=%s" % (url, utils.window('pms_token')) url = "%s&X-Plex-Token=%s" % (url, state.PMS_TOKEN)
return url return url
def item_id(self): def item_id(self):
@ -890,7 +888,7 @@ class API(object):
artwork = '%s?width=%s&height=%s' % (artwork, width, height) artwork = '%s?width=%s&height=%s' % (artwork, width, height)
artwork = ('%s/photo/:/transcode?width=3840&height=3840&' artwork = ('%s/photo/:/transcode?width=3840&height=3840&'
'minSize=1&upscale=0&url=%s' 'minSize=1&upscale=0&url=%s'
% (self.server, quote(artwork))) % (state.PMS_SERVER, quote(artwork)))
artwork = self.attach_plex_token_to_url(artwork) artwork = self.attach_plex_token_to_url(artwork)
return artwork return artwork
@ -1408,7 +1406,7 @@ class API(object):
# trailers are 'clip' with PMS xmls # trailers are 'clip' with PMS xmls
if action == "DirectStream": if action == "DirectStream":
path = self.item[self.mediastream][self.part].attrib['key'] path = self.item[self.mediastream][self.part].attrib['key']
url = self.server + path url = state.PMS_SERVER + path
# e.g. Trailers already feature an '?'! # e.g. Trailers already feature an '?'!
if '?' in url: if '?' in url:
url += '&' + urlencode(xargs) url += '&' + urlencode(xargs)
@ -1425,7 +1423,7 @@ class API(object):
} }
# Path/key to VIDEO item of xml PMS response is needed, not part # Path/key to VIDEO item of xml PMS response is needed, not part
path = self.item.attrib['key'] path = self.item.attrib['key']
transcode_path = self.server + \ transcode_path = state.PMS_SERVER + \
'/video/:/transcode/universal/start.m3u8?' '/video/:/transcode/universal/start.m3u8?'
args = { args = {
'audioBoost': utils.settings('audioBoost'), 'audioBoost': utils.settings('audioBoost'),
@ -1483,7 +1481,7 @@ class API(object):
# We don't know the language - no need to download # We don't know the language - no need to download
else: else:
path = self.attach_plex_token_to_url( path = self.attach_plex_token_to_url(
"%s%s" % (self.server, key)) "%s%s" % (state.PMS_SERVER, key))
externalsubs.append(path) externalsubs.append(path)
kodiindex += 1 kodiindex += 1
LOG.info('Found external subs: %s', externalsubs) LOG.info('Found external subs: %s', externalsubs)

View file

@ -20,7 +20,8 @@ LOCK_PLAYLISTS = Lock()
# Quit PKC # Quit PKC
STOP_PKC = False STOP_PKC = False
# URL of our current PMS
PMS_SERVER = None
# Usually triggered by another Python instance - will have to be set (by # Usually triggered by another Python instance - will have to be set (by
# polling window) through e.g. librarysync thread # polling window) through e.g. librarysync thread
SUSPEND_LIBRARY_THREAD = False SUSPEND_LIBRARY_THREAD = False

View file

@ -154,6 +154,7 @@ class UserClient(Thread):
state.RESTRICTED_USER = True \ state.RESTRICTED_USER = True \
if utils.settings('plex_restricteduser') == 'true' else False if utils.settings('plex_restricteduser') == 'true' else False
utils.window('pms_server', value=self.server) utils.window('pms_server', value=self.server)
state.PMS_SERVER = self.server
utils.window('plex_machineIdentifier', value=self.machine_identifier) utils.window('plex_machineIdentifier', value=self.machine_identifier)
utils.window('plex_servername', value=self.server_name) utils.window('plex_servername', value=self.server_name)
utils.window('plex_authenticated', value='true') utils.window('plex_authenticated', value='true')
@ -280,6 +281,7 @@ class UserClient(Thread):
state.PMS_TOKEN = None state.PMS_TOKEN = None
utils.window('plex_token', clear=True) utils.window('plex_token', clear=True)
utils.window('pms_server', clear=True) utils.window('pms_server', clear=True)
state.PMS_SERVER = None
utils.window('plex_machineIdentifier', clear=True) utils.window('plex_machineIdentifier', clear=True)
utils.window('plex_servername', clear=True) utils.window('plex_servername', clear=True)
state.PLEX_USER_ID = None state.PLEX_USER_ID = None