Skip to content

Commit

Permalink
Add subtitles after playback has started
Browse files Browse the repository at this point in the history
Reduce complexity of method
  • Loading branch information
michaelarnauts committed Mar 6, 2020
1 parent c07aa6a commit fd70581
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 24 deletions.
9 changes: 7 additions & 2 deletions resources/lib/kodiwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,13 @@ def play(self, title_item, license_key=None):
play_item.setProperty('inputstream.adaptive.license_type', 'com.widevine.alpha')
play_item.setProperty('inputstream.adaptive.license_key', license_key)

if title_item.subtitles_path:
play_item.setSubtitles(title_item.subtitles_path)
# Note: Adding the subtitle directly on the ListItem could cause sync issues, therefore
# we add the subtitles trough the Player after playback has started.
# See https://github.com/michaelarnauts/plugin.video.vtm.go/issues/148
# This is probably a Kodi or inputstream.adaptive issue

# if title_item.subtitles_path:
# play_item.setSubtitles(title_item.subtitles_path)

# To support video playback directly from RunPlugin() we need to use xbmc.Player().play instead of
# setResolvedUrl that only works with PlayMedia() or with internal playable menu items
Expand Down
42 changes: 28 additions & 14 deletions resources/lib/modules/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,7 @@ def play(self, category, item):
:type item: string
"""
# Check if inputstreamhelper is correctly installed
try:
from inputstreamhelper import Helper
is_helper = Helper('mpd', drm='com.widevine.alpha')
if not is_helper.check_inputstream():
# inputstreamhelper has already shown an error
return

except ImportError:
self._kodi.show_ok_dialog(message=self._kodi.localize(30708)) # Please reboot Kodi
if not self._check_inputstream():
return

try:
Expand Down Expand Up @@ -152,14 +144,38 @@ def play(self, category, item):
# Playback didn't start
return

# Turn on subtitles if needed
if resolved_stream.subtitles and self._kodi.get_setting_as_bool('showsubtitles'):
kodi_player.showSubtitles(True)
# Add subtitles
if resolved_stream.subtitles:
self._kodi.log('Setting subtitles')
kodi_player.setSubtitles(resolved_stream.subtitles[0])

# Turn on subtitles if needed
if self._kodi.get_setting_as_bool('showsubtitles'):
self._kodi.log('Enabling subtitles')
kodi_player.showSubtitles(True)

# Send Up Next data
if upnext_data:
self._kodi.log("Sending Up Next data: %s" % upnext_data)
self.send_upnext(upnext_data)

def _check_inputstream(self):
""" Check if inputstreamhelper and inputstream.adaptive are fine.
:rtype boolean
"""
try:
from inputstreamhelper import Helper
is_helper = Helper('mpd', drm='com.widevine.alpha')
if not is_helper.check_inputstream():
# inputstreamhelper has already shown an error
return False

except ImportError:
self._kodi.show_ok_dialog(message=self._kodi.localize(30708)) # Please reboot Kodi
return False

return True

@staticmethod
def generate_upnext(current_episode, next_episode):
""" Construct the data for Up Next.
Expand Down Expand Up @@ -208,8 +224,6 @@ def send_upnext(self, upnext_info):
""" Send a message to Up Next with information about the next Episode.
:type upnext_info: object
"""
self._kodi.log("Sending Up Next data: %s" % upnext_info)

from base64 import b64encode
from json import dumps
data = [to_unicode(b64encode(dumps(upnext_info).encode()))]
Expand Down
14 changes: 7 additions & 7 deletions resources/lib/vtmgo/vtmgostream.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ def get_stream(self, stream_type, stream_id):
# https://github.com/peak3d/inputstream.adaptive/issues/286
url = self._redirect_manifest(url)

# Extract subtitle info from our stream_info.
subtitle_info = self._extract_subtitles_from_stream_info(stream_info)
# Extract subtitles from our stream_info.
subtitles = self._extract_subtitles_from_stream_info(stream_info)

# Delay subtitles taking into account advertisements breaks.
if subtitle_info:
subtitle_info = self._delay_subtitles(subtitle_info, json_manifest)
if subtitles:
subtitles = self._delay_subtitles(subtitles, json_manifest)

if stream_type == 'episodes':
# TV episode
Expand All @@ -110,7 +110,7 @@ def get_stream(self, stream_type, stream_id):
title=stream_info['video']['metadata']['title'],
duration=stream_info['video']['duration'],
url=url,
subtitles=subtitle_info,
subtitles=subtitles,
license_url=license_url,
cookies=self._session.cookies.get_dict()
)
Expand All @@ -122,7 +122,7 @@ def get_stream(self, stream_type, stream_id):
title=stream_info['video']['metadata']['title'],
duration=stream_info['video']['duration'],
url=url,
subtitles=subtitle_info,
subtitles=subtitles,
license_url=license_url,
cookies=self._session.cookies.get_dict()
)
Expand All @@ -139,7 +139,7 @@ def get_stream(self, stream_type, stream_id):
title=stream_info['video']['metadata']['title'],
duration=None,
url=url,
subtitles=subtitle_info,
subtitles=subtitles,
license_url=license_url,
cookies=self._session.cookies.get_dict()
)
Expand Down
6 changes: 5 additions & 1 deletion test/xbmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ def isPlaying(self):
self._count += 1
return bool(self._count % 5 != 0)

def showSubtitles(self, bVisible):
def setSubtitles(self, subtitleFile):
''' A stub implementation for the xbmc Player class setSubtitles() method '''
return

def showSubtitles(self, visible):
''' A stub implementation for the xbmc Player class showSubtitles() method '''
return

Expand Down

0 comments on commit fd70581

Please sign in to comment.