def auth_trakt(Trakt_API, translations): i18n = translations.i18n start = time.time() use_https = kodi.get_setting('use_https') == 'true' trakt_timeout = int(kodi.get_setting('trakt_timeout')) trakt_api = Trakt_API(use_https=use_https, timeout=trakt_timeout) result = trakt_api.get_code() code, expires, interval = result['device_code'], result[ 'expires_in'], result['interval'] time_left = expires - int(time.time() - start) line1 = i18n('verification_url') % (result['verification_url']) line2 = i18n('prompt_code') % (result['user_code']) with kodi.CountdownDialog(i18n('trakt_acct_auth'), line1=line1, line2=line2, countdown=time_left, interval=interval) as cd: result = cd.start(__auth_trakt, [trakt_api, code, i18n]) try: kodi.set_setting('trakt_oauth_token', result['access_token']) kodi.set_setting('trakt_refresh_token', result['refresh_token']) trakt_api = Trakt_API(result['access_token'], use_https=use_https, timeout=trakt_timeout) profile = trakt_api.get_user_profile(cached=False) kodi.set_setting('trakt_user', '%s (%s)' % (profile['username'], profile['name'])) kodi.notify(msg=i18n('trakt_auth_complete'), duration=3000) except Exception as e: logger.log('Trakt Authorization Failed: %s' % (e), log_utils.LOGDEBUG)
def auth_trakt(): trakt_api = trakt.TraktAPI() start = time.time() use_https = kodi.get_setting('use_https') == 'true' trakt_timeout = int(kodi.get_setting('timeout')) trakt_api = trakt.TraktAPI(use_https=use_https, timeout=trakt_timeout) result = trakt_api.get_code() kodi.log(result) code, expires, interval = result['device_code'], result[ 'expires_in'], result['interval'] time_left = expires - int(time.time() - start) line1 = 'On ANY Device visit: ' + result['verification_url'] line2 = 'When promted , enter code: ' + result['user_code'] with kodi.CountdownDialog('Authorizer your account', line1=line1, line2=line2, countdown=time_left, interval=interval) as cd: result = cd.start(__auth_trakt, [trakt_api, code, 'TEST']) try: trakt_api = trakt.TraktAPI() kodi.set_setting('trakt_oauth_token', result['access_token']) kodi.set_setting('trakt_refresh_token', result['refresh_token']) kodi.set_setting('trakt_authorized', "true") # trakt_api = trakt.Trakt_API(result['access_token'], use_https=True, timeout=trakt_timeout) kodi.log(result['access_token']) profile = trakt_api.my_username() #kodi.log("PROFILE RESULT " + profile['username']) kodi.set_setting('trakt_username', profile['username'] + '/' + profile['name']) kodi.notify(header='Trakt', msg='You are now authorized', duration=5000, sound=None) #kodi.notify(msg='trakt_auth_complete', duration=3000) except Exception as e: log_utils.log('Trakt Authorization Failed: %s' % (e), log_utils.LOGDEBUG)