Plex trailers directly playable now

This commit is contained in:
tomkat83 2016-01-12 11:47:48 +01:00
parent 0b38176fa9
commit 57e6d40af2
4 changed files with 70 additions and 13 deletions

View file

@ -1914,6 +1914,45 @@ class API():
}
return videoCodec
def getExtras(self):
"""
Returns a list of trailer and extras from PMS XML. Returns None if
no extras are found.
Extratypes:
'1': Trailer
'5': Behind the scenes
Output: list of dicts with one entry of the form:
'key': e.g. /library/metadata/xxxx
'title':
'thumb': artwork
'duration':
'extraType':
'originallyAvailableAt':
'year':
"""
extras = self.item[0].find('Extras')
if not extras:
return None
elements = []
for extra in extras:
# Trailer:
key = extra.attrib['key']
title = extra.attrib['title']
thumb = extra.attrib['thumb']
duration = extra.attrib['duration']
year = extra.attrib['year']
extraType = extra.attrib['extraType']
originallyAvailableAt = extra.attrib['originallyAvailableAt']
elements.append({'key': key,
'title': title,
'thumb': thumb,
'duration': duration,
'extraType': extraType,
'originallyAvailableAt': originallyAvailableAt,
'year': year})
return elements
def getMediaStreams(self):
"""
Returns the media streams
@ -2291,7 +2330,12 @@ class API():
"""
item = self.item
key = self.getKey()
uuid = item.attrib['librarySectionUUID']
try:
uuid = item.attrib['librarySectionUUID']
# if not found: probably trying to start a trailer directly
# Hence no playlist needed
except KeyError:
return None
mediatype = item[self.child].tag.lower()
trailerNumber = utils.settings('trailerNumber')
if not trailerNumber:

View file

@ -34,8 +34,13 @@ def doPlayback(itemid, dbid):
# Get a first XML to get the librarySectionUUID
item = PlexAPI.PlexAPI().GetPlexMetadata(itemid)
# Use that to call the playlist
item = PlexAPI.API(item).GetPlexPlaylist()
pbutils.PlaybackUtils(item).play(itemid, dbid)
playlist = PlexAPI.API(item).GetPlexPlaylist()
if playlist:
pbutils.PlaybackUtils(playlist).play(itemid, dbid)
else:
# No playlist received e.g. when directly playing trailers
pbutils.PlaybackUtils(item).play(itemid, dbid)
##### DO RESET AUTH #####
def resetAuth():

View file

@ -349,9 +349,17 @@ class Movies(Items):
studio = None
self.logMsg("Retrieved metadata for %s" % itemid, 2)
# TODO: trailers
# Find one trailer
trailer = None
self.logMsg("Retrieved trailer for %s" % itemid, 2)
extras = API.getExtras()
if extras:
for item in extras:
# Only get 1st trailer element
if item['extraType'] == '1':
trailer = item['key']
trailer = "plugin://plugin.video.plexkodiconnect/trailer/?id=%s&mode=play" % trailer
self.logMsg("Trailer for %s: %s" % (itemid, trailer), 2)
break
##### GET THE FILE AND PATH #####
playurl = API.getFilePath()

View file

@ -121,14 +121,14 @@ class ThreadedProcessMetadata(threading.Thread):
title = updateItem['title']
itemSubFkt = getattr(item, method)
with self.lock:
itemSubFkt(
plexitem,
viewtag=viewName,
viewid=viewId
)
# Keep track of where we are at
processMetadataCount += 1
processingViewName = title
itemSubFkt(
plexitem,
viewtag=viewName,
viewid=viewId
)
# Keep track of where we are at
processMetadataCount += 1
processingViewName = title
# signals to queue job is done
self.queue.task_done()