diff --git a/resources/lib/kodiwrapper.py b/resources/lib/kodiwrapper.py index abfcb4ef..cd4a7d0f 100644 --- a/resources/lib/kodiwrapper.py +++ b/resources/lib/kodiwrapper.py @@ -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 diff --git a/resources/lib/modules/player.py b/resources/lib/modules/player.py index 245a2534..98c7e6d0 100644 --- a/resources/lib/modules/player.py +++ b/resources/lib/modules/player.py @@ -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: @@ -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. @@ -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()))] diff --git a/resources/lib/vtmgo/vtmgostream.py b/resources/lib/vtmgo/vtmgostream.py index 05e78fa9..b4de9fbf 100644 --- a/resources/lib/vtmgo/vtmgostream.py +++ b/resources/lib/vtmgo/vtmgostream.py @@ -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 @@ -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() ) @@ -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() ) @@ -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() ) diff --git a/test/xbmc.py b/test/xbmc.py index cb1836fa..8dd1c466 100644 --- a/test/xbmc.py +++ b/test/xbmc.py @@ -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