def playVideo(self, url, icon): subs_language = settings.get_subtitle_languages() title, url, subs, info_labels = self.ted_talks.getVideoDetails( url=url, video_quality=settings.video_quality, subs_language=subs_language) li = xbmcgui.ListItem(title, iconImage=icon, thumbnailImage=icon, path=url) li.setInfo(type='Video', infoLabels=info_labels) xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, li) if subs: # If not we either don't want them, or should have displayed a notification. subs_file = os.path.join(xbmc.translatePath("special://temp"), 'ted_talks_subs.srt') fh = open(subs_file, 'w') try: fh.write(subs.encode('utf-8')) finally: fh.close() player = xbmc.Player() # Up to 30s to start start_time = time.time() while not player.isPlaying() and time.time() - start_time < 30: time.sleep(1) if player.isPlaying(): xbmc.Player().setSubtitles(subs_file) else: # No user message: user was probably already notified of a problem with the stream. plugin.report( 'Could not show subtitles: timed out waiting for player to start.' )
def playVideo(self, url, icon): subs_language = settings.get_subtitle_languages() title, url, subs, info_labels = self.ted_talks.getVideoDetails(url, subs_language) li = xbmcgui.ListItem(title, iconImage=icon, thumbnailImage=icon, path=url) li.setInfo(type='Video', infoLabels=info_labels) xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, li) if subs: # If not we either don't want them, or should have displayed a notification. subs_file = os.path.join(xbmc.translatePath("special://temp"), 'ted_talks_subs.srt') fh = open(subs_file, 'w') try: fh.write(subs.encode('utf-8')) finally: fh.close() player = xbmc.Player() # Up to 30s to start start_time = time.time() while not player.isPlaying() and time.time() - start_time < 30: time.sleep(1) if player.isPlaying(): xbmc.Player().setSubtitles(subs_file); else: # No user message: user was probably already notified of a problem with the stream. plugin.report('Could not show subtitles: timed out waiting for player to start.')
def test_get_subtitle_languages_enabled_custom(self): settings.enable_subtitles = 'true' settings.subtitle_language = 'en,fr , de ,' self.assertEqual(['en', 'fr', 'de'], settings.get_subtitle_languages())
def test_get_subtitle_languages_enabled_standard_nomatch(self): settings.enable_subtitles = 'true' settings.xbmc_language = 'Klingon' settings.subtitle_language = '' self.assertEqual(None, settings.get_subtitle_languages())
def test_get_subtitle_languages_enabled_standard(self): settings.enable_subtitles = 'true' settings.xbmc_language = 'Portuguese' settings.subtitle_language = "" # Default is "en", if pref unset then XBMC will replace with "". self.assertEqual(['pt'], settings.get_subtitle_languages())
def test_get_subtitle_languages_disabled(self): settings.enable_subtitles = 'false' self.assertIsNone(settings.get_subtitle_languages())