Merge pull request #1741 from croneter/py3-fix-subs

Fix PKC changing subtitles on playback start unnecessarily
This commit is contained in:
croneter 2021-12-22 14:48:21 +01:00 committed by GitHub
commit b4cdad4181
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 20 deletions

View file

@ -442,8 +442,6 @@ def get_current_subtitle_stream_index(playerid):
""" """
Returns the currently active subtitle stream index [int] or None if there Returns the currently active subtitle stream index [int] or None if there
are no subs are no subs
PICKING UP CHANGES ON SUBTITLES IS CURRENTLY BROKEN ON THE KODI SIDE! The
JSON reply won't change even though subtitles are changed :-(
""" """
try: try:
return JsonRPC('Player.GetProperties').execute({ return JsonRPC('Player.GetProperties').execute({
@ -456,8 +454,6 @@ def get_current_subtitle_stream_index(playerid):
def get_subtitle_enabled(playerid): def get_subtitle_enabled(playerid):
""" """
Returns True if a subtitle is currently enabled, False otherwise. Returns True if a subtitle is currently enabled, False otherwise.
PICKING UP CHANGES ON SUBTITLES IS CURRENTLY BROKEN ON THE KODI SIDE! The
JSON reply won't change even though subtitles are changed :-(
""" """
return JsonRPC('Player.GetProperties').execute({ return JsonRPC('Player.GetProperties').execute({
'playerid': playerid, 'playerid': playerid,

View file

@ -357,6 +357,7 @@ class PlaylistItem(object):
PF.change_video_stream(plex_stream_index, self.api.part_id()) PF.change_video_stream(plex_stream_index, self.api.part_id())
def _set_kodi_stream_if_different(self, kodi_index, typus): def _set_kodi_stream_if_different(self, kodi_index, typus):
"""Will always activate subtitles."""
if typus == 'video': if typus == 'video':
current = js.get_current_video_stream_index(self.playerid) current = js.get_current_video_stream_index(self.playerid)
if current != kodi_index: if current != kodi_index:
@ -371,16 +372,32 @@ class PlaylistItem(object):
app.APP.player.setAudioStream(kodi_index) app.APP.player.setAudioStream(kodi_index)
else: else:
LOG.debug('Not switching audio stream (no change)') LOG.debug('Not switching audio stream (no change)')
elif typus == 'subtitle':
current = js.get_current_subtitle_stream_index(self.playerid)
enabled = js.get_subtitle_enabled(self.playerid)
if current != kodi_index:
LOG.debug('Switching subtitle stream')
app.APP.player.setAudioStream(kodi_index)
else:
LOG.debug('Not switching subtitle stream (no change)')
if not enabled:
LOG.debug('Enabling subtitles')
app.APP.player.showSubtitles(True)
else:
raise RuntimeError('Unknown stream type %s' % typus)
def switch_to_plex_stream(self, typus): def switch_to_plex_stream(self, typus):
try: try:
plex_index, language_tag = self.active_plex_stream_index(typus) plex_index, language_tag = self.active_plex_stream_index(typus)
except TypeError: except TypeError:
# Only happens if Plex did not provide us with a suitable sub
# Meaning Plex tells us to deactivate subs
LOG.debug('Deactivating Kodi subtitles because the PMS ' LOG.debug('Deactivating Kodi subtitles because the PMS '
'told us to not show any subtitles') 'told us to not show any subtitles')
app.APP.player.showSubtitles(False) app.APP.player.showSubtitles(False)
self._current_kodi_sub_stream_enabled = False self._current_kodi_sub_stream_enabled = False
return return
# Rest: video, audio and activated subs
LOG.debug('The PMS wants to display %s stream with Plex id %s and ' LOG.debug('The PMS wants to display %s stream with Plex id %s and '
'languageTag %s', typus, plex_index, language_tag) 'languageTag %s', typus, plex_index, language_tag)
try: try:
@ -396,13 +413,7 @@ class PlaylistItem(object):
typus, kodi_index, plex_index) typus, kodi_index, plex_index)
# If we're choosing an "illegal" index, this function does # If we're choosing an "illegal" index, this function does
# need seem to fail nor log any errors # need seem to fail nor log any errors
if typus == 'audio': self._set_kodi_stream_if_different(kodi_index, typus)
self._set_kodi_stream_if_different(kodi_index, 'audio')
elif typus == 'subtitle':
app.APP.player.setSubtitleStream(kodi_index)
app.APP.player.showSubtitles(True)
elif typus == 'video':
self._set_kodi_stream_if_different(kodi_index, 'video')
if typus == 'audio': if typus == 'audio':
self._current_kodi_audio_stream = kodi_index self._current_kodi_audio_stream = kodi_index
elif typus == 'subtitle': elif typus == 'subtitle':

View file

@ -4,8 +4,8 @@ from logging import getLogger
import requests import requests
from threading import Thread from threading import Thread
from .common import communicate, proxy_headers, proxy_params, log_error, \ from .common import communicate, log_error, UUIDStr, Subscriber, timeline, \
UUIDStr, Subscriber, timeline, stopped_timeline stopped_timeline, create_requests_session
from .playqueue import compare_playqueues from .playqueue import compare_playqueues
from .webserver import ThreadedHTTPServer, CompanionHandlerClassFactory from .webserver import ThreadedHTTPServer, CompanionHandlerClassFactory
from .plexgdm import plexgdm from .plexgdm import plexgdm
@ -81,13 +81,7 @@ class PlaystateMgr(backgroundthread.KillableThread):
def _get_requests_session(self): def _get_requests_session(self):
if self.s is None: if self.s is None:
log.debug('Creating new requests session') self.s = create_requests_session()
self.s = requests.Session()
self.s.headers = proxy_headers()
self.s.verify = app.CONN.verify_ssl_cert
if app.CONN.ssl_cert_path:
self.s.cert = app.CONN.ssl_cert_path
self.s.params = proxy_params()
return self.s return self.s
def _close_requests_session(self): def _close_requests_session(self):