Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __get_token(self):
pin = self.pin_edit_control.getText().strip()
print("PIN",pin)
if pin:
try:
trakt_api = TraktAPI2(use_https=False, timeout=300)
result = trakt_api.get_token(pin=pin)
print("---",result)
control.set_setting('trakt_oauth_token', result['access_token'])
control.set_setting('trakt_refresh_token', result['refresh_token'])
TOKEN = result['access_token']
trakt_api = TraktAPI2(TOKEN, use_https=False, timeout=300)
profile = trakt_api.get_user_profile(cached=False)
print("Profile",profile)
print("Profile",profile['username'])
control.set_setting('trakt_user', profile['username'])
control.infoDialog('Trakt Authorization Success !', 'Trakt Success')
return True
except Exception as e:
print('Trakt Authorization Failed: %s') % (e)
control.infoDialog('Trakt Authorization Failed: '+str(e), 'Trakt ERROR')
return False
return False
def __get_token(self):
pin = self.pin_edit_control.getText().strip()
print("PIN",pin)
if pin:
try:
trakt_api = TraktAPI2(use_https=False, timeout=300)
result = trakt_api.get_token(pin=pin)
print("---",result)
control.set_setting('trakt_oauth_token', result['access_token'])
control.set_setting('trakt_refresh_token', result['refresh_token'])
TOKEN = result['access_token']
trakt_api = TraktAPI2(TOKEN, use_https=False, timeout=300)
profile = trakt_api.get_user_profile(cached=False)
print("Profile",profile)
print("Profile",profile['username'])
control.set_setting('trakt_user', profile['username'])
control.infoDialog('Trakt Authorization Success !', 'Trakt Success')
return True
except Exception as e:
print('Trakt Authorization Failed: %s') % (e)
control.infoDialog('Trakt Authorization Failed: '+str(e), 'Trakt ERROR')
return False
return False
def onClick(self, control2):
print 'onClick: %s' % (control2)
if control2 == AUTH_BUTTON:
if not self.__get_token():
control.infoDialog('Trakt PIN Authorization Failed.', 'Trakt ERROR')
return
self.auth = True
self.close()
if control2 == LATER_BUTTON:
control.infoDialog(control.lang(32157) + control.lang(32150))
control.set_setting('last_reminder', str(int(time.time())))
if control == NEVER_BUTTON:
control.infoDialog(control.lang(32157) + control.lang(32151))
control.set_setting('last_reminder', '-1')
if control in [AUTH_BUTTON, LATER_BUTTON, NEVER_BUTTON]:
self.close()
raise TransientTraktError('Temporary Trakt Error: ' + str(e))
except urllib2.URLError as e:
if isinstance(e, urllib2.HTTPError):
if e.code in TEMP_ERRORS:
control.infoDialog('Temporary Trakt Error: ' + str(e),"Trakt ERROR")
raise TransientTraktError('Temporary Trakt Error: ' + str(e))
elif e.code == 401 or e.code == 405:
# token is fine, profile is private
if e.info().getheader('X-Private-User') == 'true':
control.infoDialog('Object is No Longer Available (%s)' % (e.code),"Trakt ERROR")
raise TraktAuthError('Object is No Longer Available (%s)' % (e.code))
# auth failure retry or a token request
elif auth_retry or url.endswith('/token'):
self.token = None
control.set_setting('trakt_oauth_token', '')
control.set_setting('trakt_refresh_token', '')
control.infoDialog('Trakt Call Authentication Failed (%s)' % (e.code),"Trakt ERROR")
raise TraktAuthError('Trakt Call Authentication Failed (%s)' % (e.code))
# first try token fail, try to refresh token
else:
result = self.get_token()
self.token = result['access_token']
control.set_setting('trakt_oauth_token', result['access_token'])
control.set_setting('trakt_refresh_token', result['refresh_token'])
auth_retry = True
elif e.code == 404:
control.infoDialog('Object Not Found (%s)' % (e.code), "Trakt ERROR")
raise TraktNotFoundError('Object Not Found (%s)' % (e.code))
else:
raise
elif isinstance(e.reason, socket.timeout) or isinstance(e.reason, ssl.SSLError):
control.infoDialog('Temporary Trakt Error: ' + str(e),"Trakt ERROR")
def onClick(self, control2):
print 'onClick: %s' % (control2)
if control2 == AUTH_BUTTON:
if not self.__get_token():
control.infoDialog('Trakt PIN Authorization Failed.', 'Trakt ERROR')
return
self.auth = True
self.close()
if control2 == LATER_BUTTON:
control.infoDialog(control.lang(32157) + control.lang(32150))
control.set_setting('last_reminder', str(int(time.time())))
if control == NEVER_BUTTON:
control.infoDialog(control.lang(32157) + control.lang(32151))
control.set_setting('last_reminder', '-1')
if control in [AUTH_BUTTON, LATER_BUTTON, NEVER_BUTTON]:
self.close()
def test2():
control.doPrint = True
control.set_setting('control_phantomjs_path', 'C:\PhantomJS')
print "PhantomJS binary file presence: %s | MD5 Checksum: %s" % checkBinaryPresence()
resp = decode("https://fmovies.taxi/film/incredibles-2.5kj1m/njpppj", debug=False, js='fmovies.js')
print resp[0]
log(PROCESSES)
def test5():
control.doPrint = True
control.set_setting('control_phantomjs_path', 'C:\PhantomJS')
print "PhantomJS binary file presence: %s | MD5 Checksum: %s" % checkBinaryPresence()
resp = decode("https://fmovies.taxi/film/venom.v5z07", debug=True, js='genericPage.js')
print resp[0]
log(PROCESSES)
control.infoDialog('Temporary Trakt Error: ' + str(e), "Trakt ERROR")
raise TransientTraktError('Temporary Trakt Error: ' + str(e))
except urllib2.URLError as e:
if isinstance(e, urllib2.HTTPError):
if e.code in TEMP_ERRORS:
control.infoDialog('Temporary Trakt Error: ' + str(e),"Trakt ERROR")
raise TransientTraktError('Temporary Trakt Error: ' + str(e))
elif e.code == 401 or e.code == 405:
# token is fine, profile is private
if e.info().getheader('X-Private-User') == 'true':
control.infoDialog('Object is No Longer Available (%s)' % (e.code),"Trakt ERROR")
raise TraktAuthError('Object is No Longer Available (%s)' % (e.code))
# auth failure retry or a token request
elif auth_retry or url.endswith('/token'):
self.token = None
control.set_setting('trakt_oauth_token', '')
control.set_setting('trakt_refresh_token', '')
control.infoDialog('Trakt Call Authentication Failed (%s)' % (e.code),"Trakt ERROR")
raise TraktAuthError('Trakt Call Authentication Failed (%s)' % (e.code))
# first try token fail, try to refresh token
else:
result = self.get_token()
self.token = result['access_token']
control.set_setting('trakt_oauth_token', result['access_token'])
control.set_setting('trakt_refresh_token', result['refresh_token'])
auth_retry = True
elif e.code == 404:
control.infoDialog('Object Not Found (%s)' % (e.code), "Trakt ERROR")
raise TraktNotFoundError('Object Not Found (%s)' % (e.code))
else:
raise
elif isinstance(e.reason, socket.timeout) or isinstance(e.reason, ssl.SSLError):
# token is fine, profile is private
if e.info().getheader('X-Private-User') == 'true':
control.infoDialog('Object is No Longer Available (%s)' % (e.code),"Trakt ERROR")
raise TraktAuthError('Object is No Longer Available (%s)' % (e.code))
# auth failure retry or a token request
elif auth_retry or url.endswith('/token'):
self.token = None
control.set_setting('trakt_oauth_token', '')
control.set_setting('trakt_refresh_token', '')
control.infoDialog('Trakt Call Authentication Failed (%s)' % (e.code),"Trakt ERROR")
raise TraktAuthError('Trakt Call Authentication Failed (%s)' % (e.code))
# first try token fail, try to refresh token
else:
result = self.get_token()
self.token = result['access_token']
control.set_setting('trakt_oauth_token', result['access_token'])
control.set_setting('trakt_refresh_token', result['refresh_token'])
auth_retry = True
elif e.code == 404:
control.infoDialog('Object Not Found (%s)' % (e.code), "Trakt ERROR")
raise TraktNotFoundError('Object Not Found (%s)' % (e.code))
else:
raise
elif isinstance(e.reason, socket.timeout) or isinstance(e.reason, ssl.SSLError):
control.infoDialog('Temporary Trakt Error: ' + str(e),"Trakt ERROR")
raise TransientTraktError('Temporary Trakt Error: ' + str(e))
else:
control.infoDialog('Trakt Error: ' + str(e), "Trakt ERROR")
raise TraktError('Trakt Error: ' + str(e))
except:
raise