Always post to PMS to get playQueue

This commit is contained in:
tomkat83 2016-12-29 15:41:14 +01:00
parent ee86f58a3f
commit 253feb9c69
3 changed files with 40 additions and 30 deletions

View file

@ -384,23 +384,22 @@ def GetPlexCollections(mediatype):
return collections return collections
def GetPlexPlaylist(itemid, librarySectionUUID, mediatype='movie'): def GetPlexPlaylist(itemid, librarySectionUUID, mediatype='movie',
trailers=False):
""" """
Returns raw API metadata XML dump for a playlist with e.g. trailers. Returns raw API metadata XML dump for a playlist with e.g. trailers.
""" """
trailerNumber = settings('trailerNumber')
if not trailerNumber:
trailerNumber = '3'
url = "{server}/playQueues" url = "{server}/playQueues"
args = { args = {
'type': mediatype, 'type': mediatype,
'uri': ('library://' + librarySectionUUID + 'uri': ('library://' + librarySectionUUID +
'/item/%2Flibrary%2Fmetadata%2F' + itemid), '/item/%2Flibrary%2Fmetadata%2F' + itemid),
'includeChapters': '1', 'includeChapters': '1',
'extrasPrefixCount': trailerNumber,
'shuffle': '0', 'shuffle': '0',
'repeat': '0' 'repeat': '0'
} }
if trailers is True:
args['extrasPrefixCount'] = settings('trailerNumber')
xml = downloadutils.DownloadUtils().downloadUrl( xml = downloadutils.DownloadUtils().downloadUrl(
url + '?' + urlencode(args), action_type="POST") url + '?' + urlencode(args), action_type="POST")
try: try:

View file

@ -37,11 +37,7 @@ class PlaybackUtils():
self.userid = window('currUserId') self.userid = window('currUserId')
self.server = window('pms_server') self.server = window('pms_server')
playqueue = Playqueue() self.pl = Playqueue().get_playqueue_from_type(
# We need to initialize already existing items as we have a completely
# different Python instance!
playqueue.init_playlists()
self.pl = playqueue.get_playqueue_from_type(
PF.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[item[0].attrib.get('type')]) PF.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[item[0].attrib.get('type')])
def play(self, itemid, dbid=None): def play(self, itemid, dbid=None):
@ -124,6 +120,22 @@ class PlaybackUtils():
window('plex_playbackProps', value="true") window('plex_playbackProps', value="true")
log.info("Setting up properties in playlist.") log.info("Setting up properties in playlist.")
# Post playQueue to PMS
trailers = False
if settings('enableCinema') == "true":
if settings('askCinema') == "true":
trailers = xbmcgui.Dialog().yesno(addonName,
"Play trailers?")
else:
trailers = True
xml = PF.GetPlexPlaylist(
itemid,
item.attrib.get('librarySectionUUID'),
mediatype=API.getType(),
trailers=trailers)
# Save playQueueID for other PKC python instance & kodimonitor
window('plex_playQueueID', value=xml.attrib.get('playQueueID'))
if (not homeScreen and not seektime and if (not homeScreen and not seektime and
window('plex_customplaylist') != "true" and window('plex_customplaylist') != "true" and
not contextmenu_play): not contextmenu_play):
@ -148,12 +160,8 @@ class PlaybackUtils():
self.currentPosition += 1 self.currentPosition += 1
############### -- CHECK FOR INTROS ################ ############### -- CHECK FOR INTROS ################
if (settings('enableCinema') == "true" and not seektime): if trailers and not seektime:
# if we have any play them when the movie/show is not being resumed # if we have any play them when the movie/show is not being resumed
xml = PF.GetPlexPlaylist(
itemid,
item.attrib.get('librarySectionUUID'),
mediatype=API.getType())
introsPlaylist = self.AddTrailers(xml) introsPlaylist = self.AddTrailers(xml)
############### -- ADD MAIN ITEM ONLY FOR HOMESCREEN ############## ############### -- ADD MAIN ITEM ONLY FOR HOMESCREEN ##############
@ -278,13 +286,6 @@ class PlaybackUtils():
if xml.attrib.get('size') == '1': if xml.attrib.get('size') == '1':
return False return False
if settings('askCinema') == "true":
resp = xbmcgui.Dialog().yesno(addonName, "Play trailers?")
if not resp:
# User selected to not play trailers
log.info("Skip trailers.")
return False
# Playurl needs to point back so we can get metadata! # Playurl needs to point back so we can get metadata!
path = "plugin://plugin.video.plexkodiconnect.movies/" path = "plugin://plugin.video.plexkodiconnect.movies/"
params = { params = {

View file

@ -79,6 +79,13 @@ class Playqueue(Thread):
% kodi_player_id) % kodi_player_id)
return playqueue return playqueue
def _grab_PMS_playqueue(self, playqueue, playqueue_id=None, repeat=None):
"""
For initiating out playqueues from the PMS because another PKC Python
instance already is setting up the Kodi playlists
"""
PL.grab_PMS_playqueue(playqueue, playqueue_id)
@lockmethod.lockthis @lockmethod.lockthis
def update_playqueue_from_PMS(self, def update_playqueue_from_PMS(self,
playqueue, playqueue,
@ -96,7 +103,6 @@ class Playqueue(Thread):
PL.update_playlist_from_PMS(playqueue, playqueue_id) PL.update_playlist_from_PMS(playqueue, playqueue_id)
playqueue.repeat = 0 if not repeat else int(repeat) playqueue.repeat = 0 if not repeat else int(repeat)
log.debug('Updated playqueue: %s' % playqueue) log.debug('Updated playqueue: %s' % playqueue)
window('plex_customplaylist', value="true") window('plex_customplaylist', value="true")
if offset not in (None, "0"): if offset not in (None, "0"):
window('plex_customplaylist.seektime', window('plex_customplaylist.seektime',
@ -153,13 +159,14 @@ class Playqueue(Thread):
} }
""" """
playqueue = self.playqueues[data['playlistid']] playqueue = self.playqueues[data['playlistid']]
if data['item'].get('id') is None and data['item'].get('file') is None: if window('plex_playbackProps') == 'true':
# Kodi screwed up. Let's try to get the data anyway log.debug('kodi_onadd called during PKC playback setup')
items = PL.get_kodi_playlist_items(playqueue) if window('plex_playQueueID'):
if items[data['position']].get('id') is not None: self._grab_PMS_playqueue(playqueue, window('plex_playQueueID'))
data['item']['id'] = items[data['position']].get('id') window('plex_playQueueID', clear=True)
else: log.debug('Done setting up playQueue')
data['item']['file'] = items[data['position']].get('file') return
if playqueue.PKC_playlist_edits: if playqueue.PKC_playlist_edits:
old = (data['item'].get('id') if data['item'].get('id') old = (data['item'].get('id') if data['item'].get('id')
else data['item'].get('file')) else data['item'].get('file'))
@ -182,6 +189,9 @@ class Playqueue(Thread):
RPC output, e.g. RPC output, e.g.
{u'position': 2, u'playlistid': 1} {u'position': 2, u'playlistid': 1}
""" """
if window('plex_playbackProps') == 'true':
log.debug('kodi_onremove called during PKC playback setup')
return
playqueue = self.playqueues[data['playlistid']] playqueue = self.playqueues[data['playlistid']]
PL.delete_playlist_item(playqueue, data['position']) PL.delete_playlist_item(playqueue, data['position'])
log.debug('Deleted item at position %s. New playqueue: %s' log.debug('Deleted item at position %s. New playqueue: %s'