read images at add, to figure out broken images

This commit is contained in:
q
2025-06-12 19:25:43 +03:00
parent 319e8584c8
commit 4fe95c765f
3 changed files with 25 additions and 30 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 tqdm import tqdm
__version__ = "0.0.9"
__version__ = "0.0.10"
SQLFILE = "image-list.sqlite"
BADDIRS = ["_tn", "_med", ".tn", ".med"]
MINSIZE = 0
@@ -199,9 +199,8 @@ class ImageList:
def measure(self):
duplicates = set()
missing_measurements = (
self.db.cursor()
.execute(
cursor = self.db.cursor()
missing_measurements = cursor.execute(
"""
SELECT
list.file,
@@ -228,10 +227,7 @@ class ImageList:
)
"""
)
.fetchall()
)
if len(missing_measurements) == 0:
return
for i, row in enumerate(tqdm(missing_measurements, desc="Measure", delay=1, smoothing=0.01)):
filename = row[0]
if filename == None:
@@ -272,7 +268,8 @@ class ImageList:
continue
self.db_writer.execute(
"""UPDATE data SET
"""
UPDATE data SET
p_hash = ?,
sharpness = ?,
R = ?,

View File

@@ -96,21 +96,12 @@ class DB:
cursor.execute("UPDATE data SET broken = ?;", (False,))
db.commit()
if config_version == "0.0.7": # => 0.0.8
with sqlite3.connect(self.sqlfile, timeout=30) as db:
cursor = db.cursor()
config_version = "0.0.8"
cursor.execute("UPDATE config SET value = ? WHERE key = ?;", (config_version, "version"))
cursor.execute("UPDATE config SET value = ? WHERE key = ?;", (running_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()
print(f"Migrated to {config_version}. Restart", file=sys.stderr)
print(f"Migrated to {running_version}. Restart", file=sys.stderr)
def connect(self):
conn = sqlite3.connect(self.sqlfile, timeout=30)

View File

@@ -68,10 +68,17 @@ class ImageMeasure:
self.filename = os.path.realpath(self.filename)
def is_broken(self):
"""Note: Size reading does not necessarily mean file is okay for reading"""
if self.broken is None:
self.broken = False
try:
read_image_size(self.filename)
self.broken = False
except Exception:
self.broken = True
if not self.broken:
try:
self.get_image(image_type="numpy")
self.get_image(image_type="PIL")
except Exception:
self.broken = True
return self.broken