diff --git a/resources/lib/PlexAPI.py b/resources/lib/PlexAPI.py index 24c0e1f2..cf3c86bf 100644 --- a/resources/lib/PlexAPI.py +++ b/resources/lib/PlexAPI.py @@ -1257,22 +1257,29 @@ class API(): """ return self.item.attrib.get('key') - def getFilePath(self): + def getFilePath(self, forceFirstMediaStream=False): """ Returns the direct path to this item, e.g. '\\NAS\movies\movie.mkv' or None + + forceFirstMediaStream=True: + will always use 1st media stream, e.g. when several different + files are present for the same PMS item """ try: - res = self.item[self.__getMedia()][self.part].attrib.get('file') + if forceFirstMediaStream is False: + ans = self.item[self.__getMedia()][self.part].attrib['file'] + else: + ans = self.item[0][self.part].attrib['file'] except: - res = None - if res is not None: + ans = None + if ans is not None: try: - res = utils.tryDecode(unquote(res)) + ans = utils.tryDecode(unquote(ans)) except UnicodeDecodeError: # Sometimes, Plex seems to have encoded in latin1 - res = unquote(res).decode('latin1') - return res + ans = unquote(ans).decode('latin1') + return ans def getTVShowPath(self): """ @@ -2368,7 +2375,9 @@ class API(): self.item[0][0].attrib['key'])) else: # Native direct paths - path = self.validatePlayurl(self.getFilePath(), 'photo') + path = self.validatePlayurl( + self.getFilePath(forceFirstMediaStream=True), + 'photo') path = utils.tryEncode(path) metadata = { 'date': self.GetKodiPremierDate(), diff --git a/resources/lib/itemtypes.py b/resources/lib/itemtypes.py index f252477a..48d3f38c 100644 --- a/resources/lib/itemtypes.py +++ b/resources/lib/itemtypes.py @@ -411,7 +411,7 @@ class Movies(Items): doIndirect = not self.directpath if self.directpath: # Direct paths is set the Kodi way - playurl = API.getFilePath() + playurl = API.getFilePath(forceFirstMediaStream=True) if playurl is None: # Something went wrong, trying to use non-direct paths doIndirect = True @@ -1302,7 +1302,7 @@ class TVShows(Items): # GET THE FILE AND PATH ##### doIndirect = not self.directpath - playurl = API.getFilePath() + playurl = API.getFilePath(forceFirstMediaStream=True) if self.directpath: # Direct paths is set the Kodi way if playurl is None: @@ -2060,7 +2060,7 @@ class Music(Items): doIndirect = not self.directpath if self.directpath: # Direct paths is set the Kodi way - playurl = API.getFilePath() + playurl = API.getFilePath(forceFirstMediaStream=True) if playurl is None: # Something went wrong, trying to use non-direct paths doIndirect = True