handle bad file names by skipping them

This commit is contained in:
q
2025-06-12 09:33:26 +03:00
parent 2aabfffbf3
commit 319e8584c8
3 changed files with 23 additions and 9 deletions

View File

@@ -10,7 +10,7 @@ from imagelist2.db import DB, DBCachedWriter, sqlite_sqrt, sqlite_square
from imagelist2.image import ImageBrokenError, ImageMeasure, is_image_extension from imagelist2.image import ImageBrokenError, ImageMeasure, is_image_extension
from tqdm import tqdm from tqdm import tqdm
__version__ = "0.0.8" __version__ = "0.0.9"
SQLFILE = "image-list.sqlite" SQLFILE = "image-list.sqlite"
BADDIRS = ["_tn", "_med", ".tn", ".med"] BADDIRS = ["_tn", "_med", ".tn", ".med"]
MINSIZE = 0 MINSIZE = 0
@@ -53,6 +53,11 @@ class ImageList:
for file in tqdm(files, desc="Files", delay=1, position=1, leave=False): for file in tqdm(files, desc="Files", delay=1, position=1, leave=False):
if not is_image_extension(file): if not is_image_extension(file):
continue continue
try:
file.encode("utf-8")
except UnicodeEncodeError:
print(f"File in folder {path} has incompatible name for unicode encoding")
continue
image = ImageMeasure(file) image = ImageMeasure(file)
if file in db_files: if file in db_files:
if self.options.changed: if self.options.changed:
@@ -890,7 +895,8 @@ def main():
options = setup_options() options = setup_options()
il = ImageList(options) il = ImageList(options)
if il.db.migrated:
sys.exit(0)
if options.command == "db": if options.command == "db":
if not options.no_add: if not options.no_add:
il.recursive_add() il.recursive_add()
@@ -919,7 +925,6 @@ def main():
il.broken() il.broken()
if options.command == "tag": if options.command == "tag":
il.tag_manage() il.tag_manage()
print("")
if __name__ == "__main__": if __name__ == "__main__":

View File

@@ -100,12 +100,17 @@ class DB:
with sqlite3.connect(self.sqlfile, timeout=30) as db: with sqlite3.connect(self.sqlfile, timeout=30) as db:
cursor = db.cursor() cursor = db.cursor()
config_version = "0.0.8" config_version = "0.0.8"
cursor.execute("UPDATE config SET value = ? WHERE key = ?;", (config_version,"version")) cursor.execute("UPDATE config SET value = ? WHERE key = ?;", (config_version, "version"))
db.commit()
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() db.commit()
print(f"Migrated to {config_version}. Restart", file=sys.stderr) print(f"Migrated to {config_version}. Restart", file=sys.stderr)
sys.exit(1)
def connect(self): def connect(self):
conn = sqlite3.connect(self.sqlfile, timeout=30) conn = sqlite3.connect(self.sqlfile, timeout=30)

View File

@@ -154,7 +154,11 @@ class ImageMeasure:
def get_p_hash(self): def get_p_hash(self):
if self.p_hash is None: if self.p_hash is None:
try:
self.p_hash = str(imagehash.phash(self.get_image("PIL"), hash_size=8)) 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 return self.p_hash
def get_sharpness(self): def get_sharpness(self):