コード例 #1
0
    def run(self, url, source):

        path = os.path.join(control.dataPath, 'temp')
        path = path.decode('utf-8')

        control.deleteDir(os.path.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 == 'subztvgr':
            subtitle = subztvgr.subztvgr().download(path, url)

        if not subtitle == None:
            item = control.item(label=subtitle)
            control.addItem(handle=int(sys.argv[1]),
                            url=subtitle,
                            listitem=item,
                            isFolder=False)

        control.directory(int(sys.argv[1]))
コード例 #2
0
def delete(url):
    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(control.bookmarksFile)
        dbcur = dbcon.cursor()
        dbcur.execute("CREATE TABLE IF NOT EXISTS bookmark ("
                      "dbid TEXT, "
                      "item TEXT, "
                      "UNIQUE(dbid)"
                      ");")
        dbcur.execute("DELETE FROM bookmark WHERE dbid = '%s'" % dbid)
        dbcon.commit()

        control.refresh()
    except:
        pass
コード例 #3
0
def add(url):
    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 data.iteritems() if not k == 'bookmark')
        item = repr(item)

        control.makeFile(control.dataPath)
        dbcon = database.connect(control.bookmarksFile)
        dbcur = dbcon.cursor()
        dbcur.execute("CREATE TABLE IF NOT EXISTS bookmark ("
                      "dbid TEXT, "
                      "item TEXT, "
                      "UNIQUE(dbid)"
                      ");")
        dbcur.execute("DELETE FROM bookmark WHERE dbid = '%s'" % dbid)
        dbcur.execute("INSERT INTO bookmark Values (?, ?)", (dbid, item))
        dbcon.commit()
    except:
        pass
コード例 #4
0
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
コード例 #5
0
def get():
    try:
        control.makeFile(control.dataPath)
        dbcon = database.connect(control.bookmarksFile)
        dbcur = dbcon.cursor()
        dbcur.execute("SELECT * FROM bookmark")
        items = dbcur.fetchall()
        items = [eval(i[1].encode('utf-8')) for i in items]
        return items
    except:
        pass
コード例 #6
0
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