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 PlexFunctions import ParseContainerKey, GetPlexMetadata
|
||||||
from PlexAPI import API
|
from PlexAPI import API
|
||||||
from playlist_func import get_pms_playqueue, get_plextype_from_xml
|
from playlist_func import get_pms_playqueue, get_plextype_from_xml
|
||||||
|
import json_rpc as js
|
||||||
import player
|
import player
|
||||||
import variables as v
|
import variables as v
|
||||||
import state
|
import state
|
||||||
|
@ -155,6 +156,25 @@ class PlexCompanion(Thread):
|
||||||
playqueue,
|
playqueue,
|
||||||
data['playQueueID'])
|
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):
|
def run(self):
|
||||||
"""
|
"""
|
||||||
Ensure that
|
Ensure that
|
||||||
|
|
|
@ -107,5 +107,10 @@ def process_command(request_path, params, queue=None):
|
||||||
js.input_home()
|
js.input_home()
|
||||||
elif request_path == "player/navigation/back":
|
elif request_path == "player/navigation/back":
|
||||||
js.input_back()
|
js.input_back()
|
||||||
|
elif request_path == "player/playback/setStreams":
|
||||||
|
queue.put({
|
||||||
|
'action': 'setStreams',
|
||||||
|
'data': params
|
||||||
|
})
|
||||||
else:
|
else:
|
||||||
LOG.error('Unknown request path: %s', request_path)
|
LOG.error('Unknown request path: %s', request_path)
|
||||||
|
|
|
@ -50,9 +50,8 @@ def get_players():
|
||||||
'picture': ...
|
'picture': ...
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
info = JsonRPC("Player.GetActivePlayers").execute()['result']
|
|
||||||
ret = {}
|
ret = {}
|
||||||
for player in info:
|
for player in JsonRPC("Player.GetActivePlayers").execute()['result']:
|
||||||
player['playerid'] = int(player['playerid'])
|
player['playerid'] = int(player['playerid'])
|
||||||
ret[player['type']] = player
|
ret[player['type']] = player
|
||||||
return ret
|
return ret
|
||||||
|
@ -405,6 +404,15 @@ def get_player_props(playerid):
|
||||||
'currentsubtitle']})['result']
|
'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):
|
def current_audiostream(playerid):
|
||||||
"""
|
"""
|
||||||
Returns a dict of the active audiostream for playerid [int]:
|
Returns a dict of the active audiostream for playerid [int]:
|
||||||
|
|
|
@ -166,6 +166,23 @@ class Playlist_Item(object):
|
||||||
return stream.attrib['id']
|
return stream.attrib['id']
|
||||||
count += 1
|
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):
|
def playlist_item_from_kodi(kodi_item):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue