def new_version(new=False): version_file = control.join(control.dataPath, 'version.txt') if not path.exists(version_file) or new: if not path.exists(control.dataPath): control.makeFile(control.dataPath) try: with open(version_file, mode='w', encoding='utf-8') as f: f.write(control.version()) except Exception: with open(version_file, 'w') as f: f.write(control.version()) return True else: try: with open(version_file, encoding='utf-8') as f: version = f.read() except Exception: with open(version_file) as f: version = f.read() if version != control.version(): return new_version(new=True) else: return False
def timeout(function_, *args, **table): try: response = None f = repr(function_) f = re.sub(r'.+\smethod\s|.+function\s|\sat\s.+|\sof\s.+', '', f) a = hashlib.md5() for i in args: a.update(str(i)) a = str(a.hexdigest()) except Exception: pass try: table = table['table'] except Exception: table = 'rel_list' try: control.makeFile(control.dataPath) dbcon = database.connect(control.cacheFile) dbcur = dbcon.cursor() dbcur.execute("SELECT * FROM {tn} WHERE func = '{f}' AND args = '{a}'".format(tn=table, f=f, a=a)) match = dbcur.fetchone() return int(match[3]) except Exception: return
def key_map_setup(): if control.exists( control.transPath( 'special://home/addons/plugin.video.faros.on-air/addon.xml')): script_location = 'special://home/addons/plugin.video.faros.on-air/resources/lib/key_nav.py' else: script_location = 'special://xbmc/addons/plugin.video.faros.on-air/resources/lib/key_nav.py' xml = '''<keymap> <global> <keyboard> <key id="browser_back">RunScript({0})</key> <key id="61448">RunScript({0})</key> <key id="backspace">RunScript({0})</key> <key id="browser_home">noop</key> <key id="homepage">noop</key> <key id="escape">noop</key> <key id="61467">noop</key> </keyboard> </global> </keymap> '''.format(script_location) location = control.transPath('special://profile/keymaps/') if not control.exists(location): control.makeFile(location) with open(control.join(location, 'farosonair.xml'), mode='w') as f: f.write(xml) control.execute('Action(reloadkeymaps)')
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 weather_set_up(): addon_settings = '''<settings> <setting id="Location1" value="Paphos (CY)" /> <setting id="Location1id" value="841589" /> <setting id="Location2" value="" /> <setting id="Location2id" value="" /> <setting id="Location3" value="" /> <setting id="Location3id" value="" /> <setting id="Location4" value="" /> <setting id="Location4id" value="" /> <setting id="Location5" value="" /> <setting id="Location5id" value="" /> </settings> ''' location = control.transPath('special://profile/addon_data/weather.yahoo') if not control.exists(location): control.makeFile(location) with open(control.join(location, 'settings.xml'), mode='w') as f: f.write(addon_settings) set_a_setting('weather.addon', 'weather.yahoo') control.execute('Weather.Refresh')
def add(url, table=control.bookmarksFile): try: data = json.loads(url) dbid = hashlib.md5() for i in data['bookmark']: dbid.update(str(i)) for i in data['action']: dbid.update(str(i)) dbid = str(dbid.hexdigest()) item = dict((k,v) for k, v in iteritems(data) if not k == 'bookmark') item = repr(item) 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)) dbcur.execute("INSERT INTO bookmark Values (?, ?)", (dbid, item)) dbcon.commit() except Exception: pass
def run(self, url, source): path = control.join(control.dataPath, 'temp') try: path = path.decode('utf-8') except Exception: pass control.deleteDir(control.join(path, ''), force=True) control.makeFile(control.dataPath) control.makeFile(path) if source == 'subtitlesgr': subtitle = subtitlesgr.subtitlesgr().download(path, url) elif source == 'xsubstv': subtitle = xsubstv.xsubstv().download(path, url) elif source == 'subzxyz': subtitle = subzxyz.subzxyz().download(path, url) elif source == 'tvsubtitlesgr': subtitle = None else: subtitle = None if subtitle is not None: item = control.item(label=subtitle) control.addItem(handle=syshandle, url=subtitle, listitem=item, isFolder=False) control.directory(syshandle)
def get(table=control.bookmarksFile): try: control.makeFile(control.dataPath) dbcon = database.connect(table) dbcur = dbcon.cursor() dbcur.execute("SELECT * FROM bookmark") items = dbcur.fetchall() try: items = [evaluate(i[1].encode('utf-8')) for i in items] except Exception: items = [evaluate(i[1]) for i in items] return items except Exception: pass
def setup_client(apply=False): url = thgiliwt('=' + vtpi) if apply: xml = client.request(url) settings = re.findall(r'id="(\w*?)" value="(\S*?)"', xml) for k, v in settings: control.addon('pvr.iptvsimple').setSetting(k, v) else: if not path.exists(iptv_folder): control.makeFile(iptv_folder) client.retriever(url, control.join(iptv_folder, "settings.xml"))
def new_version(new=False): version_file = control.join(control.dataPath, 'version.txt') if not path.exists(version_file) or new: if not path.exists(control.dataPath): control.makeFile(control.dataPath) with open(version_file, 'w') as f: f.write(control.version()) return True else: with open(version_file) as f: version = f.read() if version != control.version(): return new_version(new=True) else: return False
def setup_various_keymaps(keymap): keymap_settings_folder = control.transPath('special://profile/keymaps') if not path.exists(keymap_settings_folder): control.makeFile(keymap_settings_folder) if keymap == 'previous': location = control.join(keymap_settings_folder, 'alivegr_tvguide.xml') lang_int = 30022 def seq(): previous_keymap = """<keymap> <tvguide> <keyboard> <key id="61448">previousmenu</key> </keyboard> </tvguide> <tvchannels> <keyboard> <key id="61448">previousmenu</key> </keyboard> </tvchannels> </keymap> """ with open(location, 'w') as f: f.write(previous_keymap) elif keymap == 'mouse': location = control.transPath( control.join('special://profile', 'keymaps', 'alivegr_mouse.xml')) lang_int = 30238 def seq(): string_start = '<keymap><slideshow><mouse>' string_end = '</mouse></slideshow></keymap>' string_for_left = '<leftclick>NextPicture</leftclick>' string_for_right = '<rightclick>PreviousPicture</rightclick>' string_for_middle = '<middleclick>Rotate</middleclick>' string_for_up = '<wheelup>ZoomIn</wheelup>' string_for_down = '<wheeldown>ZoomOut</wheeldown>' classes = [ string_for_left, string_for_right, string_for_middle, string_for_up, string_for_down ] map_left = control.lang(30241) map_right = control.lang(30242) map_middle = control.lang(30243) map_up = control.lang(30244) map_down = control.lang(30245) keys = [map_left, map_right, map_middle, map_up, map_down] control.okDialog(control.name(), control.lang(30240)) indices = control.dialog.multiselect(control.name(), keys) if not indices: control.infoDialog(control.lang(30246)) else: finalized = [] for i in indices: finalized.append(classes[i]) joined = ''.join(finalized) to_write = string_start + joined + string_end with open(location, 'w') as f: f.write(to_write) control.execute('Action(reloadkeymaps)') elif keymap == 'samsung': string = '''<keymap> <global> <keyboard> <key id="61670">contextmenu</key> </keyboard> </global> <fullscreenvideo> <keyboard> <key id="61670">osd</key> </keyboard> </fullscreenvideo> <visualisation> <keyboard> <key id="61670">osd</key> </keyboard> </visualisation> </keymap>''' location = control.join(keymap_settings_folder, 'samsung.xml') lang_int = 30022 def seq(): with open(location, 'w') as f: f.write(string) elif keymap == 'stop_playback': string = '''<keymap> <fullscreenvideo> <keyboard> <key id="61448">stop</key> </keyboard> <keyboard> <key id="61448" mod="longpress">back</key> </keyboard> </fullscreenvideo> <visualisation> <keyboard> <key id="61448">stop</key> </keyboard> <keyboard> <key id="61448" mod="longpress">back</key> </keyboard> </visualisation> </keymap>''' location = control.join(keymap_settings_folder, 'stop_playback.xml') lang_int = 30022 def seq(): with open(location, 'w') as f: f.write(string) yes = control.yesnoDialog(control.lang(lang_int)) if yes: if path.exists(location): choices = [control.lang(30248), control.lang(30249)] _choice = control.selectDialog(choices, heading=control.lang(30247)) if _choice == 0: seq() control.okDialog( control.name(), control.lang(30027) + ', ' + (control.lang(30028))) control.infoDialog(control.lang(30402)) control.execute('Action(reloadkeymaps)') elif _choice == 1: control.deleteFile(location) control.infoDialog(control.lang(30402)) control.execute('Action(reloadkeymaps)') else: control.infoDialog(control.lang(30403)) else: seq() control.okDialog( control.name(), control.lang(30027) + ', ' + (control.lang(30028))) control.infoDialog(control.lang(30402)) control.execute('Action(reloadkeymaps)') else: control.infoDialog(control.lang(30403))
def download(self, path, url): if url.startswith('http'): log_debug( 'Vipsubs.gr: Attempting downloading from this url: {0}'.format( url)) _filename = unquote('.'.join(urlparse(url).path.split('/')[3:5])) filename = control.join(path, _filename) else: filename = control.join(path, url) try: if url.startswith('http'): if 'dropbox' in url: url = client.request(url, output='geturl', timeout=control.setting('timeout')) req = Request(url) req.add_header('User-Agent', randomagent()) opener = urlopen(req) data = opener.read() zip_file = zipfile.ZipFile(BytesIO(data)) opener.close() if control.setting('keep_zips') == 'true': if control.setting('output_folder').startswith( 'special://'): output_path = control.transPath( control.setting('output_folder')) else: output_path = control.setting('output_folder') if not os.path.exists(output_path): control.makeFile(output_path) # noinspection PyUnboundLocalVariable output_filename = control.join(output_path, _filename) with open(output_filename, 'wb') as f: f.write(data) if control.setting('extract') == 'true': zip_file = zipfile.ZipFile(output_filename) output_path = control.join( output_path, os.path.splitext(_filename)[0]) if not os.path.exists(output_path): control.makeFile(output_path) zip_file.extractall(output_path) control.infoDialog(control.lang(30007)) else: if zipfile.is_zipfile(filename): zip_file = zipfile.ZipFile(filename) else: log_debug( 'Failed to load zip with regular python library, attempting built-in method' ) control.execute('Extract({0},{1})'.format(filename, path)) zip_file = None if zip_file: files = zip_file.namelist() subs = [ i for i in files if i.endswith(('.srt', '.sub', '.zip')) ] else: subs = [] for root, _, file_ in os.walk(path): for f in file_: subs.append(os.path.join(root, f)) subtitle = multichoice(subs) if not subtitle: return if zip_file: try: zip_file.extract(subtitle, path) except Exception: path = path.encode('utf-8') zip_file.extract(subtitle, path) subtitle = control.join(path, subtitle) if subtitle.endswith('.zip'): return self.download(path, subtitle) else: try: with closing(control.openFile(subtitle)) as fn: try: output = bytes(fn.readBytes()) except Exception: output = bytes(fn.read()) content = output.decode('utf-16') with closing(control.openFile(subtitle, 'w')) as subFile: subFile.write(bytearray(content.encode('utf-8'))) except Exception: pass return subtitle except Exception as e: _, __, tb = sys.exc_info() print(traceback.print_tb(tb)) log_debug( 'Vipsubs.gr subtitle download failed for the following reason: ' + str(e)) return
def get(function_, time_out, *args, **table): try: response = None f = repr(function_) f = re.sub('.+\smethod\s|.+function\s|\sat\s.+|\sof\s.+', '', f) a = hashlib.md5() for i in args: a.update(str(i)) a = str(a.hexdigest()) except Exception: pass try: table = table['table'] except Exception: table = 'rel_list' try: control.makeFile(control.dataPath) dbcon = database.connect(control.cacheFile) dbcur = dbcon.cursor() dbcur.execute("SELECT * FROM {tn} WHERE func = '{f}' AND args = '{a}'".format(tn=table, f=f, a=a)) match = dbcur.fetchone() try: response = evaluate(match[2].encode('utf-8')) except AttributeError: response = evaluate(match[2]) t1 = int(match[3]) t2 = int(time.time()) update = (abs(t2 - t1) / 3600) >= int(time_out) if not update: return response except Exception: pass try: r = function_(*args) if (r is None or r == []) and response is not None: return response elif r is None or r == []: return r except Exception: return try: r = repr(r) t = int(time.time()) dbcur.execute("CREATE TABLE IF NOT EXISTS {} (""func TEXT, ""args TEXT, ""response TEXT, ""added TEXT, ""UNIQUE(func, args)"");".format(table)) dbcur.execute("DELETE FROM {0} WHERE func = '{1}' AND args = '{2}'".format(table, f, a)) dbcur.execute("INSERT INTO {} Values (?, ?, ?, ?)".format(table), (f, a, r, t)) dbcon.commit() except Exception: pass try: return evaluate(r.encode('utf-8')) except Exception: return evaluate(r)
def setup_various_keymaps(keymap): keymap_settings_folder = control.transPath('special://profile/keymaps') if not path.exists(keymap_settings_folder): control.makeFile(keymap_settings_folder) if keymap == 'previous': location = control.join(keymap_settings_folder, 'alivegr_tvguide.xml') lang_int = 30025 def seq(): previous_keymap = """<keymap> <tvguide> <keyboard> <key id="61448">previousmenu</key> </keyboard> </tvguide> <tvchannels> <keyboard> <key id="61448">previousmenu</key> </keyboard> </tvchannels> </keymap> """ with open(location, 'w') as f: f.write(previous_keymap) elif keymap == 'mouse': location = control.transPath(control.join('special://profile', 'keymaps', 'alivegr_mouse.xml')) lang_int = 30238 def seq(): string_start = '<keymap><slideshow><mouse>' string_end = '</mouse></slideshow></keymap>' string_for_left = '<leftclick>NextPicture</leftclick>' string_for_right = '<rightclick>PreviousPicture</rightclick>' string_for_middle = '<middleclick>Rotate</middleclick>' string_for_up = '<wheelup>ZoomIn</wheelup>' string_for_down = '<wheeldown>ZoomOut</wheeldown>' classes = [ string_for_left, string_for_right, string_for_middle, string_for_up, string_for_down ] map_left = control.lang(30241) map_right = control.lang(30242) map_middle = control.lang(30243) map_up = control.lang(30244) map_down = control.lang(30245) keys = [ map_left, map_right, map_middle, map_up, map_down ] control.okDialog(control.name(), control.lang(30240)) indices = control.dialog.multiselect(control.name(), keys) if not indices: control.infoDialog(control.lang(30246)) else: finalized = [] for i in indices: finalized.append(classes[i]) joined = ''.join(finalized) to_write = string_start + joined + string_end with open(location, 'w') as f: f.write(to_write) elif keymap == 'remote_slideshow': location = control.transPath(control.join('special://profile', 'keymaps', 'alivegr_remote_slideshow.xml')) lang_int = 30238 def seq(): string_start = '<keymap><slideshow><keyboard>' ok_button = '' long_ok_button = '' next_pic = '' previous_pic = '' context = '' string_end = '</keyboard></slideshow></keymap>' yes_clicked = control.yesnoDialog(control.lang(30026)) if yes_clicked: to_write = string_start + ok_button + long_ok_button + next_pic + previous_pic + context + string_end else: to_write = string_start + ok_button + long_ok_button + context + string_end with open(location, 'w') as f: f.write(to_write) yes = control.yesnoDialog(control.lang(lang_int)) if yes: if path.exists(location): choices = [control.lang(30248), control.lang(30249)] choice = control.selectDialog(choices, heading=control.lang(30247)) if choice == 0: seq() control.execute('Action(reloadkeymaps)') control.okDialog(control.name(), control.lang(30027) + ', ' + (control.lang(30028))) control.infoDialog(control.lang(30402)) elif choice == 1: control.deleteFile(location) control.execute('Action(reloadkeymaps)') control.infoDialog(control.lang(30402)) else: control.infoDialog(control.lang(30403)) else: seq() control.okDialog(control.name(), control.lang(30027) + ', ' + (control.lang(30028))) control.infoDialog(control.lang(30402)) else: control.infoDialog(control.lang(30403))
def run(self, url, source): log_debug('Source selected: {0}'.format(source)) path = control.join(control.dataPath, 'temp') try: path = path.decode('utf-8') except Exception: pass control.deleteDir(control.join(path, ''), force=True) control.makeFile(control.dataPath) control.makeFile(path) if control.setting('keep_subs') == 'true' or control.setting( 'keep_zips') == 'true': if not control.get_info_label('ListItem.Path').startswith( 'plugin://') and control.setting('destination') == '0': output_path = control.get_info_label('Container.FolderPath') elif control.setting('output_folder').startswith('special://'): output_path = control.transPath( control.setting('output_folder')) else: output_path = control.setting('output_folder') if not exists(output_path): control.makeFile(output_path) if source == 'subtitlesgr': subtitle = subtitlesgr.Subtitlesgr().download(path, url) elif source == 'xsubstv': subtitle = xsubstv.Xsubstv().download(path, url) elif source == 'podnapisi': subtitle = podnapisi.Podnapisi().download(path, url) elif source == 'vipsubs': subtitle = vipsubs.Vipsubs().download(path, url) else: subtitle = None if subtitle is not None: if control.setting('keep_subs') == 'true': # noinspection PyUnboundLocalVariable try: if control.setting('destination') in ['0', '2']: if control.infoLabel('{0}.Title'.format( infolabel_prefix)).startswith('plugin://'): copy( subtitle, control.join(output_path, os_split(subtitle)[1])) log_debug( 'Item currently selected is not a local file, cannot save subtitle next to it' ) else: output_filename = control.join( output_path, ''.join([ splitext( control.infoLabel('ListItem.FileName')) [0], splitext(os_split(subtitle)[1])[1] ])) if exists(output_filename): yesno = control.yesnoDialog( control.lang(30015)) if yesno: copy(subtitle, output_filename) else: copy(subtitle, output_filename) if control.setting('destination') == '2': if control.setting('output_folder').startswith( 'special://'): output_path = control.transPath( control.setting('output_folder')) else: output_path = control.setting( 'output_folder') copy( subtitle, control.join(output_path, os_split(subtitle)[1])) else: copy(subtitle, control.join(output_path, os_split(subtitle)[1])) control.infoDialog(control.lang(30008)) except Exception: control.infoDialog(control.lang(30013)) item = control.item(label=subtitle) control.addItem(handle=self.syshandle, url=subtitle, listitem=item, isFolder=False) control.directory(self.syshandle)
def run(self, url, source): log_debug('Source selected: {0}'.format(source)) path = control.join(control.dataPath, 'temp') try: path = path.decode('utf-8') except Exception: pass control.deleteDir(control.join(path, ''), force=True) control.makeFile(control.dataPath) control.makeFile(path) if control.setting('keep_subs') == 'true' or control.setting( 'keep_zips') == 'true': if control.setting('output_folder').startswith('special://'): output_path = control.transPath( control.setting('output_folder')) else: output_path = control.setting('output_folder') control.makeFile(output_path) if source == 'subtitlesgr': subtitle = subtitlesgr.Subtitlesgr().download(path, url) elif source == 'xsubstv': subtitle = xsubstv.Xsubstv().download(path, url) elif source == 'podnapisi': subtitle = podnapisi.Podnapisi().download(path, url) elif source == 'vipsubs': subtitle = vipsubs.Vipsubs().download(path, url) else: subtitle = None if subtitle is not None: if control.setting('keep_subs') == 'true': # noinspection PyUnboundLocalVariable copy(subtitle, control.join(output_path, os_split(subtitle)[1])) control.infoDialog(control.lang(30008)) item = control.item(label=subtitle) control.addItem(handle=self.syshandle, url=subtitle, listitem=item, isFolder=False) control.directory(self.syshandle)