From f3c8ba707773394fe9162a9cbac0abb330f8329d Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Thu, 21 Jan 2016 11:10:01 -0600 Subject: [PATCH 1/5] New transcode method for subs Extract subtitles and append them to the player, rather than burning them (burning them would result in playback failure 80% of the time) --- resources/lib/playbackutils.py | 4 ++-- resources/lib/playutils.py | 25 +++++++++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/resources/lib/playbackutils.py b/resources/lib/playbackutils.py index 4ab5ba0f..3ec60b64 100644 --- a/resources/lib/playbackutils.py +++ b/resources/lib/playbackutils.py @@ -189,7 +189,7 @@ class PlaybackUtils(): # For transcoding only, ask for audio/subs pref if utils.window('emby_%s.playmethod' % playurl) == "Transcode": - playurl = playutils.audioSubsPref(playurl) + playurl = playutils.audioSubsPref(playurl, listitem) utils.window('emby_%s.playmethod' % playurl, value="Transcode") listitem.setPath(playurl) @@ -232,7 +232,7 @@ class PlaybackUtils(): playmethod = utils.window('%s.playmethod' % embyitem) # Only for direct play and direct stream subtitles = self.externalSubs(playurl) - if playmethod in ("DirectStream", "Transcode"): + if playmethod != "Transcode": # Direct play automatically appends external listitem.setSubtitles(subtitles) diff --git a/resources/lib/playutils.py b/resources/lib/playutils.py index 10575a71..8b5474aa 100644 --- a/resources/lib/playutils.py +++ b/resources/lib/playutils.py @@ -323,7 +323,7 @@ class PlayUtils(): # max bit rate supported by server (max signed 32bit integer) return bitrate.get(videoQuality, 2147483) - def audioSubsPref(self, url): + def audioSubsPref(self, url, listitem): # For transcoding only # Present the list of audio to select from audioStreamsList = {} @@ -331,6 +331,7 @@ class PlayUtils(): audioStreamsChannelsList = {} subtitleStreamsList = {} subtitleStreams = ['No subtitles'] + downloadableStreams = [] selectAudioIndex = "" selectSubsIndex = "" playurlprefs = "%s" % url @@ -361,8 +362,8 @@ class PlayUtils(): audioStreams.append(track) elif 'Subtitle' in type: - if stream['IsExternal']: - continue + '''if stream['IsExternal']: + continue''' try: track = "%s - %s" % (index, stream['Language']) except: @@ -370,10 +371,14 @@ class PlayUtils(): default = stream['IsDefault'] forced = stream['IsForced'] + downloadable = stream['IsTextSubtitleStream'] + if default: track = "%s - Default" % track if forced: track = "%s - Forced" % track + if downloadable: + downloadableStreams.append(index) subtitleStreamsList[track] = index subtitleStreams.append(track) @@ -401,7 +406,19 @@ class PlayUtils(): # User selected subtitles selected = subtitleStreams[resp] selectSubsIndex = subtitleStreamsList[selected] - playurlprefs += "&SubtitleStreamIndex=%s" % selectSubsIndex + + # Load subtitles in the listitem if downloadable + if selectSubsIndex in downloadableStreams: + + itemid = item['Id'] + url = [("%s/Videos/%s/%s/Subtitles/%s/Stream.srt" + % (self.server, itemid, itemid, selectSubsIndex))] + self.logMsg("Set up subtitles: %s %s" % (selectSubsIndex, url), 1) + listitem.setSubtitles(url) + else: + # Burn subtitles + playurlprefs += "&SubtitleStreamIndex=%s" % selectSubsIndex + else: # User backed out of selection playurlprefs += "&SubtitleStreamIndex=%s" % mediasources.get('DefaultSubtitleStreamIndex', "") From 8adfa7a91183ee877fea58d09ffc6ff8c2f2b17f Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Thu, 21 Jan 2016 13:13:26 -0600 Subject: [PATCH 2/5] Missing version bump --- addon.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon.xml b/addon.xml index 8cd6d717..4948d7ab 100644 --- a/addon.xml +++ b/addon.xml @@ -1,7 +1,7 @@ From 65be0b6262f58bed985959989c0877a37998162f Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Thu, 21 Jan 2016 14:35:24 -0600 Subject: [PATCH 3/5] Fixing unicode bug for device name Removing decode to unicode, because we use it for the downloadutils. We need it in utf-8, not unicode. --- resources/lib/clientinfo.py | 2 +- resources/lib/downloadutils.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/resources/lib/clientinfo.py b/resources/lib/clientinfo.py index 44ed98f2..94f7d207 100644 --- a/resources/lib/clientinfo.py +++ b/resources/lib/clientinfo.py @@ -44,7 +44,7 @@ class ClientInfo(): if utils.settings('deviceNameOpt') == "false": # Use Kodi's deviceName - deviceName = xbmc.getInfoLabel('System.FriendlyName').decode('utf-8') + deviceName = xbmc.getInfoLabel('System.FriendlyName') else: deviceName = utils.settings('deviceName') deviceName = deviceName.replace("\"", "_") diff --git a/resources/lib/downloadutils.py b/resources/lib/downloadutils.py index 578c932c..e68d1951 100644 --- a/resources/lib/downloadutils.py +++ b/resources/lib/downloadutils.py @@ -189,7 +189,7 @@ class DownloadUtils(): # If user is not authenticated auth = ( 'MediaBrowser Client="Kodi", Device="%s", DeviceId="%s", Version="%s"' - % (deviceName, deviceId, version)) + % (deviceName, deviceId.encode('utf-8'), version.encode('utf-8'))) header = { 'Content-type': 'application/json', @@ -205,7 +205,8 @@ class DownloadUtils(): # Attached to the requests session auth = ( 'MediaBrowser UserId="%s", Client="Kodi", Device="%s", DeviceId="%s", Version="%s"' - % (userId, deviceName, deviceId, version)) + % (userId.encode('utf-8'), deviceName, deviceId.encode('utf-8'), + version.encode('utf-8'))) header = { 'Content-type': 'application/json', @@ -274,7 +275,6 @@ class DownloadUtils(): verify=verifyssl) elif type == "POST": - print url r = requests.post(url, json=postBody, headers=header, From c54108cfa748cc04b258ee6a64afc9d504b78488 Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Thu, 21 Jan 2016 16:32:30 -0600 Subject: [PATCH 4/5] Normalize device name Server is unable to display unicode correctly for device names. Luke is aware of this. --- resources/lib/clientinfo.py | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/lib/clientinfo.py b/resources/lib/clientinfo.py index 94f7d207..4479d8b9 100644 --- a/resources/lib/clientinfo.py +++ b/resources/lib/clientinfo.py @@ -45,6 +45,7 @@ class ClientInfo(): if utils.settings('deviceNameOpt') == "false": # Use Kodi's deviceName deviceName = xbmc.getInfoLabel('System.FriendlyName') + deviceName = utils.normalize_string(deviceName) else: deviceName = utils.settings('deviceName') deviceName = deviceName.replace("\"", "_") From c28b43451f071c904c5f9255d6bc94be21e261ac Mon Sep 17 00:00:00 2001 From: angelblue05 Date: Thu, 21 Jan 2016 16:34:35 -0600 Subject: [PATCH 5/5] Revert useless unicode changes Now that the device name is normalized without special characters. --- resources/lib/downloadutils.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/resources/lib/downloadutils.py b/resources/lib/downloadutils.py index e68d1951..1c244e74 100644 --- a/resources/lib/downloadutils.py +++ b/resources/lib/downloadutils.py @@ -189,7 +189,7 @@ class DownloadUtils(): # If user is not authenticated auth = ( 'MediaBrowser Client="Kodi", Device="%s", DeviceId="%s", Version="%s"' - % (deviceName, deviceId.encode('utf-8'), version.encode('utf-8'))) + % (deviceName, deviceId, version)) header = { 'Content-type': 'application/json', @@ -205,8 +205,7 @@ class DownloadUtils(): # Attached to the requests session auth = ( 'MediaBrowser UserId="%s", Client="Kodi", Device="%s", DeviceId="%s", Version="%s"' - % (userId.encode('utf-8'), deviceName, deviceId.encode('utf-8'), - version.encode('utf-8'))) + % (userId, deviceName, deviceId, version)) header = { 'Content-type': 'application/json',