Esempio n. 1
0
def tagTrash():
    vrPath = SysConst.getTextPath()
    movieFiles = DiskIndex.getTxts(vrPath)
    allNumbers = DownloadDAO.get_all_download()

    conn = SysConst.getConnect()

    for avNumber in allNumbers:
        name = avNumber.lower()
        first = name[0:name.find('-')]
        second = name[name.find('-') + 1:]
        for file in movieFiles:
            filename = file["filename"].lower()
            if filename.find(first) > -1 and filename.find(second) > -1:
                print("find " + name + " : " + file["fullpath"])
                movieFiles.remove(file)

                av = {
                    "av_number": avNumber.upper(),
                    "local": 0,
                    "classic": 0,
                    "vr": 0,
                    "trash": 1
                }
                DownloadDAO.mark_download(conn, av)

                break

    conn.commit()
    conn.close()
Esempio n. 2
0
def renameActor(actor, shortName):
    path = SysConst.getImageCachePath() + actor
    newPath = SysConst.getImageCachePath() + shortName
    exist = os.path.exists(path)
    exist2 = os.path.exists(newPath)
    if exist and not exist2:
        Log.info(path + " <--> " + newPath)
        os.rename(path, newPath)
Esempio n. 3
0
def copyImageToTemp(movieNumbers):
    if not os.path.exists(SysConst.getImageTempPath()):
        os.mkdir(SysConst.getImageTempPath())

    allImages = getAllImages(SysConst.getImageCachePath())
    for num in movieNumbers:
        for image in allImages:
            if num in image["fullpath"]:
                shutil.copy(image["fullpath"],
                            SysConst.getImageTempPath() + image["filename"])
                break
Esempio n. 4
0
def copyOneImageToTemp(actor, avNumber):
    if not os.path.exists(SysConst.getImageTempPath()):
        os.mkdir(SysConst.getImageTempPath())

    source = SysConst.getImageCachePath() + actor + "//" + avNumber + ".jpg"
    to = SysConst.getImageTempPath() + avNumber + ".jpg"
    shutil.copy(source, to)


# avList = [{"av_number": "ABS-072"}]
# pprint(findLocalMovies(avList=avList, path="G://Game//File//"))

#deleteSmallImages(SysConst.getImageCachePath())
#copyImageToTemp(["ABS-072"])
#copyOneImageToTemp("阿部乃美久", "ARMG-274")
Esempio n. 5
0
def updateMovieMagnet2(avNumber, magnet):
    #print(avNumber + ": " + magnet)
    conn = SysConst.getConnect()
    conn.execute("update t_movies set magnet=? where av_number=?",
                 [magnet, avNumber])
    conn.commit()
    conn.close()
Esempio n. 6
0
def predict():
    conn = SysConst.getConnect()
    movies = SimilarDAO.getAllBaseMovies(conn)
    allTargetMovies = {}
    for movie in movies:
        base = movie["av_number"]
        allMovies = SimilarDAO.getSimilarsByBase(base, conn)
        i = 0
        for movie in allMovies:
            i += 1
            if movie["target"] in allTargetMovies:
                allTargetMovies[
                    movie["target"]] = i + allTargetMovies[movie["target"]]
            else:
                allTargetMovies[movie["target"]] = i
    conn.close()

    list = []
    for name in allTargetMovies:
        list.append({"av_number": name, "similar": allTargetMovies[name]})

    list = sorted(list, key=lambda d: d["similar"], reverse=False)
    list = list[0:50]

    numberList = []
    for one in list:
        numberList.append(one["av_number"])

    return numberList


#print(predict())
Esempio n. 7
0
def readHtml(name, url, cache):
    #filePath = "D://MyDrivers//cache//html//" + name + ".html"
    filePath = SysConst.getHtmlCachePath(name + ".html")

    if cache and os.path.exists(filePath):
        file = codecs.open(filePath, "r+", "utf-8")
        #file = open(filePath,'r+')
        html = file.read()
        file.close()
        return html

    #time.sleep(1)
    html = util.httpfetch2.getHtml(url)
    #Log.info(html)
    #html = str(html, encoding="utf-8")

    if not html:
        raise Exception("can not get html content: " + name + ".html")
    fo = codecs.open(filePath, "w+", "utf-8")
    #fo = open(filePath,'w+')
    fo.write(html)
    fo.close()
    return html


#print(indexActor(url="http://www.nh87.cn/guchuanyizhi/", actor="古川伊织", cache=False, files=allFiles))
#readHtml("古川伊织", "http://www.nh87.cn/guchuanyizhi/", False)
#filePath = "D://MyDrivers//cache//html//古川伊织.html"
#file = codecs.open(filePath,'r+','utf-8')
#file = open(filePath, 'r+')
#html = file.read()
#file.close()
#print(html)
Esempio n. 8
0
def getAllActors():
    conn = SysConst.getConnect()
    yesterday = round(time.time() - 24 * 60 * 60)
    lastweek = round(time.time() - 24 * 60 * 60 * 3)
    # print(yesterday)
    cursor = conn.execute(
        "SELECT name, url, short_name from t_actors where "
        " (favor = 1 and last_read_time < ?) "
        " or (favor = 0 and last_read_time < ?)"
        " or last_read_time is null"
        " order by favor desc, last_read_time desc", [yesterday, lastweek])

    results = []

    for row in cursor:
        url = row[1]

        # domain change to nanrenvip.co
        #url = url.replace("www.nh87.cn", "nanrenvip.net")
        url = url.replace("www.nh87.cn", "nanrenvip.co")
        url = url.replace("nanrenvip.net", "nanrenvip.co")
        url = url.replace("nanrenvip.co", "nanrenvip.org")

        one = {"name": row[0], "url": url, "short_name": row[2]}
        results.append(one)

    conn.close()

    return results
Esempio n. 9
0
def forcast():
    Log.info("do forcast")
    localBayes = bayes.BayesTrainingFromDB("local")
    vrBayes = bayes.BayesTrainingFromDB("vr")
    skipBayes = bayes.BayesTrainingFromDB("skip")
    trashBayes = bayes.BayesTrainingFromDB("trash")

    movies = MovieDAO.getMoviesByCondition(
        "local = 0 and trash = 0 and skip = 0")

    conn = SysConst.getConnect()
    for movie in movies:
        token = movie["av_number"] + movie["actor"] + movie["title"]
        # token = movie["av_number"] + movie["title"]
        local = localBayes.probable(token)
        vr = vrBayes.probable(token)
        skip = skipBayes.probable(token)
        trash = trashBayes.probable(token)

        #movie["vr_forcast"] = local + vr
        forcast = round((vr - skip * 0.4 - trash * 0.01 + local * 0.3) * 10000)
        MovieDAO.updateMovieVRForcast(movie["av_number"], forcast, conn)

    conn.commit()
    conn.close()
Esempio n. 10
0
def calcByActor(actor):
    movies = MovieDAO.getMoviesByCondition("actor = '" + actor + "' and vr = 1")
    print(movies)

    allImages = DiskIndex.getAllImages(SysConst.getImageCachePath())

    for movie in movies:
        calcMovie(movie, allImages)
Esempio n. 11
0
def updateLastReadTime(name):
    conn = SysConst.getConnect()
    now = round(time.time())

    cursor = conn.cursor()
    cursor.execute("update t_actors set last_read_time = ? where name = ?",
                   [now, name])

    conn.commit()
    conn.close()
Esempio n. 12
0
def updateMovieLastReadTime(avNumber):
    conn = SysConst.getConnect()
    now = round(time.time())

    cursor = conn.cursor()
    cursor.execute(
        "update t_movies set last_read_time = ? where av_number = ?",
        [now, avNumber])

    conn.commit()
    conn.close()
Esempio n. 13
0
def tagDownload():
    path = SysConst.getDownloadPath()
    movieFiles = DiskIndex.getTxts(path)
    allNumbers = DownloadDAO.get_all_download()

    conn = SysConst.getConnect()

    for avNumber in allNumbers:
        name = avNumber.lower()
        first = name[0:name.find('-')]
        second = name[name.find('-') + 1:]
        for file in movieFiles:
            filename = file["filename"].lower()
            if filename.find(first) > -1 and filename.find(second) > -1:
                print("find " + name + " : " + file["fullpath"])
                movieFiles.remove(file)
                MovieDAO.markMovieDownload(conn, avNumber.upper())
                break

    conn.commit()
    conn.close()
Esempio n. 14
0
def getUndownloadMagnets():
    #images = DiskIndex.getAllImages(SysConst.getImageTempPath())
    conn = SysConst.getConnect()
    movies = MovieDAO.getMoviesByCondition(
        "local = 2 and download = 0 and magnet is not null and (read != 1 or read is null) order by create_time limit 20"
    )
    for movie in movies:
        print(movie["magnet"])
        MovieDAO.updateMovieReaded(movie["av_number"], conn)

    conn.commit()
    conn.close()
Esempio n. 15
0
def get_all_download():
    conn = SysConst.getConnect()
    cursor = conn.execute(
        "SELECT av_number from t_download where local != 1 and trash != 1")

    results = []
    for row in cursor:
        results.append(row[0])

    conn.close()

    return results
Esempio n. 16
0
def calcMovie(movie, allImages):
    try:
        actor = movie["actor"]
        conn = SysConst.getConnect()
        basePath = SysConst.getImageCachePath() + actor + "//" + movie["av_number"] + ".jpg";

        if not os.path.exists(basePath):
            print("can not find file: " + basePath)
            return

        base = movie["av_number"]
        targetMap = getTargetMap(base, conn)
        print("compare " + actor + "/" + base)
        count = 0
        skipCount = 0

        for image in allImages:
            targetPath = image["fullpath"]
            target = image["filename"][0:-4]
            # exist = SimilarDAO.hasSimilar(base, target, conn)
            if not target in targetMap:
                # print(targetPath)
                count += 1

                if count % 500 == 0:
                    print("calc " + str(count))
                    conn.commit()
                    conn.close()
                    conn = SysConst.getConnect()

                similar = ImageSimilar.calc_similar_by_path(basePath, targetPath)
                obj = {"base": base, "target": target, "similar": similar}
                SimilarDAO.saveSimilar(obj, conn)
            else:
                skipCount += 1

        print("count: " + str(count) + ", skip: " + str(skipCount))
    finally:
        conn.commit()
        conn.close()
Esempio n. 17
0
def saveActors(actors):
    newActors = []
    conn = SysConst.getConnect()

    for actor in actors:
        exist = saveActor(actor, conn)
        if not exist:
            newActors.append(actor)

    conn.commit()
    conn.close()

    return newActors
Esempio n. 18
0
def copyWrongMagnets():
    movies = MovieDAO.getMoviesByCondition(
        "local = 2 and download = 0 and magnet is not null")

    conn = SysConst.getConnect()
    try:
        for movie in movies:
            WrongMagnetDAO.saveMagnet(movie, conn)
    except Exception as err:
        print(err)
    finally:
        conn.commit()
        conn.close()
Esempio n. 19
0
def findWrongMagnets(avNumber):
    conn = SysConst.getConnect()

    cursor = conn.execute(
        "SELECT magnet, create_time from t_wrong_magnets where av_number = ?",
        [avNumber])

    results = []
    for row in cursor:
        results.append(row[0])

    conn.close()

    return results
Esempio n. 20
0
def getFavorActors():
    conn = SysConst.getConnect()
    yesterday = round(time.time() - 24 * 60 * 60)
    # print(yesterday)
    cursor = conn.execute("SELECT * from t_actors where favor = 1")

    results = []
    for row in cursor:
        one = {"name": row[0], "url": row[1]}
        results.append(one)

    conn.close()

    return results
Esempio n. 21
0
def getAllActorsFully():
    conn = SysConst.getConnect()
    # print(yesterday)
    cursor = conn.execute(
        "SELECT name, url, short_name from t_actors "
        " order by favor desc, last_read_time desc", [])

    results = []
    for row in cursor:
        one = {"name": row[0], "url": row[1], "short_name": row[2]}
        results.append(one)

    conn.close()

    return results
Esempio n. 22
0
def getMagnetFromTemp():
    images = DiskIndex.getAllImages(SysConst.getImageTempPath())
    mags = []
    try:
        for image in images:
            mag = getMagnet(image["filename"][0:-4])
            if mag:
                print(mag)
                mags.append(mag)
    except Exception as err:
        print(err)
    finally:
        for mag in mags:
            print(mag)

    return mags
Esempio n. 23
0
def updateShortName():
    conn = SysConst.getConnect()
    # print(yesterday)
    cursor = conn.execute("SELECT name, url from t_actors", [])
    results = []
    for row in cursor:
        one = {"name": row[0], "url": row[1]}
        results.append(one)

    cursor = conn.cursor()

    for row in results:
        shortName = substr1(row["url"])
        print(shortName)
        cursor.execute("update t_actors set short_name = ? where name = ?",
                       [shortName, row["name"]])
    conn.commit()
    conn.close()
Esempio n. 24
0
def checkDirPath(actor):
    path = SysConst.getImageCachePath() + actor
    #Log.info(sys.getdefaultencoding() + " path: " + path)
    exist = os.path.exists(path)
    if not exist:
        os.mkdir(path)
Esempio n. 25
0
import os
from index import SysConst

if __name__ == '__main__':
    folder = SysConst.getDownloadPath()

    movieTypes = set(["avi", "mp4", "mkv", "rmvb", "wmv", "iso"])

    for fpath, dirs, fs in os.walk(folder):
        for filename in fs:
            # fullpath = os.path.join(fpath, filename)
            suffix = filename[-3:].lower()
            if filename[0:1] != "." and len(filename) > 4 and suffix in movieTypes:
                newFileName = filename[:-4] + ".txt"
                newFullPath = fpath + "/" + newFileName
                print("createFile: " + newFullPath)
                file = open(newFullPath, "wt")
                file.close()

Esempio n. 26
0
def calcAllVR():
    movies = MovieDAO.getMoviesByCondition("vr = 1")
    #print(movies)
    allImages = DiskIndex.getAllImages(SysConst.getImageCachePath())
    for movie in movies:
        calcMovie(movie, allImages)
Esempio n. 27
0
def getFilePath(actor, avNumber):
    return SysConst.getImageCachePath() + actor + "//" + avNumber + ".jpg"
Esempio n. 28
0
    conn.close()

    return results


def mark_download(conn, av):
    cursor = conn.cursor()

    av_number = av["av_number"]
    local = av.get("local")
    classic = av.get("classic")
    vr = av.get("vr")
    trash = av.get("trash")

    cursor.execute(
        "update t_download set local=?,classic=?,vr=?,trash=? where av_number=?",
        [local, classic, vr, trash, av_number])


if __name__ == '__main__':
    av = {
        "av_number": "CEMN-004",
        "local": 0,
        "classic": 0,
        "vr": 0,
        "trash": 1
    }

    with SysConst.getConnect() as conn:
        mark_download(conn, av)
Esempio n. 29
0
def getConnect():
    return SysConst.getConnect()