Audio and subtitles automatically set for playback

Currently only available for direct play. Unsure if this works with
direct paths. To find out.
This commit is contained in:
angelblue05 2015-06-07 22:48:28 -05:00
parent 43b1e3b0eb
commit de928ec669
3 changed files with 105 additions and 3 deletions

View file

@ -138,9 +138,6 @@ class PlaybackUtils():
WINDOW.clearProperty(playurl+"seektime") WINDOW.clearProperty(playurl+"seektime")
else: else:
WINDOW.clearProperty(playurl+"seektime") WINDOW.clearProperty(playurl+"seektime")
'''else:
# Playback started from library
WINDOW.setProperty(playurl+"seektime", str(seekTime))'''
if result.get("Type")=="Episode": if result.get("Type")=="Episode":
WINDOW.setProperty(playurl+"refresh_id", result.get("SeriesId")) WINDOW.setProperty(playurl+"refresh_id", result.get("SeriesId"))
@ -153,6 +150,12 @@ class PlaybackUtils():
mediaSources = result.get("MediaSources") mediaSources = result.get("MediaSources")
if(mediaSources != None): if(mediaSources != None):
mediaStream = mediaSources[0].get('MediaStreams')
defaultsubs = ""
for stream in mediaStream:
if u'Subtitle' in stream[u'Type'] and stream[u'IsDefault']:
defaultsubs = stream[u'Codec']
WINDOW.setProperty("%ssubs" % playurl, defaultsubs.encode('utf-8'))
if mediaSources[0].get('DefaultAudioStreamIndex') != None: if mediaSources[0].get('DefaultAudioStreamIndex') != None:
WINDOW.setProperty(playurl+"AudioStreamIndex", str(mediaSources[0].get('DefaultAudioStreamIndex'))) WINDOW.setProperty(playurl+"AudioStreamIndex", str(mediaSources[0].get('DefaultAudioStreamIndex')))
if mediaSources[0].get('DefaultSubtitleStreamIndex') != None: if mediaSources[0].get('DefaultSubtitleStreamIndex') != None:

View file

@ -43,6 +43,9 @@ class Player( xbmc.Player ):
settings = None settings = None
playStats = {} playStats = {}
audioPref = addon.getSetting('Audiopref')
subsPref = addon.getSetting('Subspref')
def __init__( self, *args ): def __init__( self, *args ):
self.__dict__ = self._shared_state self.__dict__ = self._shared_state
@ -220,6 +223,8 @@ class Player( xbmc.Player ):
def onPlayBackStarted( self ): def onPlayBackStarted( self ):
# Will be called when xbmc starts playing a file # Will be called when xbmc starts playing a file
WINDOW = self.WINDOW WINDOW = self.WINDOW
self.addon = xbmcaddon.Addon(id=self.addonId)
addon = self.addon
xbmcplayer = self.xbmcplayer xbmcplayer = self.xbmcplayer
self.stopAll() self.stopAll()
@ -231,6 +236,99 @@ class Player( xbmc.Player ):
except: pass except: pass
self.logMsg("onPlayBackStarted: %s" % currentFile, 0) self.logMsg("onPlayBackStarted: %s" % currentFile, 0)
playMethod = WINDOW.getProperty(currentFile + "playmethod")
# Set audio and subtitles automatically
# Following Emby user preference.
if playMethod == "DirectPlay":
# Only currently compatible with DirectPlay.
# Tested on plugin://, unsure about direct paths.
audiotracks = xbmcplayer.getAvailableAudioStreams()
subs = xbmcplayer.getAvailableSubtitleStreams()
self.logMsg("%s %s" % (audiotracks, subs), 1)
defaultsubs = WINDOW.getProperty("%ssubs" % currentFile)
codecs = [
# To be adjusted and include every codec Emby server can return.
'und','Stereo','Stereo - Stereo','AC3 5.1'
]
if len(audiotracks) == 1 and len(subs) == 0:
# There's only one audio track and no subtitles
xbmcplayer.showSubtitles(False)
elif self.audioPref in audiotracks:
self.logMsg("Door 1", 2)
# Audio pref is available
index = audiotracks.index(self.audioPref)
xbmcplayer.setAudioStream(index)
if addon.getSetting('subsoverride') == "true":
if self.subsPref in subs:
self.logMsg("Door 1.1", 2)
# Subs are forced.
index = subs.index(self.subsPref)
xbmcplayer.setSubtitleStream(index)
else:
# Use default subs
if defaultsubs == "ssa":
# For some reason, Kodi sees SSA as ''
self.logMsg("Door 1.2", 2)
index = subs.index('')
xbmcplayer.setSubtitleStream(index)
elif defaultsubs:
self.logMsg("Door 1.3", 2)
index = subs.index(defaultsubs)
xbmcplayer.setSubtitleStream(index)
else:
xbmcplayer.showSubtitles(False)
elif len(audiotracks) == 1 and '\n'.join(audiotracks) not in codecs:
self.logMsg("Door 2", 2)
# 1. There's one audio track.
# 2. The audio is defined as a language.
# 3. Audio pref is not available, guaranteed.
if self.subsPref in subs:
self.logMsg("Door 2.1", 2)
# Subs pref is available.
index = subs.index(self.subsPref)
xbmcplayer.setSubtitleStream(index)
else:
# Use default subs
if defaultsubs == "ssa":
# For some reason, Kodi sees SSA as ''
self.logMsg("Door 2.2", 2)
index = subs.index('')
xbmcplayer.setSubtitleStream(index)
elif defaultsubs:
self.logMsg("Door 2.3", 2)
index = subs.index(defaultsubs)
xbmcplayer.setSubtitleStream(index)
elif len(audiotracks) == 1 and '\n'.join(audiotracks) in codecs:
self.logMsg("Door 3", 2)
# 1. There one audio track.
# 2. The audio is undefined or a codec.
# 3. Audio pref could be mislabelled.
if addon.getSetting('subsoverride') == "true":
if self.subsPref in subs:
# Subs are forced.
self.logMsg("Door 3.1", 2)
# Only display if subs language is different than audio.
index = subs.index(self.subsPref)
xbmcplayer.setSubtitleStream(index)
else:
# Use default subs
if defaultsubs == "ssa":
# For some reason, Kodi sees SSA as ''
self.logMsg("Door 3.2", 2)
index = subs.index('')
xbmcplayer.setSubtitleStream(index)
elif defaultsubs:
self.logMsg("Door 3.3", 2)
index = subs.index(defaultsubs)
xbmcplayer.setSubtitleStream(index)
# we may need to wait until the info is available # we may need to wait until the info is available
item_id = WINDOW.getProperty(currentFile + "item_id") item_id = WINDOW.getProperty(currentFile + "item_id")
tryCount = 0 tryCount = 0

View file

@ -27,6 +27,7 @@
<setting id="playFromStream" type="bool" label="30002" visible="true" enable="true" default="false" /> <setting id="playFromStream" type="bool" label="30002" visible="true" enable="true" default="false" />
<setting id="videoBitRate" type="enum" label="30160" values="664 Kbps SD|996 Kbps HD|1.3 Mbps HD|2.0 Mbps HD|3.2 Mbps HD|4.7 Mbps HD|6.2 Mbps HD|7.7 Mbps HD|9.2 Mbps HD|10.7 Mbps HD|12.2 Mbps HD|13.7 Mbps HD|15.2 Mbps HD|16.7 Mbps HD|18.2 Mbps HD|20.0 Mbps HD|40.0 Mbps HD|100.0 Mbps HD [default]|1000.0 Mbps HD" visible="eq(-1,true)" default="17" /> <setting id="videoBitRate" type="enum" label="30160" values="664 Kbps SD|996 Kbps HD|1.3 Mbps HD|2.0 Mbps HD|3.2 Mbps HD|4.7 Mbps HD|6.2 Mbps HD|7.7 Mbps HD|9.2 Mbps HD|10.7 Mbps HD|12.2 Mbps HD|13.7 Mbps HD|15.2 Mbps HD|16.7 Mbps HD|18.2 Mbps HD|20.0 Mbps HD|40.0 Mbps HD|100.0 Mbps HD [default]|1000.0 Mbps HD" visible="eq(-1,true)" default="17" />
<setting id="forceTranscodingCodecs" type="text" label="30245" visible="false" /> <setting id="forceTranscodingCodecs" type="text" label="30245" visible="false" />
<setting id="subsoverride" type="bool" label="Always display subtitles" default="false" enable="true" visible="true" />
</category> </category>
<category label="Extras"> <category label="Extras">
<setting id="disableCoverArt" type="bool" label="30157" default="false" visible="true" enable="true" /> <setting id="disableCoverArt" type="bool" label="30157" default="false" visible="true" enable="true" />