def wrapper(*args, **kwargs): try: result = func(*args, **kwargs) return result except ResourceUnavailableException as error: log_utils.log('Connection failed |{0}|'.format(error.message), log_utils.LOGERROR) kodi.notify(i18n('connection_failed'), error.message, duration=7000, sound=False) except SubRequired as error: log_utils.log('Requires subscription to |{0}|'.format(error.message), log_utils.LOGDEBUG) kodi.notify(kodi.get_name(), i18n('subscription_required') % error.message, duration=5000, sound=False) except NotFound as error: log_utils.log('Not found |{0}|'.format(error.message), log_utils.LOGDEBUG) kodi.notify(kodi.get_name(), i18n('none_found') % error.message.lower(), duration=5000, sound=False) except PlaybackFailed as error: log_utils.log('Playback Failed |{0}|'.format(error.message), log_utils.LOGDEBUG) kodi.notify(kodi.get_name(), i18n('playback_failed'), duration=5000, sound=False) except TwitchException as error: _error = '' try: _message = error.message _error = _message['error'] message = '[{0}] {1}'.format(_message['status'], _message['message']) except: message = error.message log_utils.log('Error |{0}| |{1}|'.format(_error, message.strip()), log_utils.LOGERROR) kodi.notify(_error if _error else i18n('error'), message.strip(), duration=7000, sound=False)
def wrapper(*args, **kwargs): try: result = func(*args, **kwargs) return result except ResourceUnavailableException as error: log_utils.log('Connection failed |{0}|'.format(error.message), log_utils.LOGERROR) kodi.notify(i18n('connection_failed'), error.message, duration=7000, sound=False) except SubRequired as error: log_utils.log( 'Requires subscription to |{0}|'.format(error.message), log_utils.LOGDEBUG) kodi.notify(kodi.get_name(), i18n('subscription_required') % error.message, duration=5000, sound=False) except NotFound as error: log_utils.log('Not found |{0}|'.format(error.message), log_utils.LOGDEBUG) kodi.notify(kodi.get_name(), i18n('none_found') % error.message.lower(), duration=5000, sound=False) except PlaybackFailed as error: log_utils.log('Playback Failed |{0}|'.format(error.message), log_utils.LOGDEBUG) kodi.notify(kodi.get_name(), i18n('playback_failed'), duration=5000, sound=False) except TwitchException as error: _error = '' try: _message = error.message _error = _message['error'] message = '[{0}] {1}'.format(_message['status'], _message['message']) except: message = error.message log_utils.log('Error |{0}| |{1}|'.format(_error, message.strip()), log_utils.LOGERROR) kodi.notify(_error if _error else i18n('error'), message.strip(), duration=7000, sound=False)
def get_oauth_token(token_only=True, required=False): oauth_token = kodi.get_setting('oauth_token') if not oauth_token or not oauth_token.strip(): if not required: return '' kodi.notify(kodi.get_name(), i18n('token_required'), sound=False) kodi.show_settings() oauth_token = kodi.get_setting('oauth_token') stripped_token = oauth_token.strip() if oauth_token != stripped_token: oauth_token = stripped_token kodi.set_setting('oauth_token', oauth_token) if oauth_token: if token_only: idx = oauth_token.find(':') if idx >= 0: oauth_token = oauth_token[idx + 1:] else: if not oauth_token.lower().startswith('oauth:'): idx = oauth_token.find(':') if idx >= 0: oauth_token = oauth_token[idx + 1:] oauth_token = 'oauth:{0}'.format(oauth_token) return oauth_token.decode('utf-8')