Exemple #1
0
def getTraktAsJson(url, post=None):
	try:
		r, res_headers = __getTrakt(url, post)
		r = utils.json_loads_as_str(r)
		if 'X-Sort-By' in res_headers and 'X-Sort-How' in res_headers:
			r = sort_list(res_headers['X-Sort-By'], res_headers['X-Sort-How'], r)
		return r
	except:
		pass
Exemple #2
0
def getAlternativTitle(title):
    try:
        t = cleantitle.get(title)

        r = _getAniList('/anime/search/%s' % title)
        r = [(i.get('title_romaji'), i.get('synonyms', []))
             for i in utils.json_loads_as_str(r)
             if cleantitle.get(i.get('title_english', '')) == t]
        r = [i[1][0] if i[0] == title and len(i[1]) > 0 else i[0] for i in r]
        r = [i for i in r if i if i != title][0]
        return r
    except:
        pass
Exemple #3
0
def _getToken():
    result = urllib.urlencode({
        'grant_type': 'client_credentials',
        'client_id': 'kodiexodus-7erse',
        'client_secret': 'XelwkDEccpHX2uO8NpqIjVf6zeg'
    })
    result = client.request(
        'https://anilist.co/api/auth/access_token',
        post=result,
        headers={'Content-Type': 'application/x-www-form-urlencoded'},
        error=True)
    result = utils.json_loads_as_str(result)
    return result['token_type'], result['access_token']
Exemple #4
0
def manager(name, imdb, tvdb, content):
	try:
		post = {"movies": [{"ids": {"imdb": imdb}}]} if content == 'movie' else {"shows": [{"ids": {"tvdb": tvdb}}]}
		items = [(control.lang(32516).encode('utf-8'), '/sync/collection')]
		items += [(control.lang(32517).encode('utf-8'), '/sync/collection/remove')]
		items += [(control.lang(32518).encode('utf-8'), '/sync/watchlist')]
		items += [(control.lang(32519).encode('utf-8'), '/sync/watchlist/remove')]
		items += [(control.lang(32520).encode('utf-8'), '/users/me/lists/%s/items')]
		result = getTraktAsJson('/users/me/lists')
		lists = [(i['name'], i['ids']['slug']) for i in result]
		lists = [lists[i // 2] for i in range(len(lists) * 2)]
		for i in range(0, len(lists), 2):
			lists[i] = ((control.lang(32521) % lists[i][0]).encode('utf-8'), '/users/me/lists/%s/items' % lists[i][1])
		for i in range(1, len(lists), 2):
			lists[i] = (
				(control.lang(32522) % lists[i][0]).encode('utf-8'), '/users/me/lists/%s/items/remove' % lists[i][1])
		items += lists
		select = control.selectDialog([i[0] for i in items], control.lang(32515).encode('utf-8'))
		if select == -1:
			return
		elif select == 4:
			t = control.lang(32520).encode('utf-8')
			k = control.keyboard('', t);
			k.doModal()
			new = k.getText() if k.isConfirmed() else None
			if (new is None or new == ''):
				return
			result = __getTrakt('/users/me/lists', post={"name": new, "privacy": "private"})[0]
			try:
				slug = utils.json_loads_as_str(result)['ids']['slug']
			except:
				return control.infoDialog(control.lang(32515).encode('utf-8'), heading=str(name), sound=True,
				                          icon='ERROR')
			result = __getTrakt(items[select][1] % slug, post=post)[0]
		else:
			result = __getTrakt(items[select][1], post=post)[0]
		icon = control.infoLabel('ListItem.Icon') if not result == None else 'ERROR'
		control.infoDialog(control.lang(32515).encode('utf-8'), heading=str(name), sound=True, icon=icon)
	except:
		return
Exemple #5
0
def __getTrakt(url, post=None):
	try:
		url = urlparse.urljoin(BASE_URL, url)
		post = json.dumps(post) if post else None
		headers = {'Content-Type': 'application/json', 'trakt-api-key': V2_API_KEY, 'trakt-api-version': 2}
		if getTraktCredentialsInfo():
			headers.update({'Authorization': 'Bearer %s' % control.setting('trakt.token')})
		result = client.request(url, post=post, headers=headers, output='extended', error=True)
		resp_code = result[1]
		resp_header = result[2]
		result = result[0]
		if resp_code in ['500', '502', '503', '504', '520', '521', '522', '524']:
			log_utils.log('Temporary Trakt Error: %s' % resp_code, log_utils.LOGWARNING)
			return
		elif resp_code in ['404']:
			log_utils.log('Object Not Found : %s' % resp_code, log_utils.LOGWARNING)
			return
		elif resp_code in ['429']:
			log_utils.log('Trakt Rate Limit Reached: %s' % resp_code, log_utils.LOGWARNING)
			return
		if resp_code not in ['401', '405']:
			return result, resp_header
		oauth = urlparse.urljoin(BASE_URL, '/oauth/token')
		opost = {'client_id': V2_API_KEY, 'client_secret': CLIENT_SECRET, 'redirect_uri': REDIRECT_URI,
		         'grant_type': 'refresh_token', 'refresh_token': control.setting('trakt.refresh')}
		result = client.request(oauth, post=json.dumps(opost), headers=headers)
		result = utils.json_loads_as_str(result)
		token, refresh = result['access_token'], result['refresh_token']
		control.setSetting(id='trakt.token', value=token)
		control.setSetting(id='trakt.refresh', value=refresh)
		headers['Authorization'] = 'Bearer %s' % token
		result = client.request(url, post=post, headers=headers, output='extended', error=True)
		return result[0], result[2]
	except Exception as e:
		log_utils.log('Unknown Trakt Error: %s' % e, log_utils.LOGWARNING)
		pass