From f5ea8cc3ec8086ceaceca0d7fa8269af11d828e6 Mon Sep 17 00:00:00 2001 From: croneter Date: Sat, 4 Aug 2018 15:11:21 +0200 Subject: [PATCH] Choose trailer if several are present (DB reset required) - Fixes #515 --- default.py | 12 +++++++++++- resources/lib/itemtypes.py | 6 +----- resources/lib/plex_api.py | 18 +++++++++++++++--- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/default.py b/default.py index 0539a838..e6c3e85d 100644 --- a/default.py +++ b/default.py @@ -6,7 +6,7 @@ import logging from sys import argv from urlparse import parse_qsl from xbmc import sleep, executebuiltin -from xbmcgui import ListItem +from xbmcgui import ListItem, getCurrentWindowId from xbmcplugin import setResolvedUrl from resources.lib import entrypoint, utils, pickler, pkc_listitem, \ @@ -69,6 +69,16 @@ class Main(): elif mode == 'channels': entrypoint.channels() + elif mode == 'route_to_extras': + # Hack so we can store this path in the Kodi DB + handle = ('plugin://%s?mode=extras&plex_id=%s' + % (v.ADDON_ID, params.get('plex_id'))) + if getCurrentWindowId() == 10025: + # Video Window + executebuiltin('Container.Update(\"%s\")' % handle) + else: + executebuiltin('ActivateWindow(videos, \"%s\")' % handle) + elif mode == 'extras': entrypoint.extras(plex_id=params.get('plex_id')) diff --git a/resources/lib/itemtypes.py b/resources/lib/itemtypes.py index 85867c68..17beb66f 100644 --- a/resources/lib/itemtypes.py +++ b/resources/lib/itemtypes.py @@ -207,11 +207,7 @@ class Movies(Items): studio = studios[0] except IndexError: studio = None - - trailer = api.trailer_id() - if trailer: - trailer = ('plugin://%s.movies/?plex_id=%s&plex_type=%s&mode=play' - % (v.ADDON_ID, trailer, v.PLEX_TYPE_CLIP)) + trailer = api.trailers() # GET THE FILE AND PATH ##### do_indirect = not state.DIRECT_PATHS diff --git a/resources/lib/plex_api.py b/resources/lib/plex_api.py index 0b4e6adf..e04d8ed7 100644 --- a/resources/lib/plex_api.py +++ b/resources/lib/plex_api.py @@ -728,10 +728,13 @@ class API(object): answ.append(extra) return answ - def trailer_id(self): + def trailers(self): """ - Returns the ratingKey (plex_id) of the trailer or None + Returns the URL for a single trailer, an addon path for extras + (route_to_extras) if several trailers are present. Or None """ + url = None + number = 0 for extras in self.item.iterfind('Extras'): for extra in extras: try: @@ -740,7 +743,16 @@ class API(object): typus = None if typus != 1: continue - return extra.get('ratingKey') + number += 1 + url = extra.get('ratingKey') + if number > 1: + # Several trailers present. Hence let the user choose + url = ('plugin://%s?mode=route_to_extras&plex_id=%s' + % (v.ADDON_ID, self.plex_id())) + elif url: + url = ('plugin://%s.movies/?plex_id=%s&plex_type=%s&mode=play' + % (v.ADDON_ID, url, v.PLEX_TYPE_CLIP)) + return url def mediastreams(self): """