def poll_auth(self, **params): resp = self.get_json('pin/check', **params) if resp['activated']: control.setSetting('alldebrid.apikey', resp['apikey']) self.apikey = resp['apikey'] return True, 0 return False, int(resp['expires_in'])
def SEARCH(payload, params): query = control.keyboard(control.lang(30007)) if query: if "Yes" in control.getSetting('searchhistory'): history = control.getSetting("9anime.history") if history != "": query = query + HISTORY_DELIM history = query + history while history.count(HISTORY_DELIM) > 6: history = history.rsplit(HISTORY_DELIM, 1)[0] control.setSetting("9anime.history", history) return control.draw_items(_BROWSER.search_site(query)) return False
def SEARCH(payload, params): query = control.keyboard(control.lang(30007)) if query: if "Yes" in control.getSetting('searchhistory') : history = control.getSetting("9anime.history") if history != "" : query = query+HISTORY_DELIM history=query+history while history.count(HISTORY_DELIM) > 6 : history=history.rsplit(HISTORY_DELIM, 1)[0] control.setSetting("9anime.history",history) return control.draw_items(_BROWSER.search_site(query)) return False
def set_settings(self): res = {} if self.flavor == 'anilist': res['username'] = self.getControl(1000).getText() res['token'] = self.getControl(1001).getText() else: res['authvar'] = self.getControl(1000).getText() for _id, value in res.items(): control.setSetting('%s.%s' % (self.flavor, _id), value) self.authorized = True self.close()
def SEARCH(payload, params): query = control.keyboard(control.lang(30008)) if not query: return False # TODO: Better logic here, maybe move functionatly into router? if "Yes" in control.getSetting('searchhistory'): history = control.getSetting(HISTORY_KEY) if history != "": query = query + HISTORY_DELIM history = query + history while history.count(HISTORY_DELIM) > 6: history = history.rsplit(HISTORY_DELIM, 1)[0] control.setSetting(HISTORY_KEY, history) return control.draw_items(_BROWSER.search_site(query))
def auth_loop(self): if control.progressDialog.iscanceled(): control.progressDialog.close() return time.sleep(self.OauthTimeStep) url = "client_id=%s&code=%s" % (self.ClientID, self.DeviceCode) url = self.OauthUrl + self.DeviceCredUrl % url response = json.loads(requests.get(url).text) if 'error' in response: return else: try: control.progressDialog.close() control.setSetting('rd.client_id', response['client_id']) control.setSetting('rd.secret', response['client_secret']) self.ClientSecret = response['client_secret'] self.ClientID = response['client_id'] except: control.ok_dialog(control.ADDON_NAME, control.lang(30105)) return
def poll_token(self, device_code): data = { 'client_id': self.client_id, 'code': device_code, 'grant_type': 'device_code' } token = requests.post('https://www.premiumize.me/token', data=data).json() if 'error' in token: if token['error'] == "access_denied": return False, False return True, False control.setSetting('premiumize.token', token['access_token']) self.headers['Authorization'] = 'Bearer {}'.format( token['access_token']) account_info = self.account_info() control.setSetting('premiumize.username', account_info['customer_id']) return False, True
def set_settings(self): res = {} dialog = control.kodiGui.Dialog() if self.flavor == 'anilist': res['username'] = dialog.input('Enter AniList username', type=control.kodiGui.INPUT_ALPHANUM) res['token'] = dialog.input('Enter AniList token', type=control.kodiGui.INPUT_ALPHANUM) else: res['authvar'] = dialog.input('Enter MAL auth url', type=control.kodiGui.INPUT_ALPHANUM) try: for _id, value in res.items(): if not value: raise Exception control.setSetting('%s.%s' % (self.flavor, _id), value) self.authorized = True except: pass return self.authorized
def token_request(self): if self.ClientSecret is '': return postData = {'client_id': self.ClientID, 'client_secret': self.ClientSecret, 'code': self.DeviceCode, 'grant_type': 'http://oauth.net/grant_type/device/1.0'} url = self.OauthUrl + self.TokenUrl response = requests.post(url, data=postData).text response = json.loads(response) control.setSetting('rd.auth', response['access_token']) control.setSetting('rd.refresh', response['refresh_token']) self.token = response['access_token'] self.refresh = response['refresh_token'] control.setSetting('rd.expiry', str(time.time() + int(response['expires_in']))) username = self.get_url('https://api.real-debrid.com/rest/1.0/user')['username'] control.setSetting('rd.username', username) control.ok_dialog(control.ADDON_NAME, 'Real Debrid ' + control.lang(30103))
def refreshToken(self): postData = {'grant_type': 'http://oauth.net/grant_type/device/1.0', 'code': self.refresh, 'client_secret': self.ClientSecret, 'client_id': self.ClientID } url = self.OauthUrl + 'token' response = requests.post(url, data=postData) response = json.loads(response.text) if 'access_token' in response: self.token = response['access_token'] else: pass if 'refresh_token' in response: self.refresh = response['refresh_token'] control.setSetting('rd.auth', self.token) control.setSetting('rd.refresh', self.refresh) control.setSetting('rd.expiry', str(time.time() + int(response['expires_in'])))
def CLEAR_HISTORY(payload, params): control.setSetting("9anime.history", "") return LIST_MENU(payload, params)
def CLEAR_HISTORY(payload, params): control.setSetting("9anime.history","") return LIST_MENU(payload, params)
def store_user_info(self): user_information = self.get_json('user', apikey=self.apikey) if user_information is not None: control.setSetting('alldebrid.username', user_information['user']['username'])
def __set_last_watched(url, is_dubbed, name, image): control.setSetting(LASTWATCHED_URL_KEY, 'animes/%s/%s' % (url, "dub" if is_dubbed else "sub")) control.setSetting(LASTWATCHED_NAME_KEY, '%s %s' % (name, "(Dub)" if is_dubbed else "(Sub)")) control.setSetting(LASTWATCHED_IMAGE_KEY, image)
def CLEAR_HISTORY(payload, params): control.setSetting(HISTORY_KEY, "") return LIST_MENU(payload, params)