From c88e7f37c0e8d17854df78dd0a7801793c6b55cd Mon Sep 17 00:00:00 2001 From: mediaminister <45148099+mediaminister@users.noreply.github.com> Date: Sun, 23 Aug 2020 15:31:10 +0000 Subject: [PATCH] Show message when Kodi Player fails to get the stream (#40) --- .../resource.language.en_gb/strings.po | 8 ++ .../resource.language.nl_nl/strings.po | 7 ++ resources/lib/kodilogging.py | 1 + resources/lib/service.py | 84 ++++++++++++++++++- 4 files changed, 99 insertions(+), 1 deletion(-) diff --git a/resources/language/resource.language.en_gb/strings.po b/resources/language/resource.language.en_gb/strings.po index 7816c82..03dd5ab 100644 --- a/resources/language/resource.language.en_gb/strings.po +++ b/resources/language/resource.language.en_gb/strings.po @@ -156,6 +156,14 @@ msgctxt "#30718" msgid "There is no live stream available for {channel}." msgstr "" +msgctxt "#30719" +msgid "This video cannot be played." +msgstr "" + +msgctxt "#30720" +msgid "This video is not available abroad." +msgstr "" + ### SETTINGS msgctxt "#30800" diff --git a/resources/language/resource.language.nl_nl/strings.po b/resources/language/resource.language.nl_nl/strings.po index 3b33eef..0c6b560 100644 --- a/resources/language/resource.language.nl_nl/strings.po +++ b/resources/language/resource.language.nl_nl/strings.po @@ -157,6 +157,13 @@ msgctxt "#30718" msgid "There is no live stream available for {channel}." msgstr "Er is geen live stream beschikbaar voor {channel}." +msgctxt "#30719" +msgid "This video cannot be played." +msgstr "Deze video kan niet afgespeeld worden." + +msgctxt "#30720" +msgid "This video is not available abroad." +msgstr "Deze video is niet beschikbaar in het buitenland." ### SETTINGS diff --git a/resources/lib/kodilogging.py b/resources/lib/kodilogging.py index 706de6d..16521e0 100644 --- a/resources/lib/kodilogging.py +++ b/resources/lib/kodilogging.py @@ -48,3 +48,4 @@ def config(): """ Setup the logger with this handler """ logger = logging.getLogger() logger.addHandler(KodiLogHandler()) + logger.setLevel(logging.DEBUG) diff --git a/resources/lib/service.py b/resources/lib/service.py index 19beed7..d53f471 100644 --- a/resources/lib/service.py +++ b/resources/lib/service.py @@ -8,7 +8,7 @@ import logging import os from time import time -from xbmc import Monitor +from xbmc import getInfoLabel, Monitor, Player from resources.lib import kodilogging, kodiutils from resources.lib.viervijfzes.auth import AuthApi @@ -25,6 +25,7 @@ class BackgroundService(Monitor): self.update_interval = 24 * 3600 # Every 24 hours self.cache_expiry = 30 * 24 * 3600 # One month self._auth = AuthApi(kodiutils.get_setting('username'), kodiutils.get_setting('password'), kodiutils.get_tokens_path()) + self._kodiplayer = KodiPlayer() def run(self): """ Background loop for maintenance tasks """ @@ -95,6 +96,87 @@ class BackgroundService(Monitor): os.unlink(fullpath) +class KodiPlayer(Player): + """Communication with Kodi Player""" + + def __init__(self): + """KodiPlayer initialisation""" + Player.__init__(self) + self.listen = False + self.path = None + self.av_started = False + self.stream_path = None + + def onPlayBackStarted(self): # pylint: disable=invalid-name + """Called when user starts playing a file""" + self.path = getInfoLabel('Player.FilenameAndPath') + if self.path.startswith('plugin://plugin.video.viervijfzes/'): + self.listen = True + else: + self.listen = False + return + _LOGGER.debug('KodiPlayer onPlayBackStarted') + self.av_started = False + self.stream_path = self.getPlayingFile() + + def onAVStarted(self): # pylint: disable=invalid-name + """Called when Kodi has a video or audiostream""" + if not self.listen: + return + _LOGGER.debug('KodiPlayer onAVStarted') + self.av_started = True + + def onAVChange(self): # pylint: disable=invalid-name + """Called when Kodi has a video, audio or subtitle stream. Also happens when the stream changes.""" + if not self.listen: + return + _LOGGER.debug('KodiPlayer onAVChange') + + def onPlayBackSeek(self, time, seekOffset): # pylint: disable=invalid-name, redefined-outer-name + """Called when user seeks to a time""" + if not self.listen: + return + _LOGGER.debug('KodiPlayer onPlayBackSeek time=%s offset=%s', time, seekOffset) + + def onPlayBackPaused(self): # pylint: disable=invalid-name + """Called when user pauses a playing file""" + if not self.listen: + return + _LOGGER.debug('KodiPlayer onPlayBackPaused') + + def onPlayBackResumed(self): # pylint: disable=invalid-name + """Called when user resumes a paused file or a next playlist item is started""" + if not self.listen: + return + _LOGGER.debug('KodiPlayer onPlayBackResumed') + + def onPlayBackError(self): # pylint: disable=invalid-name + """Called when playback stops due to an error""" + if not self.listen: + return + _LOGGER.debug('KodiPlayer onPlayBackError') + + def onPlayBackStopped(self): # pylint: disable=invalid-name + """Called when user stops Kodi playing a file""" + if not self.listen: + return + _LOGGER.debug('KodiPlayer onPlayBackStopped') + if not self.av_started: + # Check stream path + import requests + response = requests.get(self.stream_path) + if response.status_code == 403: + message_id = 30720 + else: + message_id = 30719 + kodiutils.ok_dialog(message=kodiutils.localize(message_id)) + + def onPlayBackEnded(self): # pylint: disable=invalid-name + """Called when Kodi has ended playing a file""" + if not self.listen: + return + _LOGGER.debug('KodiPlayer onPlayBackEnded') + def run(): """ Run the BackgroundService """ BackgroundService().run()