handle bad file names by skipping them
This commit is contained in:
@@ -10,7 +10,7 @@ from imagelist2.db import DB, DBCachedWriter, sqlite_sqrt, sqlite_square
|
||||
from imagelist2.image import ImageBrokenError, ImageMeasure, is_image_extension
|
||||
from tqdm import tqdm
|
||||
|
||||
__version__ = "0.0.8"
|
||||
__version__ = "0.0.9"
|
||||
SQLFILE = "image-list.sqlite"
|
||||
BADDIRS = ["_tn", "_med", ".tn", ".med"]
|
||||
MINSIZE = 0
|
||||
@@ -53,6 +53,11 @@ class ImageList:
|
||||
for file in tqdm(files, desc="Files", delay=1, position=1, leave=False):
|
||||
if not is_image_extension(file):
|
||||
continue
|
||||
try:
|
||||
file.encode("utf-8")
|
||||
except UnicodeEncodeError:
|
||||
print(f"File in folder {path} has incompatible name for unicode encoding")
|
||||
continue
|
||||
image = ImageMeasure(file)
|
||||
if file in db_files:
|
||||
if self.options.changed:
|
||||
@@ -890,7 +895,8 @@ def main():
|
||||
|
||||
options = setup_options()
|
||||
il = ImageList(options)
|
||||
|
||||
if il.db.migrated:
|
||||
sys.exit(0)
|
||||
if options.command == "db":
|
||||
if not options.no_add:
|
||||
il.recursive_add()
|
||||
@@ -919,7 +925,6 @@ def main():
|
||||
il.broken()
|
||||
if options.command == "tag":
|
||||
il.tag_manage()
|
||||
print("")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -103,9 +103,14 @@ class DB:
|
||||
cursor.execute("UPDATE config SET value = ? WHERE key = ?;", (config_version, "version"))
|
||||
db.commit()
|
||||
|
||||
print(f"Migrated to {config_version}. Restart", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
if config_version == "0.0.8": # => 0.0.9
|
||||
with sqlite3.connect(self.sqlfile, timeout=30) as db:
|
||||
cursor = db.cursor()
|
||||
config_version = "0.0.9"
|
||||
cursor.execute("UPDATE config SET value = ? WHERE key = ?;", (config_version, "version"))
|
||||
db.commit()
|
||||
|
||||
print(f"Migrated to {config_version}. Restart", file=sys.stderr)
|
||||
|
||||
def connect(self):
|
||||
conn = sqlite3.connect(self.sqlfile, timeout=30)
|
||||
|
||||
@@ -154,7 +154,11 @@ class ImageMeasure:
|
||||
|
||||
def get_p_hash(self):
|
||||
if self.p_hash is None:
|
||||
try:
|
||||
self.p_hash = str(imagehash.phash(self.get_image("PIL"), hash_size=8))
|
||||
except Exception:
|
||||
self.broken = True
|
||||
self.p_hash = ""
|
||||
return self.p_hash
|
||||
|
||||
def get_sharpness(self):
|
||||
|
||||
Reference in New Issue
Block a user