From 4ca321faeaff57f0842a7f3f83f9e3e856263833 Mon Sep 17 00:00:00 2001 From: tomkat83 Date: Mon, 11 Apr 2016 18:57:20 +0200 Subject: [PATCH] Always direct play items, if possible --- resources/lib/PlexAPI.py | 6 ++--- resources/lib/playutils.py | 50 ++++++++++++++++++++++---------------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/resources/lib/PlexAPI.py b/resources/lib/PlexAPI.py index 2cc74335..04f4cd9a 100644 --- a/resources/lib/PlexAPI.py +++ b/resources/lib/PlexAPI.py @@ -1226,7 +1226,7 @@ class API(): or None """ try: - res = self.item[0][0].attrib.get('file') + res = self.item[0][self.part].attrib.get('file') except: res = None if res: @@ -1869,7 +1869,7 @@ class API(): Transcode Video support; returns the URL to get a media started Input: - action 'DirectPlay', 'DirectStream' or 'Transcode' + action 'DirectStream' or 'Transcode' quality: { 'videoResolution': e.g. '1024x768', @@ -1885,7 +1885,7 @@ class API(): xargs = clientinfo.ClientInfo().getXArgsDeviceInfo() # For DirectPlay, path/key of PART is needed - if action == "DirectPlay": + if action == "DirectStream": path = self.item[0][self.part].attrib['key'] url = self.server + path # e.g. Trailers already feature an '?'! diff --git a/resources/lib/playutils.py b/resources/lib/playutils.py index 61823444..90ec5dd2 100644 --- a/resources/lib/playutils.py +++ b/resources/lib/playutils.py @@ -41,21 +41,19 @@ class PlayUtils(): window = utils.window self.API.setPartNumber(partNumber) - playurl = None + playurl = self.isDirectPlay() - if self.isDirectPlay(): + if playurl: log("File is direct playing.", 1) - playurl = self.API.getTranscodeVideoPath('DirectPlay') playurl = playurl.encode('utf-8') # Set playmethod property window('emby_%s.playmethod' % playurl, "DirectPlay") - # Currently no direct streaming possible - needs investigation - # elif self.isDirectStream(): - # self.logMsg("File is direct streaming.", 1) - # playurl = self.API.getTranscodeVideoPath('DirectStream') - # # Set playmethod property - # utils.window('emby_%s.playmethod' % playurl, "DirectStream") + elif self.isDirectStream(): + self.logMsg("File is direct streaming.", 1) + playurl = self.API.getTranscodeVideoPath('DirectStream').encode('utf-8') + # Set playmethod property + utils.window('emby_%s.playmethod' % playurl, "DirectStream") elif self.isTranscoding(): log("File is transcoding.", 1) @@ -64,9 +62,9 @@ class PlayUtils(): 'videoResolution': self.getResolution(), 'videoQuality': '100' } - playurl = self.API.getTranscodeVideoPath('Transcode', - quality=quality) - playurl = playurl.encode('utf-8') + playurl = self.API.getTranscodeVideoPath( + 'Transcode', + quality=quality).encode('utf-8') # Set playmethod property window('emby_%s.playmethod' % playurl, value="Transcode") @@ -89,6 +87,9 @@ class PlayUtils(): return playurl def isDirectPlay(self): + """ + Returns the path/playurl if successful, False otherwise + """ # Requirement: Filesystem, Accessible path if utils.settings('playFromStream') == "true": @@ -99,7 +100,22 @@ class PlayUtils(): if self.h265enabled(): return False - return True + path = self.API.getFilePath() + # Assign network protocol + if path.startswith('\\\\'): + path = path.replace('\\\\', 'smb://') + path = path.replace('\\', '/') + # Plex returns Windows paths as e.g. 'c:\slfkjelf\slfje\file.mkv' + elif '\\' in path: + path = path.replace('\\', '\\\\') + + if xbmcvfs.exists(path): + self.logMsg('Kodi can access file %s - direct playing' % path, 2) + return path + else: + self.logMsg('Kodi cannot access file %s - no direct play' + % path, 2) + return False def directPlay(self): @@ -182,14 +198,6 @@ class PlayUtils(): if not self.h265enabled(): return False - # Requirement: BitRate, supported encoding - # canDirectStream = item['MediaSources'][0]['SupportsDirectStream'] - # Plex: always able?!? - canDirectStream = True - # Make sure the server supports it - if not canDirectStream: - return False - # Verify the bitrate if not self.isNetworkSufficient(): self.logMsg(