def setDictVal(key, val, session=None): if str(val).lower() == 'true': val = 'enabled' elif str(val).lower() == 'false': val = 'disabled' key = key.replace('Toggle','') if DEVICE_OPTION_CONSTRAINTS != None and key in DEVICE_OPTION_CONSTRAINTS.keys(): for key_cons in DEVICE_OPTION_CONSTRAINTS[key]: if Prefs[key_cons['Pref']] and val!=key_cons['ReqValue']: return ObjectContainer(header='Sorry', message='Sorry %s has conflict with Pref: %s needs to be %s.' % (key, key_cons['Desc'], key_cons['ReqValue']), title1=key) if DEVICE_OPTION_CONSTRAINTS2 != None and key in DEVICE_OPTION_CONSTRAINTS2.keys(): for key_cons in DEVICE_OPTION_CONSTRAINTS2[key]: if str(UsingOption(DEVICE_OPTIONS[key_cons['Option']])) != str(key_cons['ReqValue']): return ObjectContainer(header='Sorry', message='Sorry %s has conflict with Device Option: %s needs to be %s.' % (key, DEVICE_OPTIONS[key_cons['Option']], key_cons['ReqValue']), title1=key) if session == None: session = getSession() if key in DEVICE_OPTION_PROPOGATE_TO_CONTROL.keys() and DEVICE_OPTION_PROPOGATE_TO_CONTROL[key] != None and DEVICE_OPTION_PROPOGATE_TO_CONTROL[key] == True: control.set_setting('%s-%s' % (session,key), True if val=='enabled' else False) Dict['Toggle%s%s' % (key,session)] = val Dict.Save() if Prefs["use_debug"]: Log("%s status: %s" % (key,val)) return ObjectContainer(header=key, message=key + ' has been ' + val + ' for this device.', title1=key)
def determineIP(): try: r = request('https://v4speed.oloadcdn.net/echoip') control.set_setting('ipaddress', r) except Exception as e: control.set_setting('ipaddress', None) log(type='ERROR-CRITICAL', method='determineIP', err='%s' % e, dolog=True, logToControl=True, doPrint=True)
def wizja_userstatus(): s = webClient() r = s.get('http://wizja.tv/users/index.php').text #print ('result :#%s#' % r) if 'login_input_username' in r: control.log('NIEZALOGOWANY') return 'NIEZALOGOWANY' if 'Zalogowany jako' in r: control.log('ZALOGOWANY') # no premium if '<font color=ff0000>Brak premium' in r: control.log('WIZJA.TV FREE PREMIUM: %s' % '') control.infoDialog(control.lang(30490).encode('utf-8'), time=6000) control.dialog.ok( control.addonInfo('name') + ' - WIZJA TV', control.lang(30490).encode('utf-8'), '') return 'FREE' else: try: premium = re.findall('Premium aktywne do (\d{4}.*?)</font>', r)[0] control.set_setting('wizja.expire', premium) control.infoDialog('Premium Wizja.tv do: ' + premium.encode('utf-8'), time=2000) return 'PREMIUM%s' % premium except: pass return 'PREMIUM%s' return True
def set_settings_to_control(key, val): try: control.set_setting(key, val) except Exception as e: Log.Error('ERROR common.py>set_settings_to_control: %s' % e) if Prefs["use_debug"]: Log("User Setting %s:%s set to Control" % (key,val))
def test4(): 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='fmoviesPage.js') print resp[0] log(PROCESSES)
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 test(): control.doPrint = True control.set_setting('control_phantomjs_path', 'C:\PhantomJS') print "PhantomJS binary file presence: %s | MD5 Checksum: %s" % checkBinaryPresence( ) resp = decode("https://openload.co/embed/kUEfGclsU9o", debug=False, js='openload.js') print resp[0] log(PROCESSES)
def test3(): control.doPrint = True control.set_setting('control_phantomjs_path', 'C:\PhantomJS') print "PhantomJS binary file presence: %s | MD5 Checksum: %s" % checkBinaryPresence( ) resp = decode( "https://www6.9anime.is/watch/ginga-eiyuu-densetsu-die-neue-these-kaikou.0y5r/j1xj1y", debug=False, js='9anime.js') print resp[0] log(PROCESSES)
def getTrakt(url, post=None): try: url = urlparse.urljoin('http://api-v2launch.trakt.tv', url) headers = { 'Content-Type': 'application/json', 'trakt-api-key': control.trakt_key, 'trakt-api-version': '2' } #if not post == None: post = json.dumps(post) if not post == None: post = json.dumps(post) if getTraktCredentialsInfo() == False: result = client.request(url, post=post, headers=headers) return result headers['Authorization'] = 'Bearer %s' % control.setting('trakt.token') #result = client.request(url, post=post, headers=headers, output='response', error=True) result = client.request(url, post=post, headers=headers, output='extended', error=True) if not (result[1] == '401' or result[1] == '405'): return result[0] oauth = 'http://api-v2launch.trakt.tv/oauth/token' opost = { 'client_id': control.trakt_key, 'client_secret': control.trakt_secret, 'redirect_uri': 'urn:ietf:wg:oauth:2.0:oob', 'grant_type': 'refresh_token', 'refresh_token': control.setting('trakt.refresh') } #result = client.request(oauth, post=json.dumps(opost), headers=headers) result = client.request(oauth, post=json.dumps(opost), headers=headers) result = json.loads(result) token, refresh = result['access_token'], result['refresh_token'] control.set_setting('trakt.token', token) control.set_setting('trakt.refresh', refresh) headers['Authorization'] = 'Bearer %s' % token result = client.request(url, post=post, headers=headers) return result except: pass
def getVidToken(self): try: all_js_url = urlparse.urljoin(self.base_link, self.ALL_JS) unpacked_code = '' cch = '' if len(self.TOKEN_KEY) == 0: all_js_pack_code = proxies.request( all_js_url, use_web_proxy=self.proxyrequired, httpsskip=True, timeout=7) unpacked_code = jsunpack.unpack(all_js_pack_code) cch = re.findall( r'%s' % client.b64decode( 'ZnVuY3Rpb25cKFthLXpdLFthLXpdLFthLXpdXCl7XCJ1c2Ugc3RyaWN0XCI7ZnVuY3Rpb24gW2Etel1cKFwpe3JldHVybiAoLio/KX0=' ), unpacked_code)[0] token_key = re.findall(r'%s=.*?\"(.*?)\"' % cch, unpacked_code)[0] if token_key != None and token_key != '': self.TOKEN_KEY.append(token_key) control.set_setting(name + 'VidToken', token_key) except Exception as e: log('ERROR', 'getVidToken-1', '%s' % e, dolog=False) log('ERROR', 'getVidToken-1', '%s' % unpacked_code, dolog=False) log('ERROR', 'getVidToken-1', '%s' % cch, dolog=False) try: if len(self.TOKEN_KEY) == 0: token_key = proxies.request(self.TOKEN_KEY_PASTEBIN_URL, use_web_proxy=self.proxyrequired, httpsskip=True, timeout=7) if token_key != None and token_key != '': #cookie_dict.update({'token_key':token_key}) self.TOKEN_KEY.append(token_key) control.set_setting(name + 'VidToken', token_key) except Exception as e: log('ERROR', 'getVidToken-2', '%s' % e, dolog=False) try: fm_flags = proxies.request(self.FLAGS_PASTEBIN_URL, use_web_proxy=self.proxyrequired, httpsskip=True, timeout=7) if fm_flags != None and fm_flags != '': fm_flags = json.loads(fm_flags) #cookie_dict.update({'token_key':token_key}) self.FLAGS = fm_flags except Exception as e: log('ERROR', 'getVidToken-3-Flags', '%s' % e, dolog=False)
def setPlexTVUser(session): token = Request.Headers.get("X-Plex-Token", "") url = "https://plex.tv" plexTVUser = None try: xml = XML.ObjectFromURL(url, headers={'X-Plex-Token': token}) plexTVUser = xml.get("myPlexUsername") except: pass try: control.set_setting('%s-%s' % (session, 'user'), plexTVUser) except Exception as e: Log.Error('ERROR common.py>setPlexTVUser: %s' % e)
def set_control_settings(): keys = ['use_https_alt', 'control_all_uc_api_key', 'use_openload_pairing'] for i in range(0, len(keys)): try: key = keys[i] control.set_setting(key, Prefs[key]) except Exception as e: Log('ERROR common.py-1>set_control_settings: %s' % e) try: control.set_setting('is_uss_installed', is_uss_installed()) except Exception as e: Log('ERROR common.py-2>set_control_settings: %s' % e) if Prefs["use_debug"]: Log("User Preferences have been set to Control")
def getTrakt(url, post=None): try: url = urlparse.urljoin('http://api-v2launch.trakt.tv', url) headers = {'Content-Type': 'application/json', 'trakt-api-key': control.trakt_key, 'trakt-api-version': '2'} #if not post == None: post = json.dumps(post) if not post == None: post = json.dumps(post) if getTraktCredentialsInfo() == False: result = client.request(url, post=post, headers=headers) return result headers['Authorization'] = 'Bearer %s' % control.setting('trakt.token') #result = client.request(url, post=post, headers=headers, output='response', error=True) result = client.request(url, post=post, headers=headers, output='extended', error=True) if not (result[1] == '401' or result[1] == '405'): return result[0] oauth = 'http://api-v2launch.trakt.tv/oauth/token' opost = {'client_id': control.trakt_key , 'client_secret': control.trakt_secret, 'redirect_uri': 'urn:ietf:wg:oauth:2.0:oob', 'grant_type': 'refresh_token', 'refresh_token': control.setting('trakt.refresh')} #result = client.request(oauth, post=json.dumps(opost), headers=headers) result = client.request(oauth, post=json.dumps(opost), headers=headers) result = json.loads(result) token, refresh = result['access_token'], result['refresh_token'] control.set_setting('trakt.token', token) control.set_setting('trakt.refresh', refresh) headers['Authorization'] = 'Bearer %s' % token result = client.request(url, post=post, headers=headers) return result except: pass
def authorize_resolver(self): log("Auth - 1") url = 'https://api.real-debrid.com/oauth/v2/device/code?client_id=%s&new_credentials=yes' % (CLIENT_ID) log("Auth - 2") mydata = client.request(url, headers=self.headers) print("Auth - 3", mydata) js_result = json.loads(mydata) print("Auth - 4",js_result) pd = xbmcgui.DialogProgress() line1 = 'Go to URL: %s' % (js_result['verification_url']) line2 = 'When prompted enter: %s' % (js_result['user_code']) print("Auth - 5",line1,line2) try: pd.create('URL Resolver Real Debrid Authorization', line1, line2) interval = int(js_result['interval']) * 30000 device_code = js_result['device_code'] print("sleep - 4",interval) while True: try: for i in range(INTERVALS): print("Auth - 7",i) pd.update( i) if pd.iscanceled(): break xbmc.sleep(interval / INTERVALS) url = 'https://api.real-debrid.com/oauth/v2/device/credentials?client_id=%s&code=%s' % (CLIENT_ID, device_code) js_result = json.loads(client.source(url, headers=self.headers)) print("Auth - 6",js_result) except Exception as e: log('Exception during RD auth: %s' % (e)) else: break finally: pd.close() url = 'https://api.real-debrid.com/oauth/v2/token' data = {'client_id': js_result['client_id'], 'client_secret': js_result['client_secret'], 'code': device_code, 'grant_type': 'http://oauth.net/grant_type/device/1.0'} control.set_setting('realdebrid_client_id', js_result['client_id']) control.set_setting('realdebrid_client_secret', js_result['client_secret']) log('Authorizing Real Debrid: %s' % (js_result['client_id'])) js_result = json.loads(client.source(url, post=data, headers=self.headers)) log('Authorizing Real Debrid Result: |%s|' % (js_result)) control.set_setting('realdebrid_token', js_result['access_token']) control.set_setting('realdebrid_refresh', js_result['refresh_token'])
def get_media_url(self, host, media_id, retry=False): try: url = 'http://api.real-debrid.com/rest/1.0/unrestrict/link' headers = self.headers headers['Authorization'] = 'Bearer %s' % (control.setting('realdebrid_token')) data = {'link': media_id} myresult = client.request(url, post=data, headers=headers,output='response2') result = myresult[1] log(">>> RealDebrid res %s >>>>>> DATA: %s " % (myresult[0],myresult [1])) if myresult[0] != '200': raise ValueError(myresult[0]) except ValueError as e: log("RealDebrid ERROR %s RETRY: %s" % (e,retry)) print ("Myre",e,myresult[0]=='401',control.setting('realdebrid_refresh')) if not retry and myresult[0] == 401: if control.setting('realdebrid_refresh'): self.refresh_token() return self.get_media_url(host, media_id, retry=True) else: control.set_setting('realdebrid_client_id', '') control.set_setting('realdebrid_client_secret', '') control.set_setting('realdebrid_token', '') raise UrlResolver.ResolverError('Real Debrid Auth Failed & No Refresh Token') else: try: js_result = json.loads(e.read()) if 'error' in js_result: msg = js_result['error'] else: msg = 'Unknown Error (1)' except: msg = 'Unknown Error (2)' raise UrlResolver.ResolverError('Real Debrid Error: %s (%s)' % (msg, e.code)) except Exception as e: raise UrlResolver.ResolverError('Unexpected Exception during RD Unrestrict: %s' % (e)) else: js_result = json.loads(result) links = [] link = self.__get_link(js_result) if link is not None: links.append(link) if 'alternative' in js_result: for alt in js_result['alternative']: link = self.__get_link(alt) if link is not None: links.append(link) if len(links) == 1 or control.setting('realdebrid_autopick') == 'true': return links[0][1] elif len(links) > 1: sd = xbmcgui.Dialog() ret = sd.select('Select a Link', [link[0] for link in links]) if ret > -1: return links[ret][1] else: raise UrlResolver.ResolverError('No usable link from Real Debrid')
def refresh_token(self): print("Refresh",control.setting('realdebrid_client_id')) url = 'http://api.real-debrid.com/oauth/v2/token' client_id = control.setting('realdebrid_client_id') client_secret = control.setting('realdebrid_client_secret') refresh_token = control.setting('realdebrid_refresh') data = {'client_id': client_id, 'client_secret': client_secret, 'code': refresh_token, 'grant_type': 'http://oauth.net/grant_type/device/1.0'} log('Refreshing Expired Real Debrid Token: |%s|%s|' % (client_id, refresh_token)) try: js_result = json.loads(client.source(url, post=data, headers=self.headers)) log('Refreshed Real Debrid Token: |%s|' % (js_result)) control.set_setting('realdebrid_token', js_result['access_token']) control.set_setting('realdebrid_refresh', js_result['refresh_token']) except Exception as e: # empty all auth settings to force a re-auth on next use control.set_setting('realdebrid_client_id', '') control.set_setting('realdebrid_client_secret', '') control.set_setting('realdebrid_token', '') control.set_setting('realdebrid_refresh', '') raise UrlResolver.ResolverError('Unable to Refresh Real Debrid Token: %s' % (e))
def rdAuthorize(): try: CLIENT_ID = 'TC3DG7YFNBKQK' USER_AGENT = 'fanfilm for Kodi/1.0' if not '' in credentials()['realdebrid'].values(): if control.yesnoDialog( control.lang(32411).encode('utf-8'), control.lang(32413).encode('utf-8'), '', 'RealDebrid', control.lang(32415).encode('utf-8'), control.lang(32414).encode('utf-8')): control.set_setting('realdebrid_client_id', '') control.set_setting('realdebrid_client_secret', '') control.set_setting('realdebrid_token', '') control.set_setting('realdebrid_refresh', '') control.set_setting('realdebrid_auth', '') raise Exception() headers = {'User-Agent': USER_AGENT} url = 'https://api.real-debrid.com/oauth/v2/device/code?client_id=%s&new_credentials=yes' % ( CLIENT_ID) result = client.request(url, headers=headers) result = json.loads(result) verification_url = control.lang(30416).encode( 'utf-8') + '[COLOR skyblue]%s[/COLOR]' % ( result['verification_url']) user_code = control.lang(30417).encode( 'utf-8') + '[COLOR skyblue]%s[/COLOR]' % (result['user_code']) device_code = result['device_code'] interval = result['interval'] progressDialog = control.progressDialog progressDialog.create('RealDebrid', verification_url, user_code) for i in range(0, 3600): try: if progressDialog.iscanceled(): break time.sleep(1) if not float(i) % interval == 0: raise Exception() url = 'https://api.real-debrid.com/oauth/v2/device/credentials?client_id=%s&code=%s' % ( CLIENT_ID, device_code) result = client.request(url, headers=headers, error=True) result = json.loads(result) if 'client_secret' in result: break except: pass try: progressDialog.close() except: pass id, secret = result['client_id'], result['client_secret'] url = 'https://api.real-debrid.com/oauth/v2/token' post = urllib.urlencode({ 'client_id': id, 'client_secret': secret, 'code': device_code, 'grant_type': 'http://oauth.net/grant_type/device/1.0' }) result = client.request(url, post=post, headers=headers) #control.log("### result:%s " % (result)) result = json.loads(result) token, refresh = result['access_token'], result['refresh_token'] control.log("### id:%s, secret:%s, token:%s, refresh:%s " % (id, secret, token, refresh)) control.set_setting('realdebrid_client_id', id) control.set_setting('realdebrid_client_secret', secret) control.set_setting('realdebrid_token', token) control.set_setting('realdebrid_refresh', refresh) control.set_setting('realdebrid_auth', '*************') raise Exception() except: control.openSettings('3.13')
def resolve(url, debrid='realdebrid'): u = url u = u.replace('filefactory.com/stream/', 'filefactory.com/file/') #control.log("@@@@ REALDEBRID INIT %s ### %s" % (url,debrid)) try: u1 = urlparse.urlparse(url)[1].split('.') u1 = u[-2] + '.' + u[-1] if status() is False: raise Exception() if not debrid == 'realdebrid' and not debrid == True: raise Exception() #raise Exception() if '' in credentials()['realdebrid'].values(): raise Exception() id, secret, token, refresh = credentials()['realdebrid'][ 'id'], credentials()['realdebrid']['secret'], credentials( )['realdebrid']['token'], credentials()['realdebrid']['refresh'] control.log('@@ DEBRID refresh@@ %s' % refresh) USER_AGENT = 'fanfilm for Kodi/1.0' post = urllib.urlencode({'link': u}) headers = { 'Authorization': 'Bearer %s' % token, 'User-Agent': USER_AGENT } url = 'https://api.real-debrid.com/rest/1.0/unrestrict/link' result = client.request(url, post=post, headers=headers, error=True) control.log('@@ DEBRID RESULTS@@ %s' % result) result = json.loads(result) if 'error' in result and result['error'] == 'bad_token': result = client.request( 'https://api.real-debrid.com/oauth/v2/token', post=urllib.urlencode({ 'client_id': id, 'client_secret': secret, 'code': refresh, 'grant_type': 'http://oauth.net/grant_type/device/1.0' }), headers={'User-Agent': USER_AGENT}, error=True) result = json.loads(result) control.log('Refreshing Expired Real Debrid Token: |%s|%s|' % (id, refresh)) control.log('Refreshing Expired : |%s|' % (result)) if 'error' in result: return token, refresh = result['access_token'], result['refresh_token'] control.set_setting('realdebrid_token', token) control.set_setting('realdebrid_refresh', refresh) headers['Authorization'] = 'Bearer %s' % result['access_token'] result = client.request(url, post=post, headers=headers) result = json.loads(result) if 'error' in result and result['error'] == 'file_unavailable': control.log("@@@@ REALDEBRID FILE UNAVAIL %s ### %s" % (url)) return url = result['download'] #control.log('@@ DEBRID URl@@ %s' % url) return url except: pass try: if not debrid == 'premiumize' and not debrid == True: raise Exception() if '' in credentials()['premiumize'].values(): raise Exception() user, password = credentials()['premiumize']['user'], credentials( )['premiumize']['pass'] url = 'http://api.premiumize.me/pm-api/v1.php?method=directdownloadlink¶ms[login]=%s¶ms[pass]=%s¶ms[link]=%s' % ( user, password, urllib.quote_plus(u)) result = client.request(url, close=False) url = json.loads(result)['result']['location'] return url except: pass try: if not debrid == 'alldebrid' and not debrid == True: raise Exception() if '' in credentials()['alldebrid'].values(): raise Exception() user, password = credentials()['alldebrid']['user'], credentials( )['alldebrid']['pass'] login_data = { 'action': 'login', 'login_login': user, 'login_password': password } login_link = 'http://alldebrid.com/register/?%s' % login_data cookie = client.request(login_link, output='cookie', close=False) url = 'http://www.alldebrid.com/service.php?link=%s' % urllib.quote_plus( u) result = client.request(url, cookie=cookie, close=False) url = client.parseDOM(result, 'a', ret='href', attrs={'class': 'link_dl'})[0] url = client.replaceHTMLCodes(url) url = '%s|Cookie=%s' % (url, urllib.quote_plus(cookie)) return url except: pass try: if not debrid == 'rpnet' and not debrid == True: raise Exception() if '' in credentials()['rpnet'].values(): raise Exception() user, password = credentials()['rpnet']['user'], credentials( )['rpnet']['pass'] login_data = { 'username': user, 'password': password, 'action': 'generate', 'links': u } login_link = 'http://premium.rpnet.biz/client_api.php?%s' % login_data result = client.request(login_link, close=False) result = json.loads(result) url = result['links'][0]['generated'] return url except: return
def authTrakt(): try: if getTraktCredentialsInfo() == True: if control.yesnoDialog(control.lang(32511).encode('utf-8'), control.lang(32512).encode('utf-8'), '', 'Trakt', control.lang(30483).encode('utf-8'), control.lang(30482).encode('utf-8')): control.set_setting('trakt.user', '') control.set_setting('trakt.token', '') control.set_setting('trakt.refresh', '') raise Exception() result = getTrakt('/oauth/device/code', {"client_id": control.trakt_key }) result = json.loads(result) verification_url = (control.lang(30416) + '[COLOR skyblue]%s[/COLOR]' % result['verification_url']).encode('utf-8') user_code = (control.lang(30417) + '[COLOR skyblue]%s[/COLOR]' % result['user_code']).encode('utf-8') expires_in = int(result['expires_in']) device_code = result['device_code'] interval = result['interval'] progressDialog = control.progressDialog progressDialog.create('Trakt', verification_url, user_code) for i in range(0, expires_in): try: if progressDialog.iscanceled(): break time.sleep(1) if not float(i) % interval == 0: raise Exception() r = getTrakt('/oauth/device/token', {'client_id': control.trakt_key , 'client_secret': control.trakt_secret, 'code': device_code}) r = json.loads(r) if 'access_token' in r: break except: pass try: progressDialog.close() except: pass token, refresh = r['access_token'], r['refresh_token'] headers = {'Content-Type': 'application/json', 'trakt-api-key': control.trakt_key , 'trakt-api-version': '2', 'Authorization': 'Bearer %s' % token} result = client.request('http://api-v2launch.trakt.tv/users/me', headers=headers) result = json.loads(result) user = result['username'] control.set_setting('trakt.user', user) control.set_setting('trakt.token', token) control.set_setting('trakt.refresh', refresh) raise Exception() except: control.openSettings('6.1')
def rdAuthorize(): try: CLIENT_ID = 'TC3DG7YFNBKQK' USER_AGENT = 'SPECTO for Kodi/1.0' if not '' in credentials()['realdebrid'].values(): if control.yesnoDialog(control.lang(32411).encode('utf-8'), control.lang(32413).encode('utf-8'), '', 'RealDebrid', control.lang(32415).encode('utf-8'), control.lang(32414).encode('utf-8')): control.set_setting('realdebrid_client_id','') control.set_setting('realdebrid_client_secret', '') control.set_setting('realdebrid_token', '') control.set_setting('realdebrid_refresh', '') control.set_setting('realdebrid_auth', '') raise Exception() headers = {'User-Agent': USER_AGENT} url = 'https://api.real-debrid.com/oauth/v2/device/code?client_id=%s&new_credentials=yes' % (CLIENT_ID) result = client.request(url, headers=headers) result = json.loads(result) verification_url = control.lang(30416).encode('utf-8') + '[COLOR skyblue]%s[/COLOR]' % (result['verification_url']) user_code = control.lang(30417).encode('utf-8') + '[COLOR skyblue]%s[/COLOR]' % (result['user_code']) device_code = result['device_code'] interval = result['interval'] progressDialog = control.progressDialog progressDialog.create('RealDebrid', verification_url, user_code) for i in range(0, 3600): try: if progressDialog.iscanceled(): break time.sleep(1) if not float(i) % interval == 0: raise Exception() url = 'https://api.real-debrid.com/oauth/v2/device/credentials?client_id=%s&code=%s' % (CLIENT_ID, device_code) result = client.request(url, headers=headers, error=True) result = json.loads(result) if 'client_secret' in result: break except: pass try: progressDialog.close() except: pass id, secret = result['client_id'], result['client_secret'] url = 'https://api.real-debrid.com/oauth/v2/token' post = {'client_id': id, 'client_secret': secret, 'code': device_code, 'grant_type': 'http://oauth.net/grant_type/device/1.0'} result = client.request(url, post=post, headers=headers) result = json.loads(result) token, refresh = result['access_token'], result['refresh_token'] control.set_setting('realdebrid_client_id', id) control.set_setting('realdebrid_client_secret', secret) control.set_setting('realdebrid_token', token) control.set_setting('realdebrid_refresh', refresh) control.set_setting('realdebrid_auth', '*************') raise Exception() except: control.openSettings('3.13')
def resolve(url, debrid='realdebrid'): u = url u = u.replace('filefactory.com/stream/', 'filefactory.com/file/') #control.log("@@@@ REALDEBRID INIT %s ### %s" % (url,debrid)) try: u1 = urlparse.urlparse(url)[1].split('.') u1 = u[-2] + '.' + u[-1] if status() is False:raise Exception() if not debrid == 'realdebrid' and not debrid == True: raise Exception() #raise Exception() if '' in credentials()['realdebrid'].values(): raise Exception() id, secret, token, refresh = credentials()['realdebrid']['id'], credentials()['realdebrid']['secret'], credentials()['realdebrid']['token'], credentials()['realdebrid']['refresh'] USER_AGENT = 'Kodi Exodus/3.0' post = {'link': u} headers = {'Authorization': 'Bearer %s' % token, 'User-Agent': USER_AGENT} url = 'http://api.real-debrid.com/rest/1.0/unrestrict/link' result = client.request(url, post=post, headers=headers, error=True) control.log('@@ DEBRID RESULTS@@ %s' % result) result = json.loads(result) if 'error' in result and result['error'] == 'bad_token': result = client.request('https://api.real-debrid.com/oauth/v2/token', post={'client_id': id, 'client_secret': secret, 'code': refresh, 'grant_type': 'http://oauth.net/grant_type/device/1.0'}, headers={'User-Agent': USER_AGENT}, error=True) result = json.loads(result) control.log('Refreshing Expired Real Debrid Token: |%s|%s|' % (id, refresh)) control.log('Refreshing Expired : |%s|' % (result)) if 'error' in result: return token, refresh = result['access_token'], result['refresh_token'] control.set_setting('realdebrid_token', token) control.set_setting('realdebrid_refresh', refresh) headers['Authorization'] = 'Bearer %s' % result['access_token'] result = client.request(url, post=post, headers=headers) result = json.loads(result) if 'error' in result and result['error'] == 'file_unavailable': control.log("@@@@ REALDEBRID FILE UNAVAIL %s ### %s" % (url)) return url = result['download'] control.log('@@ DEBRID URl@@ %s' % url) return url except: pass try: if not debrid == 'premiumize' and not debrid == True: raise Exception() if '' in credentials()['premiumize'].values(): raise Exception() user, password = credentials()['premiumize']['user'], credentials()['premiumize']['pass'] url = 'http://api.premiumize.me/pm-api/v1.php?method=directdownloadlink¶ms[login]=%s¶ms[pass]=%s¶ms[link]=%s' % (user, password, urllib.quote_plus(u)) result = client.request(url, close=False) url = json.loads(result)['result']['location'] return url except: pass try: if not debrid == 'alldebrid' and not debrid == True: raise Exception() if '' in credentials()['alldebrid'].values(): raise Exception() user, password = credentials()['alldebrid']['user'], credentials()['alldebrid']['pass'] login_data = {'action': 'login', 'login_login': user, 'login_password': password} login_link = 'http://alldebrid.com/register/?%s' % login_data cookie = client.request(login_link, output='cookie', close=False) url = 'http://www.alldebrid.com/service.php?link=%s' % urllib.quote_plus(u) result = client.request(url, cookie=cookie, close=False) url = client.parseDOM(result, 'a', ret='href', attrs = {'class': 'link_dl'})[0] url = client.replaceHTMLCodes(url) url = '%s|Cookie=%s' % (url, urllib.quote_plus(cookie)) return url except: pass try: if not debrid == 'rpnet' and not debrid == True: raise Exception() if '' in credentials()['rpnet'].values(): raise Exception() user, password = credentials()['rpnet']['user'], credentials()['rpnet']['pass'] login_data = {'username': user, 'password': password, 'action': 'generate', 'links': u} login_link = 'http://premium.rpnet.biz/client_api.php?%s' % login_data result = client.request(login_link, close=False) result = json.loads(result) url = result['links'][0]['generated'] return url except: return
def set_control_settings(session=None): keys = ['use_https_alt','control_all_uc_api_key','control_openload_api_key','use_openload_pairing','use_phantomjs','control_phantomjs_path'] control.set_setting('ver', VERSION) for i in range(0,len(keys)): try: key = keys[i] control.set_setting(key, Prefs[key]) except Exception as e: Log('ERROR common.py-1>set_control_settings: %s' % e) try: control.set_setting('is_uss_installed', is_uss_installed()) except Exception as e: Log.Error('ERROR common.py-2>set_control_settings: %s' % e) try: key = DEVICE_OPTIONS[7] if key in DEVICE_OPTION_PROPOGATE_TO_CONTROL.keys() and DEVICE_OPTION_PROPOGATE_TO_CONTROL[key] != None and DEVICE_OPTION_PROPOGATE_TO_CONTROL[key] == True: control.set_setting('%s-%s' % (session,key), UsingOption(key, session=session)) except Exception as e: Log.Error('ERROR common.py-3>set_control_settings: %s' % e) try: control_all_uc_api_key = Prefs['control_all_uc_api_key'] if control_all_uc_api_key == None or len(control_all_uc_api_key) == 0: is_control_all_uc_api_key = False else: is_control_all_uc_api_key = True control.set_setting('is_control_all_uc_api_key', is_control_all_uc_api_key) except Exception as e: Log.Error('ERROR common.py-2>set_control_settings: %s' % e) try: control_openload_api_key = Prefs['control_openload_api_key'] if control_openload_api_key == None or len(control_openload_api_key) == 0: is_control_openload_api_key = False else: is_control_openload_api_key = True control.set_setting('is_control_openload_api_key', is_control_openload_api_key) except Exception as e: Log.Error('ERROR common.py-2>set_control_settings: %s' % e) if Prefs["use_debug"]: Log("User Preferences have been set to Control")
def authTrakt(): try: if getTraktCredentialsInfo() == True: if control.yesnoDialog( control.lang(30479).encode('utf-8'), control.lang(30481).encode('utf-8'), '', 'Trakt', control.lang(30483).encode('utf-8'), control.lang(30482).encode('utf-8')): control.set_setting('trakt.user', '') control.set_setting('trakt.token', '') control.set_setting('trakt.refresh', '') raise Exception() result = getTrakt('/oauth/device/code', {"client_id": control.trakt_key}) result = json.loads(result) verification_url = (control.lang(30416) + '[COLOR skyblue]%s[/COLOR]' % result['verification_url']).encode('utf-8') user_code = ( control.lang(30417) + '[COLOR skyblue]%s[/COLOR]' % result['user_code']).encode('utf-8') expires_in = int(result['expires_in']) device_code = result['device_code'] interval = result['interval'] progressDialog = control.progressDialog progressDialog.create('Trakt', verification_url, user_code) for i in range(0, expires_in): try: if progressDialog.iscanceled(): break time.sleep(1) if not float(i) % interval == 0: raise Exception() r = getTrakt( '/oauth/device/token', { 'client_id': control.trakt_key, 'client_secret': control.trakt_secret, 'code': device_code }) r = json.loads(r) if 'access_token' in r: break except: pass try: progressDialog.close() except: pass token, refresh = r['access_token'], r['refresh_token'] headers = { 'Content-Type': 'application/json', 'trakt-api-key': control.trakt_key, 'trakt-api-version': '2', 'Authorization': 'Bearer %s' % token } result = client.request('http://api-v2launch.trakt.tv/users/me', headers=headers) result = json.loads(result) user = result['username'] control.set_setting('trakt.user', user) control.set_setting('trakt.token', token) control.set_setting('trakt.refresh', refresh) raise Exception() except: control.openSettings('6.1')
def initAndSleep(self): try: self.TOKEN_KEY = [] self.serverts = None self.getVidToken() if len(self.TOKEN_KEY) > 0: log('SUCCESS', 'initAndSleep', 'Vid Token: %s' % client.b64encode(self.TOKEN_KEY[0])) else: log('FAIL', 'initAndSleep', 'Vid Token Not retrieved !') t_base_link = self.base_link self.headers = {'X-Requested-With': 'XMLHttpRequest'} self.headers['Referer'] = t_base_link ua = client.randomagent() self.headers['User-Agent'] = ua #get cf cookie cookie1 = proxies.request(url=t_base_link, headers=self.headers, output='cookie', use_web_proxy=self.proxyrequired, httpsskip=True) self.headers['Cookie'] = cookie1 # get reqkey cookie try: token_url = urlparse.urljoin(t_base_link, self.token_link) r1 = proxies.request(token_url, headers=self.headers, httpsskip=True) reqkey = self.decodeJSFCookie(r1) except: reqkey = '' # get session cookie self.serverts = self.getSetServerTs() serverts = str(((int(time.time()) / 3600) * 3600)) if self.serverts == None: self.serverts = serverts else: serverts = self.serverts control.set_setting(name + 'serverts', serverts) query = {'ts': serverts} try: tk = self.__get_token(query) except: tk = self.__get_token(query, True) query.update(tk) hash_url = urlparse.urljoin(t_base_link, self.hash_menu_link) hash_url = hash_url + '?' + urllib.urlencode(query) r1, headers, content, cookie2 = proxies.request( hash_url, headers=self.headers, limit='0', output='extended', httpsskip=True) #cookie = cookie1 + '; ' + cookie2 + '; user-info=null; reqkey=' + reqkey cookie = '%s; %s; user-info=null; reqkey=%s' % (cookie1, cookie2, reqkey) self.headers['Cookie'] = cookie log('SUCCESS', 'initAndSleep', 'Cookies : %s for %s' % (cookie, self.base_link)) except Exception as e: log('ERROR', 'initAndSleep', '%s' % e)