def get_data(self, endpoint, prefer_localized=False):
'''grab the results from the api'''
data = {}
url = 'https://api.thetvdb.com/' + endpoint
headers = {'Content-Type': 'application/json',
'Accept': 'application/json',
'User-agent': 'Mozilla/5.0', 'Authorization': 'Bearer %s' % self._get_token()}
if prefer_localized:
headers["Accept-Language"] = KODI_LANGUAGE
try:
response = requests.get(url, headers=headers, timeout=20)
if response and response.content and response.status_code == 200:
data = json.loads(response.content.decode('utf-8', 'replace'))
elif response.status_code == 401:
# token expired, refresh it and repeat our request
self._log_msg("Token expired, refreshing...")
headers['Bearer'] = self._get_token(True)
response = requests.get(url, headers=headers, timeout=5)
if response and response.content and response.status_code == 200:
data = json.loads(response.content.decode('utf-8', 'replace'))
if data.get("data"):
data = data["data"]
except Exception as exc:
self._log_msg("Exception in get_data --> %s" % repr(exc), xbmc.LOGERROR)
return data
评论列表
文章目录