Fix KeyErrors
This commit is contained in:
parent
892a1afdcb
commit
41ec923a30
2 changed files with 19 additions and 17 deletions
|
@ -91,10 +91,10 @@ def process_websocket_messages():
|
||||||
else:
|
else:
|
||||||
successful, video, music = process_new_item_message(message)
|
successful, video, music = process_new_item_message(message)
|
||||||
if (successful and SYNC_FANART and
|
if (successful and SYNC_FANART and
|
||||||
message['type'] in (v.PLEX_TYPE_MOVIE, v.PLEX_TYPE_SHOW)):
|
message['plex_type'] in (v.PLEX_TYPE_MOVIE, v.PLEX_TYPE_SHOW)):
|
||||||
task = FanartTask()
|
task = FanartTask()
|
||||||
task.setup(utils.cast(int, message['ratingKey']),
|
task.setup(message['plex_id'],
|
||||||
message['type'],
|
message['plex_type'],
|
||||||
refresh=False)
|
refresh=False)
|
||||||
backgroundthread.BGThreader.addTask(task)
|
backgroundthread.BGThreader.addTask(task)
|
||||||
if successful is True:
|
if successful is True:
|
||||||
|
@ -119,26 +119,26 @@ def process_websocket_messages():
|
||||||
|
|
||||||
|
|
||||||
def process_new_item_message(message):
|
def process_new_item_message(message):
|
||||||
plex_id = message['ratingKey']
|
LOG.debug('Message: %s', message)
|
||||||
xml = PF.GetPlexMetadata(plex_id)
|
xml = PF.GetPlexMetadata(message['plex_id'])
|
||||||
try:
|
try:
|
||||||
plex_type = xml[0].attrib['type']
|
plex_type = xml[0].attrib['type']
|
||||||
except (IndexError, KeyError, TypeError):
|
except (IndexError, KeyError, TypeError):
|
||||||
LOG.error('Could not download metadata for %s', plex_id)
|
LOG.error('Could not download metadata for %s', message['plex_id'])
|
||||||
return False, False, False
|
return False, False, False
|
||||||
LOG.debug("Processing new/updated PMS item: %s", plex_id)
|
LOG.debug("Processing new/updated PMS item: %s", message['plex_id'])
|
||||||
with itemtypes.ITEMTYPE_FROM_PLEXTYPE[plex_type](utils.unix_timestamp()) as typus:
|
with itemtypes.ITEMTYPE_FROM_PLEXTYPE[plex_type](utils.unix_timestamp()) as typus:
|
||||||
typus.add_update(xml[0],
|
typus.add_update(xml[0],
|
||||||
section_name=xml.get('librarySectionTitle'),
|
section_name=xml.get('librarySectionTitle'),
|
||||||
section_id=xml.get('librarySectionID'))
|
section_id=xml.get('librarySectionID'))
|
||||||
cache_artwork(plex_id, plex_type)
|
cache_artwork(message['plex_id'], plex_type)
|
||||||
return True, plex_type in v.PLEX_VIDEOTYPES, plex_type in v.PLEX_AUDIOTYPES
|
return True, plex_type in v.PLEX_VIDEOTYPES, plex_type in v.PLEX_AUDIOTYPES
|
||||||
|
|
||||||
|
|
||||||
def process_delete_message(message):
|
def process_delete_message(message):
|
||||||
plex_type = message['type']
|
plex_type = message['plex_type']
|
||||||
with itemtypes.ITEMTYPE_FROM_PLEXTYPE[plex_type](None) as typus:
|
with itemtypes.ITEMTYPE_FROM_PLEXTYPE[plex_type](None) as typus:
|
||||||
typus.remove(message['ratingKey'], plex_type=plex_type)
|
typus.remove(message['plex_id'], plex_type=plex_type)
|
||||||
return True, plex_type in v.PLEX_VIDEOTYPES, plex_type in v.PLEX_AUDIOTYPES
|
return True, plex_type in v.PLEX_VIDEOTYPES, plex_type in v.PLEX_AUDIOTYPES
|
||||||
|
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ def process_playing(data):
|
||||||
if status == 'buffering' or status == 'stopped':
|
if status == 'buffering' or status == 'stopped':
|
||||||
# Drop buffering and stop messages immediately - no value
|
# Drop buffering and stop messages immediately - no value
|
||||||
continue
|
continue
|
||||||
plex_id = int(message['ratingKey'])
|
plex_id = utils.cast(int, message['ratingKey'])
|
||||||
skip = False
|
skip = False
|
||||||
for pid in (0, 1, 2):
|
for pid in (0, 1, 2):
|
||||||
if plex_id == state.PLAYER_STATES[pid]['plex_id']:
|
if plex_id == state.PLAYER_STATES[pid]['plex_id']:
|
||||||
|
|
|
@ -39,25 +39,27 @@ def ConvertPlexToKodiTime(plexTime):
|
||||||
|
|
||||||
def GetPlexKeyNumber(plexKey):
|
def GetPlexKeyNumber(plexKey):
|
||||||
"""
|
"""
|
||||||
Deconstructs e.g. '/library/metadata/xxxx' to the tuple
|
Deconstructs e.g. '/library/metadata/xxxx' to the tuple (unicode, int)
|
||||||
|
|
||||||
('library/metadata', 'xxxx')
|
('library/metadata', xxxx)
|
||||||
|
|
||||||
Returns ('','') if nothing is found
|
Returns (None, None) if nothing is found
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
result = utils.REGEX_END_DIGITS.findall(plexKey)[0]
|
result = utils.REGEX_END_DIGITS.findall(plexKey)[0]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
result = ('', '')
|
result = (None, None)
|
||||||
|
else:
|
||||||
|
result[1] = utils.cast(int, result[1])
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def ParseContainerKey(containerKey):
|
def ParseContainerKey(containerKey):
|
||||||
"""
|
"""
|
||||||
Parses e.g. /playQueues/3045?own=1&repeat=0&window=200 to:
|
Parses e.g. /playQueues/3045?own=1&repeat=0&window=200 to:
|
||||||
'playQueues', '3045', {'window': '200', 'own': '1', 'repeat': '0'}
|
'playQueues', 3045, {'window': '200', 'own': '1', 'repeat': '0'}
|
||||||
|
|
||||||
Output hence: library, key, query (str, str, dict)
|
Output hence: library, key, query (str, int, dict)
|
||||||
"""
|
"""
|
||||||
result = urlparse(containerKey)
|
result = urlparse(containerKey)
|
||||||
library, key = GetPlexKeyNumber(result.path)
|
library, key = GetPlexKeyNumber(result.path)
|
||||||
|
|
Loading…
Reference in a new issue