Example #1
0
def getVideoFiles(path):
    files = glob.glob(path + "/**/*", recursive=True)
    vfiles = list()
    for f in files:
        ext = FileSystem.getExtension(f)
        if ext in VIDEOEXT:
            fn = str(f).replace("\\", "/")
            vfiles.append(str(fn))
    return vfiles
Example #2
0
def insertBinaries(filePath):
    ext = fs.getExtension(filePath)
    size = fs.getFileSize(filePath)
    name = fs.getFileName(filePath)
    filePath = filePath.replace("\\", "/")
    hexa = bin2hex(filePath)
    sn = mysql_client.getValue("SELECT max(sn) FROM BINDATA") + 1
    sql = Text.format(INSERT, name, filePath, ext, hexa, size, sn)
    mysql_client.execute(sql)
    lastId = mysql_client.getValue("SELECT max(id) FROM BINDATA")
    return lastId
Example #3
0
def api_bindata_insert(folder) :
  files = fs.listFiles(folder, asstr=True)
  count = 0
  try :
    for f in files :
      ext = Text.tolower(fs.getExtension(f))
      if ext in [".jpg", ".jpeg", ".png", ".gif"] :
        util.insertBinaries(f)
        count += 1
  except Exception as e :
    print(str(e))
  return count
Example #4
0
def api_image_resize(folder, size) :
  files = fs.listFiles(folder, asstr=True)
  count = 0
  try :
    for f in files :
      ext = Text.tolower(fs.getExtension(f))
      if ext in [".jpg", ".jpeg", ".png", ".gif"] :
        util.resizeImage(f, size)
        count += 1
  except Exception as e:
    print(str(e))
  return count
Example #5
0
def insertBinaries(filePath):
    INSERT = "INSERT INTO BINDATA(`title`, `original`, `datatype`, `data`, `info`, `size`) VALUES('{0}', '{1}', '{2}', {3}, '', {4})"
    ext = fs.getExtension(filePath)
    size = fs.getFileSize(filePath)
    fileName = fs.getFileName(filePath)
    filePath = filePath.replace("\\", "/")
    filePath = filePath.replace("'", "''")
    hexa = bin2hex(filePath)
    sql = Text.format(INSERT, fileName, filePath, ext, hexa, size)
    client = MySQL.MySQL()
    client.execute(sql)
    return
Example #6
0
def insertBinaries(filePath, origin):
    ext = fs.getExtension(filePath)
    size = fs.getFileSize(filePath)
    parts = origin.split("/")
    n = len(parts)
    name = parts[n - 3] + " " + parts[n - 2]
    filePath = filePath.replace("\\", "/")
    filePath = filePath.replace("'", "''")
    hexa = bin2hex(filePath)
    sql = Text.format(INSERT, name, origin, ext, hexa, size)
    mysql_client.execute(sql)
    lastId = mysql_client.getValue("SELECT max(id) FROM BINDATA")
    return lastId
Example #7
0
def renameAll(args):
    dir = args[0]
    wild = args[1]
    fix = args[2]
    cols = args[3]
    i = 1
    files = fs.listFiles(dir, wild)
    sortedFiles = sorted(files)
    for fold in sortedFiles:
        ext = fs.getExtension(fold)
        fmt = "{0:0" + cols + "d}"
        fnew = dir + "/" + fix + Text.format(fmt, i) + ext
        cmd = f"mv -v {fold} {fnew}"
        print(cmd)
        i += 1
Example #8
0
def delete_badchars(folder):
    # 画像ファイル一覧を得る。
    print(folder)
    files = fs.listFiles(folder, asstr=True)
    # 画像ファイルをリネーム
    for fpath in files:
        #fpath = Common.from_bytes(f)
        ext = fs.getExtension(fpath).lower()
        if ext == ".jpg" or ext == ".png" or ext == ".gif":
            fpath_new = fpath.replace("#", "").replace("+", "")
            if fpath != fpath_new:
                print("mv -v '" + fpath + "' '" + fpath_new + "'")
        else:
            print("Non image passed: " + fpath)
    return
Example #9
0
def pillow_convert():
    if request.method == "POST":
        path = request.form["path"]
        mode = request.form["mode"]
        if mode == "LA" and fs.getExtension(path) == ".jpg":
            return "Error: JPEG は LA を使用できません。"
        return render_template("pillow_convert.html",
                               result=pillow_module.convert_image(path, mode),
                               path=path,
                               mode=mode)
    else:
        defaulticon = fs.getCurrentDirectory() + PYTHONICON
        return render_template("pillow_convert.html",
                               result=defaulticon,
                               path=defaulticon,
                               mode="")
Example #10
0
  album = json["album"]
  media = json["media"]
  series = json["series"]
  mark = json["mark"]
  info = json["info"]
else :
  pass

#  ファイルリストを読む。
filename = "insert.sql"
lines = fs.readLines(filelist)
firstdata = True
sql = ""
#with open(filename, mode="w", encoding='utf_8_sig') as f :
with open(filename, mode="w", encoding='shift_jis') as f :
  f.write("INSERT INTO Videos VALUES\n")
  for path in lines :
    if firstdata :
      firstdata = False
    else :
      f.write(sql + ",\n")
    path = path.strip().replace("'", "''").replace('\\', '/')
    print(path)
    title = fs.getFileName(path)
    ext = fs.getExtension(path)
    title = title.replace(ext, "")
    sql = f"(NULL, {album}, '{title}', '{path}', '{media}', '{series}', '{mark}', '{info}', 0, 0, 0, 0, NULL)"
  f.write(sql + ";\n")
print("Done.")

Example #11
0
#!/usr/bin/env python3
#  再帰的に中間ファイルを削除する。
from Py365Lib import Common, FileSystem as fs
import os

# 中間ファイルの拡張子
iexts = (".obj", ".res", ".resw", ".pdb", ".pch", ".rc", ".rc2")

# パラメータを得る。
print("== 再帰的に中間ファイルを削除する。==")
# 対象のフォルダを得る。
if Common.count_args() == 0 :
  Common.stop(9, "フォルダを指定してください。")
folder = Common.args(0)
a = Common.readline(folder + "に対して再帰的に中間ファイルを削除します。よろしいですか? (y/n)")
if a != "y" :
  Common.stop(1, "実行を中止しました。")

# 実行する。
files = fs.listFilesRecursively(folder, asstr=True)
for f in files:
  ext = fs.getExtension(f)
  for e in iexts:
    if ext == e :
      print("削除: " + f)
      os.remove(f)
    else :
      pass
print("終了。")
Example #12
0
def rename_files(folder):
    # 画像ファイル一覧を得る。
    print(folder)
    files = fs.listFiles(folder, asstr=True)
    # 画像ファイルをリネーム
    for fpath in files:
        #fpath = Common.from_bytes(f)
        ext = fs.getExtension(fpath).lower()
        # 画像ファイルのみを対象にする。
        if ext == ".jpg" or ext == ".png" or ext == ".gif":
            # ファイル名が nnnnnnn_pnn[.jpg] か
            fname = fs.getFileName(fpath)
            ff = Text.split("_", fname)
            if not (ext in ff[1]):
                ff[1] += ext
            if len(ff) == 3:
                # 3分割できて 'master' が含まれる場合は 'master..' 部分を削除する。
                #fname_old = fname
                fname = ff[0] + '_' + ff[1]
                #print(fname_old + " to " + fname)
            elif len(ff) != 2:
                # _ で2分割できない場合(ファイル名の形式が異なる場合)はスキップする。
                print("Skipped " + fname)
                continue
            else:
                # その他の場合は何もしない。(2分割できた場合)
                pass
            # 連続番号部分の形式を確認する。
            sf = ff[1]
            if ff[1].startswith('p'):
                if len(ff[1]) == 6 or (len(ff) == 3 and len(ff[1]) == 2):
                    # 連続番号が1桁の場合
                    sf = "p0" + Text.substring(ff[1], 1)
                    newname = folder + "/" + ff[0] + "_" + sf
                    fs.move(fpath, newname)
                    print("Renamed: " + newname)
                elif len(ff) == 3 and len(ff[1]) == 7:
                    # _master1200 があり連続番号が2桁の場合
                    newname = folder + "/" + fname
                    fs.move(fpath, newname)
                elif len(ff[1]) == 8 or (len(ff) == 3 and len(ff[1]) == 4):
                    # 連続番号が3桁または連続番号が3桁かつ _master1200 がある場合
                    sn = Text.substring(ff[1], 1)
                    if sn == '1':
                        # 連続番号が3桁かつ100番台の場合
                        sf = "q" + Text.substring(ff[1], 2)
                        newname = folder + "/" + ff[0] + "_" + sf
                        fs.move(fpath, newname)
                        print("Renamed: " + newname)
                    elif sn == '2':
                        # 連続番号が3桁かつ200番台の場合
                        sf = "r" + Text.substring(ff[1], 2)
                        newname = folder + "/" + ff[0] + "_" + sf
                        fs.move(fpath, newname)
                        print("Renamed: " + newname)
                    else:
                        # 連続番号が3桁かつ300番台以上の場合はサポートしない(スキップする)
                        pass
                else:
                    # 連続番号が2桁の場合
                    #print("Passed: " + fpath)
                    pass
        else:
            #fs.move(fpath, fpath + ".jpg")
            print("Non image passed: " + fpath)
    return