def authorize(): control.setSetting('get.toggle', 'true') kodi_auth() control.sleep(200) control.refresh()
def reddit_subs(action, sr_name): if action is None: action = 'sub' sleep = True else: sleep = False if sr_name is None: from tulip.bookmarks import get bookmarks = get(file_=saved_subrs) if not bookmarks: return sr_name = ','.join([i['sr_name'] for i in bookmarks]) post_data = {'action': action, 'sr_name': sr_name} result = client.request(base_link() + '/api/subscribe', post=post_data, headers=request_headers(), output='response') if control.setting('debugging.toggle') == 'true': log_debug(result) if action == 'unsub' or sleep: if sleep: control.sleep(200) control.refresh()
def authorize(): control.setSetting('get.toggle', 'true') choices = [ control.lang(30063), control.lang(30080), control.lang(30149), control.lang(30081) ] choice = control.selectDialog(choices, control.lang(30061)) if choice == 0: control.open_web_browser(authorization_link()) reddit_server() elif choice == 1: kodi_auth() elif choice == 2: manual_auth() if choice != -1: control.sleep(200) control.refresh()
def delete(url, table=control.bookmarksFile): try: data = json.loads(url) dbid = hashlib.md5() for i in data['delbookmark']: dbid.update(str(i)) for i in data['action']: dbid.update(str(i)) dbid = str(dbid.hexdigest()) control.makeFile(control.dataPath) dbcon = database.connect(table) dbcur = dbcon.cursor() dbcur.execute("CREATE TABLE IF NOT EXISTS bookmark (""dbid TEXT, ""item TEXT, ""UNIQUE(dbid)"");") dbcur.execute("DELETE FROM bookmark WHERE dbid = '{}'".format(dbid)) dbcon.commit() control.refresh() except Exception: pass
def clear_bookmarks(): bookmarks.clear('bookmark', withyes=True, file_=control.bookmarksFile, notify=False, label_yes_no=30025) control.sleep(200) control.refresh()
def switch(query): pages = [control.lang(30026).format(i) for i in list(range(1, int(query) + 1))] choice = control.selectDialog(pages, heading=control.lang(30028)) if choice != -1: control.setSetting('page', str(choice)) control.sleep(200) control.refresh()
def clear_history(file_=history_file): if control.exists(file_): with open(file_, 'w') as f: f.write('') control.infoDialog(control.lang(30011)) control.sleep(200) control.refresh()
def unpin(): control.busy() title = control.infoLabel('ListItem.Title') unpin_from_file(PINNED, title) control.sleep(100) control.refresh() control.infoDialog(control.lang(30338), time=750) control.idle()
def switch(self): choices = [control.lang(30020), control.lang(30021)] choice = control.selectDialog(choices) if choice == 0: control.setSetting('sport', '0') elif choice == 1: control.setSetting('sport', '1') if choice != -1: control.sleep(100) control.refresh()
def vod_switcher(self, url): self.data = root(url)[1] translated = [control.lang(int(i)) for i in self.data] choice = control.selectDialog(heading=control.lang(30062), list=translated) if choice <= len(self.data) and not choice == -1: control.setSetting('vod_group', self.data[choice]) control.idle() control.sleep(100) # ensure setting has been saved control.refresh() else: control.execute('Dialog.Close(all)')
def page_selector(query): pages = [control.lang(30415).format(i) for i in list(range(1, int(query) + 1))] _choice = control.selectDialog(pages, heading=control.lang(30416)) if _choice != -1: control.setSetting('page', str(_choice)) control.sleep(200) control.refresh() if control.setting('pagination_reset') == 'true': # wait a second in order to ensure container is first loaded then reset the page control.sleep(1000) control.setSetting('page', '0')
def selector(): choices = [control.lang(30004), control.lang(30005)] choice = control.selectDialog(choices, control.lang(30007)) if choice == 0: control.setSetting('region', 'GR') elif choice == 1: control.setSetting('region', 'CY') if choice != -1: cache.FunctionCache().reset_cache() control.sleep(200) control.refresh()
def delete_from_history(txt, file_=history_file): with open(file_, 'r') as f: text = [i.rstrip('\n') for i in f.readlines()] text.remove(txt) with open(file_, 'w') as f: if not text: text = '' else: text = '\n'.join(text) + '\n' f.write(text) control.sleep(200) control.refresh()
def add_to_history(file_=history_file): if not control.exists(file_): control.makeFiles(control.dataPath) txt = control.dialog.input(control.name()) if not txt: return if txt not in read_from_history(): with open(file_, 'a') as f: f.writelines(txt + '\n') trim_history(file_) control.sleep(200) control.refresh()
def revoke(): yesno = control.yesnoDialog(control.lang(30079)) if yesno: post = {'token': control.setting('access.token')} headers = {'User-Agent': user_agent()} username, password = (client_id, '') result = client.request(api_link('revoke_token'), post=post, headers=headers, username=username, password=password, output='response') if control.setting('debugging.toggle') == 'true': log_debug('Revoking tokens, response: ' + result[0]) tokens_reset() control.refresh()
def delete_from_history(txt): if is_py3: f = open(HISTORY, 'r', encoding='utf-8') else: f = codecs.open(HISTORY, 'r', encoding='utf-8') lines = f.readlines() f.close() if py2_uni(txt) + '\n' in lines: lines.remove(py2_uni(txt) + '\n') else: return if is_py3: f = open(HISTORY, 'w', encoding='utf-8') else: f = codecs.open(HISTORY, 'w', encoding='utf-8') f.write(''.join(lines)) f.close() control.refresh()
def refresh(): from tulip.cache import clear clear(withyes=False) control.refresh()
def refresh(): control.refresh()
def search(self, action, query=None): if query is not None: choice = list(QUERY_MAP.keys()).index(query.split(',')[0]) str_input = query.split(',')[1] else: choice = None str_input = None if choice is None: choices = [ control.lang(30096), control.lang(30031), control.lang(30030), control.lang(30063), control.lang(30068), control.lang(30097), control.lang(30101) ] choice = control.selectDialog(heading=control.lang(30095), list=choices) if choice == 0: if str_input is None: str_input = control.dialog.input( heading=control.lang(30095).partition(' ')[0] + control.lang(30100) + control.lang(30096)) if not str_input: return add_to_history(u"Live TV Channel,{0}".format(str_input)) if action == 'add_to_history': control.refresh() return self.list = live.Indexer().live_tv(zapping=False, query=str_input.lower()) if query: directory.add(self.list) else: directory.run_builtin(action='generic_index', query=quote_plus(json.dumps(self.list))) elif choice == 1: if str_input is None: str_input = control.dialog.input( heading=control.lang(30095).partition(' ')[0] + control.lang(30100) + control.lang(30031)) try: str_input = cleantitle.strip_accents( str_input.decode('utf-8')) except (UnicodeEncodeError, UnicodeDecodeError, AttributeError): str_input = cleantitle.strip_accents(str_input) if not str_input: return add_to_history(u"Movie,{0}".format(str_input)) if action == 'add_to_history': control.refresh() return self.list = self.wrapper(str_input, 'movies') if query: directory.add(self.list, content='movies') else: directory.run_builtin(action='generic_index', query=quote_plus(json.dumps(self.list))) elif choice == 2: if str_input is None: str_input = control.dialog.input( heading=control.lang(30095).partition(' ')[0] + control.lang(30100) + control.lang(30030)) if not str_input: return try: str_input = cleantitle.strip_accents( str_input.decode('utf-8')) except (UnicodeEncodeError, UnicodeDecodeError, AttributeError): str_input = cleantitle.strip_accents(str_input) add_to_history(u"TV Serie,{0}".format(str_input)) if action == 'add_to_history': control.refresh() return self.list = self.wrapper(str_input, 'series') if query is not None: directory.add(self.list, content='tvshows') else: directory.run_builtin(action='generic_index', query=quote_plus(json.dumps(self.list))) elif choice == 3: if not str_input: str_input = control.dialog.input( heading=control.lang(30095).partition(' ')[0] + control.lang(30100) + control.lang(30063)) if not str_input: return try: str_input = cleantitle.strip_accents( str_input.decode('utf-8')) except (UnicodeEncodeError, UnicodeDecodeError, AttributeError): str_input = cleantitle.strip_accents(str_input) add_to_history(u"TV Show,{0}".format(str_input)) if action == 'add_to_history': control.refresh() return self.list = self.wrapper(str_input, 'shows') if query is not None: directory.add(self.list, content='tvshows') else: directory.run_builtin(action='generic_index', query=quote_plus(json.dumps(self.list))) elif choice == 4: if str_input is None: str_input = control.dialog.input( heading=control.lang(30095).partition(' ')[0] + control.lang(30100) + control.lang(30068)) if not str_input: return try: str_input = cleantitle.strip_accents( str_input.decode('utf-8')) except (UnicodeEncodeError, UnicodeDecodeError, AttributeError): str_input = cleantitle.strip_accents(str_input) add_to_history(u"Theater,{0}".format(str_input)) if action == 'add_to_history': control.refresh() return self.list = self.wrapper(str_input, 'theater') if query is not None: directory.add(self.list, content='movies') else: directory.run_builtin(action='generic_index', query=quote_plus(json.dumps(self.list))) elif choice == 5: if str_input is None: str_input = control.dialog.input( heading=control.lang(30095).partition(' ')[0] + control.lang(30100) + control.lang(30097)) if not str_input: return try: str_input = cleantitle.strip_accents( str_input.decode('utf-8')) except (UnicodeEncodeError, UnicodeDecodeError, AttributeError): str_input = cleantitle.strip_accents(str_input) add_to_history(u"Cartoon,{0}".format(str_input)) if action == 'add_to_history': control.refresh() return self.list = self.wrapper(str_input, 'animation') if query is not None: directory.add(self.list, content='tvshows') else: directory.run_builtin(action='generic_index', query=quote_plus(json.dumps(self.list))) elif choice == 6: if str_input is None: str_input = control.dialog.input( heading=control.lang(30095).partition(' ')[0] + control.lang(30100) + control.lang(30101)) if not str_input: return try: str_input = cleantitle.strip_accents( str_input.decode('utf-8')) except (UnicodeEncodeError, UnicodeDecodeError, AttributeError): str_input = cleantitle.strip_accents(str_input) add_to_history(u"Person,{0}".format(str_input)) if action == 'add_to_history': control.refresh() return self.list = self.wrapper(str_input, 'person') if query is not None: directory.add(self.list) else: directory.run_builtin(action='generic_index', query=quote_plus(json.dumps(self.list))) else: control.close_all()
def seq(choose): control.setSetting('group', choose) control.sleep(50) control.refresh()
def seq(choose): control.setSetting('papers_group', choose) control.idle() control.sleep(100) control.refresh()
elif action == 'unpin': utils.unpin() elif action == 'bookmarks': bookmarks.Indexer().bookmarks() elif action == 'clear_bookmarks': bm.clear('bookmark', withyes=True, label_yes_no=30311, file_=control.bookmarksFile, notify=False) control.sleep(200) control.refresh() elif action == 'search': search.Indexer().search() elif action == 'settings': settings.Indexer().menu() elif action == 'tools_menu': utils.tools_menu() elif action == 'openSettings':
ert.Indexer().root() elif action == 'addBookmark': bookmarks.add(url) elif action == 'deleteBookmark': bookmarks.delete(url) elif action == 'clear_bookmarks': bookmarks.clear('bookmark', withyes=True, file_=bookmarksFile, notify=False, label_yes_no=30025) sleep(200) refresh() elif action == 'channels': ert.Indexer().channels() elif action == 'bookmarks': ert.Indexer().bookmarks() elif action == 'index': ert.Indexer().index() elif action == 'sports': ert.Indexer().sports() elif action == 'listing': ert.Indexer().listing(url)
def get_tokens(code=None, refresh=False): if not code: code = control.setting('auth.token') if refresh: post_data = { 'grant_type': 'refresh_token', 'refresh_token': control.setting('refresh.token') } if control.setting('debugging.toggle') == 'true': log_debug('Attempting to refresh access token...') else: post_data = { 'grant_type': 'authorization_code', 'code': code, 'redirect_uri': redirect_uri } if control.setting('debugging.toggle') == 'true': log_debug('Attempting to retrieve access token...') if control.setting('debugging.toggle') == 'true': log_debug(post_data) headers = {'User-Agent': user_agent()} username, password = (client_id, '') result = client.request(api_link('access_token'), post=post_data, headers=headers, username=username, password=password) tokens = json.loads(result) if control.setting('debugging.toggle') == 'true': log_debug(tokens) if 'error' in tokens: try: log_debug('Authorization failed, reason: ' + tokens.get('error')) except TypeError: log_debug('Failure in general!') tokens_reset() return control.setSetting('access.token', tokens['access_token']) control.setSetting( 'expiration.string', convert_date(int(time.time()) + int(tokens['expires_in']))) control.setSetting('expiration.stamp', str(time.time() + float(tokens['expires_in']))) if not refresh: control.setSetting('access.scope', tokens['scope'].replace(' ', ', ')) control.setSetting('refresh.token', tokens['refresh_token']) control.infoDialog(control.lang(30402)) control.refresh() elif refresh and control.setting('notify.refresh') == 'true': control.infoDialog(control.lang(30145)) control.setSetting('auth.toggle', 'false')
def seq(group): control.setSetting('live_group', str(group)) control.idle() control.sleep(100) control.refresh()
def refresh(): from tulip import cache cache.FunctionCache().reset_cache() control.refresh()