This commit is contained in:
Shaun
2018-11-10 10:41:53 +11:00
5 changed files with 75 additions and 47 deletions

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.embycon"
name="EmbyCon"
version="1.5.56"
version="1.5.59"
provider-name="Team B">
<requires>
<import addon="xbmc.python" version="2.25.0"/>

View File

@@ -79,8 +79,8 @@ class DownloadUtils():
"ToggleMute",
"SendString",
"DisplayMessage",
#"SetAudioStreamIndex",
#"SetSubtitleStreamIndex",
"SetAudioStreamIndex",
"SetSubtitleStreamIndex",
"SetRepeatMode",
"Mute",
"Unmute",

View File

@@ -1079,8 +1079,11 @@ def PLAY(params):
media_source_id = params.get("media_source_id", "")
log.debug("media_source_id: {0}", media_source_id)
use_default = params.get("use_default", "false") == "true"
log.debug("use_default: {0}", use_default)
subtitle_stream_index = params.get("subtitle_stream_index")
log.debug("subtitle_stream_index: {0}", subtitle_stream_index)
audio_stream_index = params.get("audio_stream_index")
log.debug("audio_stream_index: {0}", audio_stream_index)
# set the current playing item id
# set all the playback info, this will be picked up by the service
@@ -1093,7 +1096,8 @@ def PLAY(params):
play_info["auto_resume"] = str(auto_resume)
play_info["force_transcode"] = forceTranscode
play_info["media_source_id"] = media_source_id
play_info["use_default"] = use_default
play_info["subtitle_stream_index"] = subtitle_stream_index
play_info["audio_stream_index"] = audio_stream_index
log.info("Sending embycon_play_action : {0}", play_info)
send_event_notification("embycon_play_action", play_info)

View File

@@ -40,6 +40,7 @@ def playAllFiles(items, monitor):
item_id = item.get("Id")
sources = item.get("MediaSources")
selected_media_source = sources[0]
source_id = selected_media_source.get("Id")
listitem_props = []
playback_type = "0"
@@ -77,6 +78,7 @@ def playAllFiles(items, monitor):
# add playurl and data to the monitor
data = {}
data["item_id"] = item_id
data["source_id"] = source_id
data["playback_type"] = playback_type_string
data["play_session_id"] = play_session_id
data["play_action_type"] = "play_all"
@@ -119,7 +121,8 @@ def playFile(play_info, monitor):
auto_resume = play_info.get("auto_resume", "-1")
force_transcode = play_info.get("force_transcode", False)
media_source_id = play_info.get("media_source_id", "")
use_default = play_info.get("use_default", False)
subtitle_stream_index = play_info.get("subtitle_stream_index", None)
audio_stream_index = play_info.get("audio_stream_index", None)
log.debug("playFile id({0}) resume({1}) force_transcode({2})", id, auto_resume, force_transcode)
@@ -200,6 +203,7 @@ def playFile(play_info, monitor):
log.debug("Play Aborted, MediaSource was None")
return
source_id = selected_media_source.get("Id")
seekTime = 0
auto_resume = int(auto_resume)
@@ -298,7 +302,7 @@ def playFile(play_info, monitor):
#list_item = xbmcgui.ListItem(label=item_title)
if playback_type == "2": # if transcoding then prompt for audio and subtitle
playurl = audioSubsPref(playurl, list_item, selected_media_source, id, use_default)
playurl = audioSubsPref(playurl, list_item, selected_media_source, id, audio_stream_index, subtitle_stream_index)
log.debug("New playurl for transcoding: {0}", playurl)
elif playback_type == "1": # for direct stream add any streamable subtitles
@@ -307,6 +311,7 @@ def playFile(play_info, monitor):
# add playurl and data to the monitor
data = {}
data["item_id"] = id
data["source_id"] = source_id
data["playback_type"] = playback_type_string
data["play_session_id"] = play_session_id
data["play_action_type"] = "play"
@@ -488,7 +493,7 @@ def setListItemProps(id, listItem, result, server, extra_props, title):
# Present the list of audio and subtitles to select from
# for external streamable subtitles add the URL to the Kodi item and let Kodi handle it
# else ask for the subtitles to be burnt in when transcoding
def audioSubsPref(url, list_item, media_source, item_id, use_default):
def audioSubsPref(url, list_item, media_source, item_id, audio_stream_index, subtitle_stream_index):
dialog = xbmcgui.Dialog()
audioStreamsList = {}
@@ -497,11 +502,12 @@ def audioSubsPref(url, list_item, media_source, item_id, use_default):
subtitleStreamsList = {}
subtitleStreams = ['No subtitles']
downloadableStreams = []
selectAudioIndex = ""
selectSubsIndex = ""
selectAudioIndex = audio_stream_index
selectSubsIndex = subtitle_stream_index
playurlprefs = "%s" % url
default_audio = media_source.get('DefaultAudioStreamIndex', 1)
default_sub = media_source.get('DefaultSubtitleStreamIndex', "")
source_id = media_source["Id"]
media_streams = media_source['MediaStreams']
@@ -542,8 +548,9 @@ def audioSubsPref(url, list_item, media_source, item_id, use_default):
subtitleStreamsList[track] = index
subtitleStreams.append(track)
if use_default:
playurlprefs += "&AudioStreamIndex=%s" % default_audio
# set audio index
if selectAudioIndex is not None:
playurlprefs += "&AudioStreamIndex=%s" % selectAudioIndex
elif len(audioStreams) > 1:
resp = dialog.select(string_load(30291), audioStreams)
@@ -555,36 +562,40 @@ def audioSubsPref(url, list_item, media_source, item_id, use_default):
else: # User backed out of selection
playurlprefs += "&AudioStreamIndex=%s" % default_audio
elif len(audioStreams) == 1: # There's only one audiotrack.
selectAudioIndex = audioStreamsList[audioStreams[0]]
playurlprefs += "&AudioStreamIndex=%s" % selectAudioIndex
if len(subtitleStreams) > 1:
if use_default:
playurlprefs += "&SubtitleStreamIndex=%s" % default_sub
# set subtitle index
if selectSubsIndex is not None:
# Load subtitles in the listitem if downloadable
if selectSubsIndex in downloadableStreams:
url = [("%s/emby/Videos/%s/%s/Subtitles/%s/Stream.srt"
% (download_utils.getServer(), item_id, source_id, selectSubsIndex))]
log.debug("Streaming subtitles url: {0} {1}", selectSubsIndex, url)
list_item.setSubtitles(url)
else:
resp = dialog.select(string_load(30292), subtitleStreams)
if resp == 0:
# User selected no subtitles
pass
elif resp > -1:
# User selected subtitles
selected = subtitleStreams[resp]
selectSubsIndex = subtitleStreamsList[selected]
# Burn subtitles
playurlprefs += "&SubtitleStreamIndex=%s" % selectSubsIndex
# Load subtitles in the listitem if downloadable
if selectSubsIndex in downloadableStreams:
url = [("%s/Videos/%s/%s/Subtitles/%s/Stream.srt"
% (download_utils.getServer(), item_id, item_id, selectSubsIndex))]
log.debug("Streaming subtitles url: {0} {1}", selectSubsIndex, url)
list_item.setSubtitles(url)
else:
# Burn subtitles
playurlprefs += "&SubtitleStreamIndex=%s" % selectSubsIndex
elif len(subtitleStreams) > 1:
resp = dialog.select(string_load(30292), subtitleStreams)
if resp == 0:
# User selected no subtitles
pass
elif resp > -1:
# User selected subtitles
selected = subtitleStreams[resp]
selectSubsIndex = subtitleStreamsList[selected]
else: # User backed out of selection
playurlprefs += "&SubtitleStreamIndex=%s" % default_sub
# Load subtitles in the listitem if downloadable
if selectSubsIndex in downloadableStreams:
url = [("%s/emby/Videos/%s/%s/Subtitles/%s/Stream.srt"
% (download_utils.getServer(), item_id, source_id, selectSubsIndex))]
log.debug("Streaming subtitles url: {0} {1}", selectSubsIndex, url)
list_item.setSubtitles(url)
else:
# Burn subtitles
playurlprefs += "&SubtitleStreamIndex=%s" % selectSubsIndex
else: # User backed out of selection
playurlprefs += "&SubtitleStreamIndex=%s" % default_sub
# Get number of channels for selected audio track
audioChannels = audioStreamsChannelsList.get(selectAudioIndex, 0)
@@ -613,11 +624,13 @@ def externalSubs(media_source, list_item, item_id):
and stream['SupportsExternalStream']):
index = stream['Index']
url = ("%s/Videos/%s/%s/Subtitles/%s/Stream.%s"
% (download_utils.getServer(), item_id, item_id, index, stream['Codec']))
source_id = media_source['Id']
url = ("%s/emby/Videos/%s/%s/Subtitles/%s/Stream.%s"
% (download_utils.getServer(), item_id, source_id, index, stream['Codec']))
externalsubs.append(url)
log.debug("External Subtitles : {0}", externalsubs)
list_item.setSubtitles(externalsubs)
@@ -649,6 +662,8 @@ def sendProgress(monitor):
if item_id is None:
return
source_id = play_data.get("source_id")
ticks = int(play_time * 10000000)
paused = play_data.get("paused", False)
playback_type = play_data.get("playback_type")
@@ -658,7 +673,7 @@ def sendProgress(monitor):
'QueueableMediaTypes': "Video",
'CanSeek': True,
'ItemId': item_id,
'MediaSourceId': item_id,
'MediaSourceId': source_id,
'PositionTicks': ticks,
'IsPaused': paused,
'IsMuted': False,
@@ -762,14 +777,15 @@ def stopAll(played_information):
current_possition = data.get("currentPossition", 0)
emby_item_id = data.get("item_id")
emby_source_id = data.get("source_id")
if emby_item_id is not None:
if emby_item_id is not None and current_possition >= 0:
log.debug("Playback Stopped at: {0}", current_possition)
url = "{server}/emby/Sessions/Playing/Stopped"
postdata = {
'ItemId': emby_item_id,
'MediaSourceId': emby_item_id,
'MediaSourceId': emby_source_id,
'PositionTicks': int(current_possition * 10000000)
}
download_utils.downloadUrl(url, postBody=postdata, method="POST")
@@ -818,6 +834,7 @@ class Service(xbmc.Player):
data["currently_playing"] = True
emby_item_id = data["item_id"]
emby_source_id = data["source_id"]
playback_type = data["playback_type"]
play_session_id = data["play_session_id"]
@@ -830,7 +847,7 @@ class Service(xbmc.Player):
'QueueableMediaTypes': "Video",
'CanSeek': True,
'ItemId': emby_item_id,
'MediaSourceId': emby_item_id,
'MediaSourceId': emby_source_id,
'PlayMethod': playback_type,
'PlaySessionId': play_session_id
}

View File

@@ -70,6 +70,8 @@ class WebSocketClient(threading.Thread):
log.debug("WebSocket Message PlayNow: {0}", data)
media_source_id = data.get("MediaSourceId", "")
subtitle_stream_index = data.get("SubtitleStreamIndex", None)
audio_stream_index = data.get("AudioStreamIndex", None)
start_index = data.get("StartIndex", 0)
@@ -83,7 +85,8 @@ class WebSocketClient(threading.Thread):
params["item_id"] = item_ids
params["auto_resume"] = str(startat)
params["media_source_id"] = media_source_id
params["use_default"] = "true"
params["subtitle_stream_index"] = subtitle_stream_index
params["audio_stream_index"] = audio_stream_index
PLAY(params)
@@ -145,6 +148,10 @@ class WebSocketClient(threading.Thread):
index = int(arguments['Index'])
player.setAudioStream(index - 1)
elif command == 'SetSubtitleStreamIndex':
index = int(arguments['Index'])
player.setSubtitleStream(index - 1)
elif command == 'SetRepeatMode':
mode = arguments['RepeatMode']
xbmc.executebuiltin('xbmc.PlayerControl(%s)' % mode)