def set(hashed, data, hours=24): try: r = repr(data) t = int(time.time()) e = int(t+(60*60*int(hours))) common.makeFile(common.dataPath) dbcon = database.connect(common.libraDbFile) dbcur = dbcon.cursor() dbcur.execute("CREATE TABLE IF NOT EXISTS cache (""hash TEXT, ""data TEXT, ""expire TEXT, ""created TEXT, ""UNIQUE(hash)"");") dbcur.execute("DELETE FROM cache WHERE hash = '%s'" % (hashed)) dbcur.execute("INSERT INTO cache Values (?, ?, ?, ?)", (hashed, r, e, t)) dbcon.commit() return True except: return None
def get(hashed): try: t = int(time.time()) common.makeFile(common.dataPath) dbcon = database.connect(common.libraDbFile) dbcur = dbcon.cursor() dbcur.execute("CREATE TABLE IF NOT EXISTS cache (""hash TEXT, ""data TEXT, ""expire TEXT, ""created TEXT, ""UNIQUE(hash)"");") dbcur.execute("SELECT * FROM cache WHERE hash = '%s'" % (hashed)) match = dbcur.fetchone() if int(match[2]) < t: dbcur.execute("DELETE FROM cache WHERE hash = '%s'" % (hashed)) dbcon.commit() return None return match except: return None
def strm_file(self, i): try: name, title, year, imdb = i['name'], i['title'], i['year'], i['imdb'] sysname, systitle = urllib.quote_plus(name), urllib.quote_plus(title) transname = name.translate(None, "\/:*?&'`<>|").strip('.') content = 'plugin://script.libra/?action=play&name=%s&title=%s&year=%s&imdb=%s' % (sysname, systitle, year, imdb) common.makeFile(self.library_folder) folder = os.path.join(self.library_folder, transname) if common.fileExists(folder + "/"): return False common.makeFile(folder) try: if not 'ftp://' in folder: raise Exception() from ftplib import FTP ftparg = re.compile('ftp://(.+?):(.+?)@(.+?):?(\d+)?/(.+/?)').findall(folder) ftp = FTP(ftparg[0][2],ftparg[0][0],ftparg[0][1]) try: ftp.cwd(ftparg[0][4]) except: ftp.mkd(ftparg[0][4]) ftp.quit() except: pass stream = os.path.join(folder, transname + '.strm') strmfile = common.openFile(stream, 'w') strmfile.write(str(content)) strmfile.close() nfo_stream = os.path.join(folder, transname + '.nfo') nfofile = common.openFile(nfo_stream, 'w') nfocontent = "http://www.imdb.com/title/%s" % imdb nfofile.write(str(nfocontent)) nfofile.close() except: return False print "Create %s" % stream return True