def toggle_reuselanguageinvoker(forced_state=None): def _store_and_reload(output): with open(file_path, "w+") as addon_xml: addon_xml.writelines(output) xbmcgui.Dialog().ok( g.ADDON_NAME, 'Language Invoker option has been changed, reloading kodi profile') g.reload_profile() file_path = os.path.join(g.ADDON_DATA_PATH, "addon.xml") with open(file_path, "r") as addon_xml: file_lines = addon_xml.readlines() for i in range(len(file_lines)): line_string = file_lines[i] if "reuselanguageinvoker" in file_lines[i]: if ("false" in line_string and forced_state is None) or ("false" in line_string and forced_state): file_lines[i] = file_lines[i].replace("false", "true") g.set_setting("reuselanguageinvoker.status", "Enabled") _store_and_reload(file_lines) elif ("true" in line_string and forced_state is None) or ("true" in line_string and forced_state is False): file_lines[i] = file_lines[i].replace("true", "false") g.set_setting("reuselanguageinvoker.status", "Disabled") _store_and_reload(file_lines) break
def poll_auth(self, **params): resp = self.get_json('pin/check', **params) if resp['activated']: g.set_setting('alldebrid.apikey', resp['apikey']) self.apikey = resp['apikey'] return True, 0 return False, int(resp['expires_in'])
def __set_login(flavor, res, login_ts): if not res: return control.ok_dialog('Login', 'Incorrect username or password') for _id, value in list(res.items()): g.set_setting('%s.%s' % (flavor, _id), value) g.container_refresh() return control.ok_dialog('Login', 'Success')
def onPlayBackStarted(self): if self._build_playlist and g.PLAYLIST.size() == 1: self._build_playlist(self._anilist_id, self._episode, self._filter_lang) current_ = g.PLAYLIST.getposition() self.media_type = g.PLAYLIST[current_].getVideoInfoTag().getMediaType() g.set_setting('addon.last_watched', self._anilist_id) pass
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 list(res.items()): g.set_setting('%s.%s' % (self.flavor, _id), value) self.authorized = True self.close()
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() g.set_setting('rd.client_id', response['client_id']) g.set_setting('rd.secret', response['client_secret']) self.ClientSecret = response['client_secret'] self.ClientID = response['client_id'] except: control.ok_dialog(g.ADDON_NAME, g.lang(30105)) return
def set_settings(self): res = {} dialog = xbmcgui.Dialog() if self.flavor == 'anilist': dialog.textviewer( g.ADDON_NAME + ': AniList', '{}\n{}\n{}'.format( g.lang(40105), g.lang(40106).replace( 'below', 'in the input dialog that will popup once you close this' ), g.lang(40110))) res['username'] = dialog.input('Enter AniList username', type=xbmcgui.INPUT_ALPHANUM) res['token'] = dialog.input('Enter AniList token', type=xbmcgui.INPUT_ALPHANUM) else: dialog.textviewer( g.ADDON_NAME + ': MyAnimeList', '{}\n{}\n{}'.format( g.lang(40100), g.lang(40101).replace( 'below', 'in the input dialog that will popup once you close this' ), g.lang(40110))) res['authvar'] = dialog.input('Enter MAL auth url', type=xbmcgui.INPUT_ALPHANUM) try: for _id, value in list(res.items()): if not value: raise Exception g.set_setting('%s.%s' % (self.flavor, _id), value) self.authorized = True except: pass return self.authorized
def refresh_token(self): oauth_url = 'https://myanimelist.net/v1/oauth2/token' data = { 'client_id': 'a8d85a4106b259b8c9470011ce2f76bc', 'grant_type': 'refresh_token', 'refresh_token': g.get_setting('mal.refresh') } res = requests.post(oauth_url, data=data).json() g.set_setting('mal.token', res['access_token']) g.set_setting('mal.refresh', res['refresh_token']) g.set_setting('mal.expiry', str(time.time() + int(res['expires_in'])))
def refresh_token(self): params = { "grant_type": "refresh_token", "refresh_token": g.get_setting('kitsu.refresh'), } resp = self._post_request(self._to_url("oauth/token"), params=params) if resp.status_code != 200: return data = resp.json() g.set_setting('kitsu.token', data['access_token']) g.set_setting('kitsu.refresh', data['refresh_token']) g.set_setting('kitsu.expiry', str(time.time() + int(data['expires_in'])))
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) g.set_setting('rd.auth', response['access_token']) g.set_setting('rd.refresh', response['refresh_token']) self.token = response['access_token'] self.refresh = response['refresh_token'] g.set_setting('rd.expiry', str(time.time() + int(response['expires_in']))) username = self.get_url( 'https://api.real-debrid.com/rest/1.0/user')['username'] g.set_setting('rd.username', username) control.ok_dialog(g.ADDON_NAME, 'Real Debrid ' + g.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'] g.set_setting('rd.auth', self.token) g.set_setting('rd.refresh', self.refresh) g.set_setting('rd.expiry', str(time.time() + int(response['expires_in'])))
def logout_request(flavor): g.set_setting('%s.userid' % flavor, '') g.set_setting('%s.authvar' % flavor, '') g.set_setting('%s.token' % flavor, '') g.set_setting('%s.refresh' % flavor, '') g.set_setting('%s.username' % flavor, '') g.set_setting('%s.password' % flavor, '') g.set_setting('%s.sort' % flavor, '') g.set_setting('%s.titles' % flavor, '') return g.container_refresh()
def store_user_info(self): user_information = self.get_json('user', apikey=self.apikey) if user_information is not None: g.set_setting('alldebrid.username', user_information['user']['username'])