mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 04:06:11 +00:00
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:
parent
43b1e3b0eb
commit
de928ec669
3 changed files with 105 additions and 3 deletions
|
@ -138,9 +138,6 @@ class PlaybackUtils():
|
|||
WINDOW.clearProperty(playurl+"seektime")
|
||||
else:
|
||||
WINDOW.clearProperty(playurl+"seektime")
|
||||
'''else:
|
||||
# Playback started from library
|
||||
WINDOW.setProperty(playurl+"seektime", str(seekTime))'''
|
||||
|
||||
if result.get("Type")=="Episode":
|
||||
WINDOW.setProperty(playurl+"refresh_id", result.get("SeriesId"))
|
||||
|
@ -153,6 +150,12 @@ class PlaybackUtils():
|
|||
|
||||
mediaSources = result.get("MediaSources")
|
||||
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:
|
||||
WINDOW.setProperty(playurl+"AudioStreamIndex", str(mediaSources[0].get('DefaultAudioStreamIndex')))
|
||||
if mediaSources[0].get('DefaultSubtitleStreamIndex') != None:
|
||||
|
|
|
@ -42,6 +42,9 @@ class Player( xbmc.Player ):
|
|||
played_information = {}
|
||||
settings = None
|
||||
playStats = {}
|
||||
|
||||
audioPref = addon.getSetting('Audiopref')
|
||||
subsPref = addon.getSetting('Subspref')
|
||||
|
||||
def __init__( self, *args ):
|
||||
|
||||
|
@ -220,6 +223,8 @@ class Player( xbmc.Player ):
|
|||
def onPlayBackStarted( self ):
|
||||
# Will be called when xbmc starts playing a file
|
||||
WINDOW = self.WINDOW
|
||||
self.addon = xbmcaddon.Addon(id=self.addonId)
|
||||
addon = self.addon
|
||||
xbmcplayer = self.xbmcplayer
|
||||
self.stopAll()
|
||||
|
||||
|
@ -230,6 +235,99 @@ class Player( xbmc.Player ):
|
|||
currentFile = xbmcplayer.getPlayingFile()
|
||||
except: pass
|
||||
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
|
||||
item_id = WINDOW.getProperty(currentFile + "item_id")
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
<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="forceTranscodingCodecs" type="text" label="30245" visible="false" />
|
||||
<setting id="subsoverride" type="bool" label="Always display subtitles" default="false" enable="true" visible="true" />
|
||||
</category>
|
||||
<category label="Extras">
|
||||
<setting id="disableCoverArt" type="bool" label="30157" default="false" visible="true" enable="true" />
|
||||
|
|
Loading…
Reference in a new issue