def insert(meta): try: control.makeFile(control.dataPath) dbcon = database.connect(control.metacacheFile) dbcur = dbcon.cursor() dbcur.execute("CREATE TABLE IF NOT EXISTS meta (" "imdb TEXT, " "tvdb TEXT, " "lang TEXT, " "user TEXT, " "item TEXT, " "time TEXT, " "UNIQUE(imdb, tvdb, lang, user)" ");") t = int(time.time()) for m in meta: try: i = repr(m['item']) try: dbcur.execute( "DELETE * FROM meta WHERE (imdb = '%s' and lang = '%s' and user = '******' and not imdb = '0') or (tvdb = '%s' and lang = '%s' and user = '******' and not tvdb = '0')" % (m['imdb'], m['lang'], m['user'], m['tvdb'], m['lang'], m['user'])) except: pass dbcur.execute( "INSERT INTO meta Values (?, ?, ?, ?, ?, ?)", (m['imdb'], m['tvdb'], m['lang'], m['user'], i, t)) except: pass dbcon.commit() except: return
def prepareSources(self): try: control.makeFile(control.dataPath) self.sourceFile = control.providercacheFile dbcon = database.connect(self.sourceFile) dbcur = dbcon.cursor() dbcur.execute("CREATE TABLE IF NOT EXISTS rel_url (" "source TEXT, " "imdb_id TEXT, " "season TEXT, " "episode TEXT, " "rel_url TEXT, " "UNIQUE(source, imdb_id, season, episode)" ");") dbcur.execute("CREATE TABLE IF NOT EXISTS rel_src (" "source TEXT, " "imdb_id TEXT, " "season TEXT, " "episode TEXT, " "hosts TEXT, " "added TEXT, " "UNIQUE(source, imdb_id, season, episode)" ");") except: pass
def reset(self, currentTime, totalTime, name, year='0'): try: if not control.setting('bookmarks') == 'true': raise Exception() timeInSeconds = str(currentTime) ok = int(currentTime) > 180 and (currentTime / totalTime) <= .92 idFile = hashlib.md5() for i in name: idFile.update(str(i)) for i in year: idFile.update(str(i)) idFile = str(idFile.hexdigest()) control.makeFile(control.dataPath) dbcon = database.connect(control.bookmarksFile) dbcur = dbcon.cursor() dbcur.execute("CREATE TABLE IF NOT EXISTS bookmark (" "idFile TEXT, " "timeInSeconds TEXT, " "UNIQUE(idFile)" ");") dbcur.execute("DELETE FROM bookmark WHERE idFile = '%s'" % idFile) if ok: dbcur.execute("INSERT INTO bookmark Values (?, ?)", (idFile, timeInSeconds)) dbcon.commit() except: pass
def timeout(function, *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: pass try: table = table['table'] except: table = 'rel_list' try: control.makeFile(control.dataPath) dbcon = database.connect(control.cacheFile) dbcur = dbcon.cursor() dbcur.execute("SELECT * FROM %s WHERE func = '%s' AND args = '%s'" % (table, f, a)) match = dbcur.fetchone() return int(match[3]) except: return
def get(function, timeout, *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: pass try: table = table['table'] except: table = 'rel_list' try: control.makeFile(control.dataPath) dbcon = database.connect(control.cacheFile) dbcur = dbcon.cursor() dbcur.execute("SELECT * FROM %s WHERE func = '%s' AND args = '%s'" % (table, f, a)) match = dbcur.fetchone() response = eval(match[2].encode('utf-8')) t1 = int(match[3]) t2 = int(time.time()) update = (abs(t2 - t1) / 3600) >= int(timeout) if update == False: return response except: pass try: r = function(*args) if (r == None or r == []) and not response == None: return response elif (r == None or r == []): return r except: return try: r = repr(r) t = int(time.time()) dbcur.execute("CREATE TABLE IF NOT EXISTS %s (""func TEXT, ""args TEXT, ""response TEXT, ""added TEXT, ""UNIQUE(func, args)"");" % table) dbcur.execute("DELETE FROM %s WHERE func = '%s' AND args = '%s'" % (table, f, a)) dbcur.execute("INSERT INTO %s Values (?, ?, ?, ?)" % table, (f, a, r, t)) dbcon.commit() except: pass try: return eval(r.encode('utf-8')) except: pass
def addView(content): try: skin = control.skin skinPath = control.skinPath xml = os.path.join(skinPath, 'addon.xml') file = control.openFile(xml) read = file.read().replace('\n', '') file.close() try: src = re.compile('defaultresolution="(.+?)"').findall(read)[0] except: src = re.compile('<res.+?folder="(.+?)"').findall(read)[0] src = os.path.join(skinPath, src) src = os.path.join(src, 'MyVideoNav.xml') file = control.openFile(src) read = file.read().replace('\n', '') file.close() views = re.compile('<views>(.+?)</views>').findall(read)[0] views = [int(x) for x in views.split(',')] for view in views: label = control.infoLabel('Control.GetLabel(%s)' % (view)) if not (label == '' or label == None): break record = (skin, content, str(view)) control.makeFile(control.dataPath) dbcon = database.connect(control.viewsFile) dbcur = dbcon.cursor() dbcur.execute("CREATE TABLE IF NOT EXISTS views (" "skin TEXT, " "view_type TEXT, " "view_id TEXT, " "UNIQUE(skin, view_type)" ");") dbcur.execute( "DELETE FROM views WHERE skin = '%s' AND view_type = '%s'" % (record[0], record[1])) dbcur.execute("INSERT INTO views Values (?, ?, ?)", record) dbcon.commit() viewName = control.infoLabel('Container.Viewmode') skinName = control.addon(skin).getAddonInfo('name') skinIcon = control.addon(skin).getAddonInfo('icon') control.infoDialog(viewName, heading=skinName, sound=True, icon=skinIcon) except: return
def clearSources(self): try: control.idle() yes = control.yesnoDialog( control.lang(32407).encode('utf-8'), '', '') if not yes: return control.makeFile(control.dataPath) dbcon = database.connect(control.providercacheFile) dbcur = dbcon.cursor() dbcur.execute("DROP TABLE IF EXISTS rel_src") dbcur.execute("VACUUM") dbcon.commit() control.infoDialog(control.lang(32408).encode('utf-8'), sound=True, icon='INFO') except: pass
def download(name, image, url): if url == None: return from resources.lib.smodules import control try: headers = dict(urlparse.parse_qsl(url.rsplit('|', 1)[1])) except: headers = dict('') url = url.split('|')[0] content = re.compile('(.+?)\sS(\d*)E\d*$').findall(name) transname = name.translate(None, '\/:*?"<>|').strip('.') levels = ['../../../..', '../../..', '../..', '..'] if len(content) == 0: dest = control.setting('movie.download.path') dest = control.transPath(dest) for level in levels: try: control.makeFile(os.path.abspath(os.path.join(dest, level))) except: pass control.makeFile(dest) dest = os.path.join(dest, transname) control.makeFile(dest) else: dest = control.setting('tv.download.path') dest = control.transPath(dest) for level in levels: try: control.makeFile(os.path.abspath(os.path.join(dest, level))) except: pass control.makeFile(dest) transtvshowtitle = content[0][0].translate(None, '\/:*?"<>|').strip('.') dest = os.path.join(dest, transtvshowtitle) control.makeFile(dest) dest = os.path.join(dest, 'Season %01d' % int(content[0][1])) control.makeFile(dest) ext = os.path.splitext(urlparse.urlparse(url).path)[1][1:] if not ext in ['mp4', 'mkv', 'flv', 'avi', 'mpg']: ext = 'mp4' dest = os.path.join(dest, transname + '.' + ext) sysheaders = urllib.quote_plus(json.dumps(headers)) sysurl = urllib.quote_plus(url) systitle = urllib.quote_plus(name) sysimage = urllib.quote_plus(image) sysdest = urllib.quote_plus(dest) script = inspect.getfile(inspect.currentframe()) cmd = 'RunScript(%s, %s, %s, %s, %s, %s)' % ( script, sysurl, sysdest, systitle, sysimage, sysheaders) xbmc.executebuiltin(cmd)
def resolve(self, url): try: m3u8 = [ '#EXTM3U', '#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",DEFAULT=YES,AUTOSELECT=YES,NAME="Stream 1",URI="{audio_stream}"', '', '#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=0,NAME="{stream_name}",AUDIO="audio"', '{video_stream}' ] query = urlparse.parse_qs(url) query = dict([(key, query[key][0]) if query[key] else (key, '') for key in query]) auth = 'http://streamtorrent.tv/api/torrent/%s/%s.m3u8?json=true' % ( query['vid_id'], query['stream_id']) r = client.request(auth) r = json.loads(r) try: url = r['url'] except: url = None if not url == None: def dialog(url): try: self.disableScraper = control.yesnoDialog( 'To watch this video visit from any device', '[COLOR skyblue]%s[/COLOR]' % url, '', 'Torba', 'Cancel', 'Settings') except: pass workers.Thread(dialog, url).start() control.sleep(3000) for i in range(100): try: if not control.condVisibility( 'Window.IsActive(yesnoDialog)'): break r = client.request(auth) r = json.loads(r) try: url = r['url'] except: url = None if url == None: break workers.Thread(dialog, url).start() control.sleep(3000) except: pass if self.disableScraper: control.openSettings(query='2.0') return '' control.execute('Dialog.Close(yesnoDialog)') if not url == None: return stream_name = '%sp' % (query['height']) video_stream = r[stream_name] if not 'audio' in r: return video_stream audio_stream = r['audio'] content = ('\n'.join(m3u8)).format( **{ 'audio_stream': audio_stream, 'stream_name': stream_name, 'video_stream': video_stream }) path = os.path.join(control.dataPath, 'torbase.m3u8') control.makeFile(control.dataPath) control.deleteFile(path) file = control.openFile(path, 'w') file.write(content) file.close() return path except: return