Change way item is added to Plex playqueue by using PMS machine identifier

This commit is contained in:
croneter 2019-08-09 13:40:18 +02:00
parent 9139669f44
commit 0d7a1b3a9f
3 changed files with 14 additions and 29 deletions

View file

@ -234,14 +234,9 @@ def _playback_init(plex_id, plex_type, playqueue, pos):
playqueue.clear()
if plex_type != v.PLEX_TYPE_CLIP:
# Post to the PMS to create a playqueue - in any case due to Companion
section_uuid = xml.attrib.get('librarySectionUUID')
xml = PF.init_plex_playqueue(plex_id,
section_uuid,
mediatype=plex_type,
trailers=trailers)
xml = PF.init_plex_playqueue(plex_id, plex_type, trailers=trailers)
if xml is None:
LOG.error('Could not get a playqueue xml for plex id %s, UUID %s',
plex_id, section_uuid)
LOG.error('Could not get a playqueue xml for plex id %s', plex_id)
# "Play error"
utils.dialog('notification',
utils.lang(29999),

View file

@ -137,11 +137,10 @@ class Playlist_Item(object):
id = None [int] Plex playlist/playqueue id, e.g. playQueueItemID
plex_id = None [int] Plex unique item id, "ratingKey"
plex_type = None [str] Plex type, e.g. 'movie', 'clip'
plex_uuid = None [str] Plex librarySectionUUID
kodi_id = None [int] Kodi unique kodi id (unique only within type!)
kodi_type = None [str] Kodi type: 'movie'
file = None [str] Path to the item's file. STRING!!
uri = None [str] Weird Plex uri path involving plex_uuid. STRING!
uri = None [str] PMS path to item; will be auto-set with plex_id
guid = None [str] Weird Plex guid
xml = None [etree] XML from PMS, 1 lvl below <MediaContainer>
playmethod = None [str] either 'DirectPlay', 'DirectStream', 'Transcode'
@ -154,11 +153,10 @@ class Playlist_Item(object):
self._id = None
self._plex_id = None
self.plex_type = None
self.plex_uuid = None
self._kodi_id = None
self.kodi_type = None
self.file = None
self.uri = None
self._uri = None
self.guid = None
self.xml = None
self.playmethod = None
@ -182,6 +180,12 @@ class Playlist_Item(object):
if not isinstance(value, int) and value is not None:
raise TypeError('Passed %s instead of int!' % type(value))
self._plex_id = value
self._uri = ('server://%s/com.plexapp.plugins.library/library/metadata/%s' %
(app.CONN.machine_identifier, value))
@property
def uri(self):
return self._uri
@property
def id(self):
@ -238,11 +242,9 @@ class Playlist_Item(object):
"'id': {self.id}, "
"'plex_id': {self.plex_id}, "
"'plex_type': '{self.plex_type}', "
"'plex_uuid': '{self.plex_uuid}', "
"'kodi_id': {self.kodi_id}, "
"'kodi_type': '{self.kodi_type}', "
"'file': '{self.file}', "
"'uri': '{self.uri}', "
"'guid': '{self.guid}', "
"'playmethod': '{self.playmethod}', "
"'playcount': {self.playcount}, "
@ -328,7 +330,6 @@ def playlist_item_from_kodi(kodi_item):
if db_item:
item.plex_id = db_item['plex_id']
item.plex_type = db_item['plex_type']
item.plex_uuid = db_item['plex_id'] # we dont need the uuid yet :-)
item.file = kodi_item.get('file')
if item.plex_id is None and item.file is not None:
try:
@ -338,13 +339,6 @@ def playlist_item_from_kodi(kodi_item):
query = dict(utils.parse_qsl(query))
item.plex_id = utils.cast(int, query.get('plex_id'))
item.plex_type = query.get('itemType')
if item.plex_id is None and item.file is not None:
item.uri = ('library://whatever/item/%s'
% utils.quote(item.file, safe=''))
else:
# TO BE VERIFIED - PLEX DOESN'T LIKE PLAYLIST ADDS IN THIS MANNER
item.uri = ('library://%s/item/library%%2Fmetadata%%2F%s' %
(item.plex_uuid, item.plex_id))
LOG.debug('Made playlist item from Kodi: %s', item)
return item
@ -408,9 +402,6 @@ def playlist_item_from_plex(plex_id):
item.kodi_type = db_item['kodi_type']
else:
raise KeyError('Could not find plex_id %s in database' % plex_id)
item.plex_uuid = plex_id
item.uri = ('library://%s/item/library%%2Fmetadata%%2F%s' %
(item.plex_uuid, plex_id))
LOG.debug('Made playlist item from plex: %s', item)
return item

View file

@ -820,16 +820,15 @@ def get_plex_sections():
return xml
def init_plex_playqueue(plex_id, librarySectionUUID, mediatype='movie',
trailers=False):
def init_plex_playqueue(plex_id, plex_type, trailers=False):
"""
Returns raw API metadata XML dump for a playlist with e.g. trailers.
"""
url = "{server}/playQueues"
args = {
'type': mediatype,
'uri': ('library://{0}/item/%2Flibrary%2Fmetadata%2F{1}'.format(
librarySectionUUID, plex_id)),
'type': plex_type,
'uri': ('server://%s/com.plexapp.plugins.library/library/metadata/%s' %
(app.CONN.machine_identifier, plex_id)),
'includeChapters': '1',
'shuffle': '0',
'repeat': '0'