Companion: enable audio and subtitle stream switch
This commit is contained in:
parent
f0a3cd8c55
commit
72de3b6796
4 changed files with 52 additions and 2 deletions
|
@ -14,6 +14,7 @@ from plexbmchelper import listener, plexgdm, subscribers, httppersist
|
|||
from PlexFunctions import ParseContainerKey, GetPlexMetadata
|
||||
from PlexAPI import API
|
||||
from playlist_func import get_pms_playqueue, get_plextype_from_xml
|
||||
import json_rpc as js
|
||||
import player
|
||||
import variables as v
|
||||
import state
|
||||
|
@ -155,6 +156,25 @@ class PlexCompanion(Thread):
|
|||
playqueue,
|
||||
data['playQueueID'])
|
||||
|
||||
elif task['action'] == 'setStreams':
|
||||
# Plex Companion client adjusted audio or subtitle stream
|
||||
playqueue = self.mgr.playqueue.get_playqueue_from_type(
|
||||
v.KODI_PLAYLIST_TYPE_FROM_PLEX_TYPE[data['type']])
|
||||
pos = js.get_position(playqueue.playlistid)
|
||||
if 'audioStreamID' in data:
|
||||
index = playqueue.items[pos].kodi_stream_index(
|
||||
data['audioStreamID'], 'audio')
|
||||
self.player.setAudioStream(index)
|
||||
elif 'subtitleStreamID' in data:
|
||||
if data['subtitleStreamID'] == '0':
|
||||
self.player.showSubtitles(False)
|
||||
else:
|
||||
index = playqueue.items[pos].kodi_stream_index(
|
||||
data['subtitleStreamID'], 'subtitle')
|
||||
self.player.setSubtitleStream(index)
|
||||
else:
|
||||
LOG.error('Unknown setStreams command: %s', task)
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
Ensure that
|
||||
|
|
|
@ -107,5 +107,10 @@ def process_command(request_path, params, queue=None):
|
|||
js.input_home()
|
||||
elif request_path == "player/navigation/back":
|
||||
js.input_back()
|
||||
elif request_path == "player/playback/setStreams":
|
||||
queue.put({
|
||||
'action': 'setStreams',
|
||||
'data': params
|
||||
})
|
||||
else:
|
||||
LOG.error('Unknown request path: %s', request_path)
|
||||
|
|
|
@ -50,9 +50,8 @@ def get_players():
|
|||
'picture': ...
|
||||
}
|
||||
"""
|
||||
info = JsonRPC("Player.GetActivePlayers").execute()['result']
|
||||
ret = {}
|
||||
for player in info:
|
||||
for player in JsonRPC("Player.GetActivePlayers").execute()['result']:
|
||||
player['playerid'] = int(player['playerid'])
|
||||
ret[player['type']] = player
|
||||
return ret
|
||||
|
@ -405,6 +404,15 @@ def get_player_props(playerid):
|
|||
'currentsubtitle']})['result']
|
||||
|
||||
|
||||
def get_position(playerid):
|
||||
"""
|
||||
Returns the currently playing item's position [int] within the playlist
|
||||
"""
|
||||
return JsonRPC('Player.GetProperties').execute({
|
||||
'playerid': playerid,
|
||||
'properties': ['position']})['result']['position']
|
||||
|
||||
|
||||
def current_audiostream(playerid):
|
||||
"""
|
||||
Returns a dict of the active audiostream for playerid [int]:
|
||||
|
|
|
@ -166,6 +166,23 @@ class Playlist_Item(object):
|
|||
return stream.attrib['id']
|
||||
count += 1
|
||||
|
||||
def kodi_stream_index(self, plex_stream_index, stream_type):
|
||||
"""
|
||||
Pass in the kodi_stream_index [int] in order to receive the Plex stream
|
||||
index.
|
||||
|
||||
stream_type: 'video', 'audio', 'subtitle'
|
||||
|
||||
Returns None if unsuccessful
|
||||
"""
|
||||
stream_type = v.PLEX_STREAM_TYPE_FROM_STREAM_TYPE[stream_type]
|
||||
count = 0
|
||||
for stream in self.xml[0][self.part]:
|
||||
if stream.attrib['streamType'] == stream_type:
|
||||
if stream.attrib['id'] == plex_stream_index:
|
||||
return count
|
||||
count += 1
|
||||
|
||||
|
||||
def playlist_item_from_kodi(kodi_item):
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue