def get_api(self): try: api_key = self.api_key if api_key == '': if self.user_name == '' or self.user_pass == '': return else: s = requests.Session() link = (self.base_link + self.login_link % (self.user_name, self.user_pass)) p = s.post(link) p = json.loads(p.text) if p['status'] == 'ok': api_key = p['api_key'] control.setSetting('furk.api', api_key) else: pass return api_key except: print("Unexpected error in Furk Script: check_api", sys.exc_info()[0]) exc_type, exc_obj, exc_tb = sys.exc_info() print(exc_type, exc_tb.tb_lineno) pass
def ScraperChoice(): from exoscrapers import providerSources sourceList = sorted(providerSources()) control.idle() select = control.selectDialog([i for i in sourceList]) if select == -1: return module_choice = sourceList[select] control.setSetting('module.provider', module_choice) control.openSettings('0.1')
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
if action == "ExoscrapersSettings": control.openSettings('0.0', 'script.module.exoscrapers') elif mode == "ExoscrapersSettings": control.openSettings('0.0', 'script.module.exoscrapers') elif action == "ScraperChoice": ScraperChoice() elif action == "toggleAll": sourceList = [] sourceList = sources_exoscrapers.all_providers for i in sourceList: source_setting = 'provider.' + i control.setSetting(source_setting, params['setting']) # xbmc.log('All providers = %s' % sourceList,2) control.openSettings(query, "script.module.exoscrapers") elif action == "toggleAllHosters": sourceList = [] sourceList = sources_exoscrapers.hoster_providers for i in sourceList: source_setting = 'provider.' + i control.setSetting(source_setting, params['setting']) # xbmc.log('All Hoster providers = %s' % sourceList,2) control.openSettings(query, "script.module.exoscrapers") elif action == "toggleAllForeign": sourceList = [] sourceList = sources_exoscrapers.all_foreign_providers