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')