Plex Companion: add itemType to playstate

This commit is contained in:
tomkat83 2017-05-07 15:02:45 +02:00
parent bd6dca7342
commit 543253e10e
3 changed files with 22 additions and 13 deletions

View file

@ -75,6 +75,7 @@ class Playqueue_Object(Playlist_Object_Baseclase):
class Playlist_Item(object): class Playlist_Item(object):
ID = None # Plex playlist/playqueue id, e.g. playQueueItemID ID = None # Plex playlist/playqueue id, e.g. playQueueItemID
plex_id = None # Plex unique item id, "ratingKey" plex_id = None # Plex unique item id, "ratingKey"
plex_type = None # Plex type, e.g. 'movie', 'clip'
plex_UUID = None # Plex librarySectionUUID plex_UUID = None # Plex librarySectionUUID
kodi_id = None # Kodi unique kodi id (unique only within type!) kodi_id = None # Kodi unique kodi id (unique only within type!)
kodi_type = None # Kodi type: 'movie' kodi_type = None # Kodi type: 'movie'
@ -102,20 +103,22 @@ def playlist_item_from_kodi(kodi_item):
""" """
item = Playlist_Item() item = Playlist_Item()
item.kodi_id = kodi_item.get('id') item.kodi_id = kodi_item.get('id')
item.kodi_type = kodi_item.get('type')
if item.kodi_id: if item.kodi_id:
with plexdb.Get_Plex_DB() as plex_db: with plexdb.Get_Plex_DB() as plex_db:
plex_dbitem = plex_db.getItem_byKodiId(kodi_item['id'], plex_dbitem = plex_db.getItem_byKodiId(kodi_item['id'],
kodi_item['type']) kodi_item['type'])
try: try:
item.plex_id = plex_dbitem[0] item.plex_id = plex_dbitem[0]
item.plex_type = plex_dbitem[2]
item.plex_UUID = plex_dbitem[0] # we dont need the uuid yet :-) item.plex_UUID = plex_dbitem[0] # we dont need the uuid yet :-)
except TypeError: except TypeError:
pass pass
item.file = kodi_item.get('file') item.file = kodi_item.get('file')
if item.file is not None and item.plex_id is None: if item.plex_id is None and item.file is not None:
item.plex_id = dict( query = dict(parse_qsl(urlsplit(item.file).query))
parse_qsl(urlsplit(item.file).query)).get('plex_id') item.plex_id = query.get('plex_id')
item.kodi_type = kodi_item.get('type') item.plex_type = query.get('itemType')
if item.plex_id is None: if item.plex_id is None:
item.uri = 'library://whatever/item/%s' % quote(item.file, safe='') item.uri = 'library://whatever/item/%s' % quote(item.file, safe='')
else: else:
@ -137,6 +140,7 @@ def playlist_item_from_plex(plex_id):
with plexdb.Get_Plex_DB() as plex_db: with plexdb.Get_Plex_DB() as plex_db:
plex_dbitem = plex_db.getItem_byId(plex_id) plex_dbitem = plex_db.getItem_byId(plex_id)
try: try:
item.plex_type = plex_dbitem[5]
item.kodi_id = plex_dbitem[0] item.kodi_id = plex_dbitem[0]
item.kodi_type = plex_dbitem[4] item.kodi_type = plex_dbitem[4]
except: except:
@ -155,6 +159,7 @@ def playlist_item_from_xml(playlist, xml_video_element):
item = Playlist_Item() item = Playlist_Item()
api = API(xml_video_element) api = API(xml_video_element)
item.plex_id = api.getRatingKey() item.plex_id = api.getRatingKey()
item.plex_type = api.getType()
item.ID = xml_video_element.attrib['%sItemID' % playlist.kind] item.ID = xml_video_element.attrib['%sItemID' % playlist.kind]
item.guid = xml_video_element.attrib.get('guid') item.guid = xml_video_element.attrib.get('guid')
if item.guid is not None: if item.guid is not None:

View file

@ -122,7 +122,9 @@ class SubscriptionManager:
ret += ' shuffle="%s"' % info['shuffle'] ret += ' shuffle="%s"' % info['shuffle']
ret += ' mute="%s"' % self.mute ret += ' mute="%s"' % self.mute
ret += ' repeat="%s"' % info['repeat'] ret += ' repeat="%s"' % info['repeat']
ret += ' itemType="%s"' % info['itemType']
# Might need an update in the future # Might need an update in the future
if ptype == 'video':
ret += ' subtitleStreamID="-1"' ret += ' subtitleStreamID="-1"'
ret += ' audioStreamID="-1"' ret += ' audioStreamID="-1"'
@ -244,10 +246,11 @@ class SubscriptionManager:
{"playerid": playerid, {"playerid": playerid,
"properties": ["position"]})['position'] "properties": ["position"]})['position']
try: try:
info['playQueueItemID'] = playqueue.items[pos].ID info['playQueueItemID'] = playqueue.items[pos].ID or 'null'
info['guid'] = playqueue.items[pos].guid info['guid'] = playqueue.items[pos].guid or 'null'
info['playQueueID'] = playqueue.ID info['playQueueID'] = playqueue.ID or 'null'
info['playQueueVersion'] = playqueue.version info['playQueueVersion'] = playqueue.version or 'null'
info['itemType'] = playqueue.items[pos].plex_type or 'null'
except: except:
pass pass
except: except:

View file

@ -258,10 +258,11 @@ class Plex_DB_Functions():
def getItem_byKodiId(self, kodi_id, kodi_type): def getItem_byKodiId(self, kodi_id, kodi_type):
""" """
Returns the tuple (plex_id, parent_id) for kodi_id and kodi_type Returns the tuple (plex_id, parent_id, plex_type) for kodi_id and
kodi_type
""" """
query = ''' query = '''
SELECT plex_id, parent_id SELECT plex_id, parent_id, plex_type
FROM plex FROM plex
WHERE kodi_id = ? WHERE kodi_id = ?
AND kodi_type = ? AND kodi_type = ?