Added remote control - audio and subtitle streams
Fix the index of streams to properly reflect the correct ones.
This commit is contained in:
parent
c7c35fd442
commit
abe60aa3b8
4 changed files with 50 additions and 13 deletions
|
@ -21,8 +21,7 @@ class DownloadUtils():
|
||||||
clientInfo = ClientInformation()
|
clientInfo = ClientInformation()
|
||||||
|
|
||||||
addonName = clientInfo.getAddonName()
|
addonName = clientInfo.getAddonName()
|
||||||
addonId = clientInfo.getAddonId()
|
addon = xbmcaddon.Addon()
|
||||||
addon = xbmcaddon.Addon(id=addonId)
|
|
||||||
WINDOW = xbmcgui.Window(10000)
|
WINDOW = xbmcgui.Window(10000)
|
||||||
|
|
||||||
# Requests session
|
# Requests session
|
||||||
|
@ -79,6 +78,7 @@ class DownloadUtils():
|
||||||
"GoHome,PageUp,NextLetter,GoToSearch,"
|
"GoHome,PageUp,NextLetter,GoToSearch,"
|
||||||
"GoToSettings,PageDown,PreviousLetter,TakeScreenshot,"
|
"GoToSettings,PageDown,PreviousLetter,TakeScreenshot,"
|
||||||
"VolumeUp,VolumeDown,ToggleMute,SendString,DisplayMessage,"
|
"VolumeUp,VolumeDown,ToggleMute,SendString,DisplayMessage,"
|
||||||
|
"SetAudioStreamIndex,SetSubtitleStreamIndex,"
|
||||||
|
|
||||||
"Mute,Unmute,SetVolume,"
|
"Mute,Unmute,SetVolume,"
|
||||||
"Play,Playstate,PlayNext"
|
"Play,Playstate,PlayNext"
|
||||||
|
@ -183,7 +183,6 @@ class DownloadUtils():
|
||||||
# Replace for the real values and append api_key
|
# Replace for the real values and append api_key
|
||||||
url = url.replace("{server}", self.server, 1)
|
url = url.replace("{server}", self.server, 1)
|
||||||
url = url.replace("{UserId}", self.userId, 1)
|
url = url.replace("{UserId}", self.userId, 1)
|
||||||
#url = "%s&api_key=%s" % (url, self.token)
|
|
||||||
|
|
||||||
self.logMsg("URL: %s" % url, 2)
|
self.logMsg("URL: %s" % url, 2)
|
||||||
# Prepare request
|
# Prepare request
|
||||||
|
@ -293,7 +292,7 @@ class DownloadUtils():
|
||||||
if r.headers['X-Application-Error-Code'] == "ParentalControl":
|
if r.headers['X-Application-Error-Code'] == "ParentalControl":
|
||||||
# Parental control - access restricted
|
# Parental control - access restricted
|
||||||
WINDOW.setProperty("Server_status", "restricted")
|
WINDOW.setProperty("Server_status", "restricted")
|
||||||
xbmcgui.Dialog().notification("Emby server", "Access restricted.", xbmcgui.NOTIFICATION_ERROR, time=5000)
|
xbmcgui.Dialog().notification("Emby server", "Access restricted.", xbmcgui.NOTIFICATION_ERROR, icon="special://home/addons/plugin.video.emby/icon.png", time=5000)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if (status == "401") or (status == "Auth"):
|
if (status == "401") or (status == "Auth"):
|
||||||
|
@ -303,7 +302,7 @@ class DownloadUtils():
|
||||||
# Tell UserClient token has been revoked.
|
# Tell UserClient token has been revoked.
|
||||||
WINDOW.setProperty("Server_status", "401")
|
WINDOW.setProperty("Server_status", "401")
|
||||||
self.logMsg("HTTP Error: %s" % e, 0)
|
self.logMsg("HTTP Error: %s" % e, 0)
|
||||||
xbmcgui.Dialog().notification("Error connecting", "Unauthorized.", xbmcgui.NOTIFICATION_ERROR)
|
xbmcgui.Dialog().notification("Error connecting", "Unauthorized.", xbmcgui.NOTIFICATION_ERROR, icon="special://home/addons/plugin.video.emby/icon.png")
|
||||||
return 401
|
return 401
|
||||||
|
|
||||||
elif (r.status_code == 301) or (r.status_code == 302):
|
elif (r.status_code == 301) or (r.status_code == 302):
|
||||||
|
|
|
@ -147,7 +147,7 @@ class PlaybackUtils():
|
||||||
WINDOW.setProperty(playurl+"type", result.get("Type"))
|
WINDOW.setProperty(playurl+"type", result.get("Type"))
|
||||||
WINDOW.setProperty(playurl+"item_id", id)
|
WINDOW.setProperty(playurl+"item_id", id)
|
||||||
|
|
||||||
mediaSources = result.get("MediaSources")
|
'''mediaSources = result.get("MediaSources")
|
||||||
if(mediaSources != None):
|
if(mediaSources != None):
|
||||||
mediaStream = mediaSources[0].get('MediaStreams')
|
mediaStream = mediaSources[0].get('MediaStreams')
|
||||||
defaultsubs = ""
|
defaultsubs = ""
|
||||||
|
@ -161,7 +161,7 @@ class PlaybackUtils():
|
||||||
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:
|
||||||
WINDOW.setProperty(playurl+"SubtitleStreamIndex", str(mediaSources[0].get('DefaultSubtitleStreamIndex')))
|
WINDOW.setProperty(playurl+"SubtitleStreamIndex", str(mediaSources[0].get('DefaultSubtitleStreamIndex')))'''
|
||||||
|
|
||||||
#launch the playback - only set the listitem props if we're not using the setresolvedurl approach
|
#launch the playback - only set the listitem props if we're not using the setresolvedurl approach
|
||||||
if setup == "service":
|
if setup == "service":
|
||||||
|
|
|
@ -176,6 +176,18 @@ class Player( xbmc.Player ):
|
||||||
volume = result.get(u'result').get(u'volume')
|
volume = result.get(u'result').get(u'volume')
|
||||||
muted = result.get(u'result').get(u'muted')
|
muted = result.get(u'result').get(u'muted')
|
||||||
|
|
||||||
|
# Get current audio and subtitles track
|
||||||
|
track_query = '{"jsonrpc": "2.0", "method": "Player.GetProperties", "params": {"playerid":1,"properties": ["currentsubtitle","currentaudiostream"]} , "id": 1}'
|
||||||
|
result = xbmc.executeJSONRPC(track_query)
|
||||||
|
result = json.loads(result)
|
||||||
|
indexAudio = result['result']['currentaudiostream']['index']
|
||||||
|
indexSubs = result['result']['currentsubtitle']['index']
|
||||||
|
|
||||||
|
# Convert back into an Emby index
|
||||||
|
audioTracks = len(xbmc.Player().getAvailableAudioStreams())
|
||||||
|
indexAudio = indexAudio + 1
|
||||||
|
indexSubs = indexSubs + audioTracks + 1
|
||||||
|
|
||||||
postdata = {
|
postdata = {
|
||||||
'QueueableMediaTypes': "Video",
|
'QueueableMediaTypes': "Video",
|
||||||
'CanSeek': True,
|
'CanSeek': True,
|
||||||
|
@ -190,11 +202,17 @@ class Player( xbmc.Player ):
|
||||||
if playTime:
|
if playTime:
|
||||||
postdata['PositionTicks'] = int(playTime * 10000000)
|
postdata['PositionTicks'] = int(playTime * 10000000)
|
||||||
|
|
||||||
if audioindex:
|
if audioindex == indexAudio:
|
||||||
postdata['AudioStreamIndex'] = audioindex
|
postdata['AudioStreamIndex'] = audioindex
|
||||||
|
else:
|
||||||
|
postdata['AudioStreamIndex'] = indexAudio
|
||||||
|
data['AudioStreamIndex'] = indexAudio
|
||||||
|
|
||||||
if subtitleindex:
|
if subtitleindex == indexSubs:
|
||||||
postdata['SubtitleStreamIndex'] = subtitleindex
|
postdata['SubtitleStreamIndex'] = subtitleindex
|
||||||
|
else:
|
||||||
|
postdata['SubtitleStreamIndex'] = indexSubs
|
||||||
|
data['SubtitleStreamIndex'] = indexSubs
|
||||||
|
|
||||||
postdata = json.dumps(postdata)
|
postdata = json.dumps(postdata)
|
||||||
self.logMsg("Report: %s" % postdata, 2)
|
self.logMsg("Report: %s" % postdata, 2)
|
||||||
|
@ -267,6 +285,13 @@ class Player( xbmc.Player ):
|
||||||
volume = result.get(u'result').get(u'volume')
|
volume = result.get(u'result').get(u'volume')
|
||||||
muted = result.get(u'result').get(u'muted')
|
muted = result.get(u'result').get(u'muted')
|
||||||
|
|
||||||
|
# Get the current audio track and subtitles
|
||||||
|
track_query = '{"jsonrpc": "2.0", "method": "Player.GetProperties", "params": {"playerid":1,"properties": ["currentsubtitle","currentaudiostream"]} , "id": 1}'
|
||||||
|
result = xbmc.executeJSONRPC(track_query)
|
||||||
|
result = json.loads(result)
|
||||||
|
indexAudio = result['result']['currentaudiostream']['index']
|
||||||
|
indexSubs = result['result']['currentsubtitle']['index']
|
||||||
|
|
||||||
seekTime = xbmc.Player().getTime()
|
seekTime = xbmc.Player().getTime()
|
||||||
|
|
||||||
url = "{server}/mediabrowser/Sessions/Playing"
|
url = "{server}/mediabrowser/Sessions/Playing"
|
||||||
|
@ -283,9 +308,14 @@ class Player( xbmc.Player ):
|
||||||
|
|
||||||
if audioindex:
|
if audioindex:
|
||||||
postdata['AudioStreamIndex'] = audioindex
|
postdata['AudioStreamIndex'] = audioindex
|
||||||
|
else:
|
||||||
|
postdata['AudioStreamIndex'] = indexAudio + 1
|
||||||
|
|
||||||
if subtitleindex:
|
if subtitleindex:
|
||||||
postdata['SubtitleStreamIndex'] = subtitleindex
|
postdata['SubtitleStreamIndex'] = subtitleindex
|
||||||
|
else:
|
||||||
|
audioTracks = len(xbmc.Player().getAvailableAudioStreams())
|
||||||
|
postdata['SubtitleStreamIndex'] = indexSubs + audioTracks + 1
|
||||||
|
|
||||||
# Post playback to server
|
# Post playback to server
|
||||||
self.logMsg("Sending POST play started.", 1)
|
self.logMsg("Sending POST play started.", 1)
|
||||||
|
@ -297,8 +327,8 @@ class Player( xbmc.Player ):
|
||||||
'item_id': item_id,
|
'item_id': item_id,
|
||||||
'refresh_id': refresh_id,
|
'refresh_id': refresh_id,
|
||||||
'currentfile': currentFile,
|
'currentfile': currentFile,
|
||||||
'AudioStreamIndex': audioindex,
|
'AudioStreamIndex': postdata['AudioStreamIndex'],
|
||||||
'SubtitleStreamIndex': subtitleindex,
|
'SubtitleStreamIndex': postdata['SubtitleStreamIndex'],
|
||||||
'playmethod': playMethod,
|
'playmethod': playMethod,
|
||||||
'Type': itemType,
|
'Type': itemType,
|
||||||
'currentPosition': int(seekTime)
|
'currentPosition': int(seekTime)
|
||||||
|
|
|
@ -96,7 +96,7 @@ class WebSocketThread(threading.Thread):
|
||||||
xbmc.executebuiltin("Dialog.Close(all,true)")
|
xbmc.executebuiltin("Dialog.Close(all,true)")
|
||||||
xbmc.executebuiltin("XBMC.Notification(Playlist: Added %s items to Playlist,)" % len(itemIds))
|
xbmc.executebuiltin("XBMC.Notification(Playlist: Added %s items to Playlist,)" % len(itemIds))
|
||||||
PlaybackUtils().PLAYAllItems(itemIds, startPositionTicks)
|
PlaybackUtils().PLAYAllItems(itemIds, startPositionTicks)
|
||||||
# Don't think this is being used.
|
|
||||||
elif "PlayNext" in playCommand:
|
elif "PlayNext" in playCommand:
|
||||||
xbmc.executebuiltin("XBMC.Notification(Playlist: Added %s items to Playlist,)" % len(itemIds))
|
xbmc.executebuiltin("XBMC.Notification(Playlist: Added %s items to Playlist,)" % len(itemIds))
|
||||||
playlist = PlaybackUtils().AddToPlaylist(itemIds)
|
playlist = PlaybackUtils().AddToPlaylist(itemIds)
|
||||||
|
@ -155,7 +155,7 @@ class WebSocketThread(threading.Thread):
|
||||||
command = data['Name']
|
command = data['Name']
|
||||||
arguments = data.get("Arguments")
|
arguments = data.get("Arguments")
|
||||||
|
|
||||||
if command in ('Mute', 'Unmute', 'SetVolume'):
|
if command in ('Mute', 'Unmute', 'SetVolume', 'SetSubtitleStreamIndex', 'SetAudioStreamIndex'):
|
||||||
# These commands need to be reported back
|
# These commands need to be reported back
|
||||||
if command == "Mute":
|
if command == "Mute":
|
||||||
xbmc.executebuiltin('Mute')
|
xbmc.executebuiltin('Mute')
|
||||||
|
@ -164,6 +164,14 @@ class WebSocketThread(threading.Thread):
|
||||||
elif command == "SetVolume":
|
elif command == "SetVolume":
|
||||||
volume = arguments['Volume']
|
volume = arguments['Volume']
|
||||||
xbmc.executebuiltin('SetVolume(%s[,showvolumebar])' % volume)
|
xbmc.executebuiltin('SetVolume(%s[,showvolumebar])' % volume)
|
||||||
|
elif command == "SetSubtitleStreamIndex":
|
||||||
|
# Emby merges audio and subtitle index together
|
||||||
|
audioTracks = len(xbmc.Player().getAvailableAudioStreams())
|
||||||
|
index = int(arguments['Index']) - audioTracks
|
||||||
|
xbmc.Player().setSubtitleStream(index - 1)
|
||||||
|
elif command == "SetAudioStreamIndex":
|
||||||
|
index = int(arguments['Index'])
|
||||||
|
xbmc.Player().setAudioStream(index - 1)
|
||||||
# Report playback
|
# Report playback
|
||||||
WINDOW.setProperty('commandUpdate', "true")
|
WINDOW.setProperty('commandUpdate', "true")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue