diff --git a/resources/lib/PlexAPI.py b/resources/lib/PlexAPI.py index c9205342..9dcd9bf4 100644 --- a/resources/lib/PlexAPI.py +++ b/resources/lib/PlexAPI.py @@ -1709,11 +1709,13 @@ class API(): def getExtras(self): """ + Currently ONLY returns the very first trailer found! + Returns a list of trailer and extras from PMS XML. Returns [] if no extras are found. Extratypes: - '1': Trailer - '5': Behind the scenes + 1: Trailer + 5: Behind the scenes Output: list of dicts with one entry of the form: 'key': e.g. /library/metadata/xxxx @@ -1725,14 +1727,21 @@ class API(): 'year': """ elements = [] - for extra in self.item.findall('Extras'): - # Trailer: + extras = self.item.find('Extras') + if extras is None: + return elements + for extra in extras: + try: + extraType = int(extra.attrib['extraType']) + except: + extraType = None + if extraType != 1: + continue key = extra.attrib.get('key', None) title = extra.attrib.get('title', None) thumb = extra.attrib.get('thumb', None) duration = float(extra.attrib.get('duration', 0.0)) year = extra.attrib.get('year', None) - extraType = extra.attrib.get('extraType', None) originallyAvailableAt = extra.attrib.get( 'originallyAvailableAt', None) elements.append( @@ -1745,6 +1754,7 @@ class API(): 'originallyAvailableAt': originallyAvailableAt, 'year': year }) + break return elements def getMediaStreams(self): diff --git a/resources/lib/itemtypes.py b/resources/lib/itemtypes.py index 695cf88c..c8ed2153 100644 --- a/resources/lib/itemtypes.py +++ b/resources/lib/itemtypes.py @@ -383,7 +383,7 @@ class Movies(Items): extras = API.getExtras() for extra in extras: # Only get 1st trailer element - if extra['extraType'] == '1': + if extra['extraType'] == 1: trailer = ("plugin://plugin.video.plexkodiconnect/trailer/?" "id=%s&mode=play") % extra['key'] break