read images at add, to figure out broken images
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 imagelist2.image import ImageBrokenError, ImageMeasure, is_image_extension
|
||||||
from tqdm import tqdm
|
from tqdm import tqdm
|
||||||
|
|
||||||
__version__ = "0.0.9"
|
__version__ = "0.0.10"
|
||||||
SQLFILE = "image-list.sqlite"
|
SQLFILE = "image-list.sqlite"
|
||||||
BADDIRS = ["_tn", "_med", ".tn", ".med"]
|
BADDIRS = ["_tn", "_med", ".tn", ".med"]
|
||||||
MINSIZE = 0
|
MINSIZE = 0
|
||||||
@@ -199,9 +199,8 @@ class ImageList:
|
|||||||
def measure(self):
|
def measure(self):
|
||||||
|
|
||||||
duplicates = set()
|
duplicates = set()
|
||||||
missing_measurements = (
|
cursor = self.db.cursor()
|
||||||
self.db.cursor()
|
missing_measurements = cursor.execute(
|
||||||
.execute(
|
|
||||||
"""
|
"""
|
||||||
SELECT
|
SELECT
|
||||||
list.file,
|
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)):
|
for i, row in enumerate(tqdm(missing_measurements, desc="Measure", delay=1, smoothing=0.01)):
|
||||||
filename = row[0]
|
filename = row[0]
|
||||||
if filename == None:
|
if filename == None:
|
||||||
@@ -272,7 +268,8 @@ class ImageList:
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
self.db_writer.execute(
|
self.db_writer.execute(
|
||||||
"""UPDATE data SET
|
"""
|
||||||
|
UPDATE data SET
|
||||||
p_hash = ?,
|
p_hash = ?,
|
||||||
sharpness = ?,
|
sharpness = ?,
|
||||||
R = ?,
|
R = ?,
|
||||||
|
|||||||
@@ -96,21 +96,12 @@ class DB:
|
|||||||
cursor.execute("UPDATE data SET broken = ?;", (False,))
|
cursor.execute("UPDATE data SET broken = ?;", (False,))
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
if config_version == "0.0.7": # => 0.0.8
|
|
||||||
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"
|
cursor.execute("UPDATE config SET value = ? WHERE key = ?;", (running_version, "version"))
|
||||||
cursor.execute("UPDATE config SET value = ? WHERE key = ?;", (config_version, "version"))
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
if config_version == "0.0.8": # => 0.0.9
|
print(f"Migrated to {running_version}. Restart", file=sys.stderr)
|
||||||
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):
|
def connect(self):
|
||||||
conn = sqlite3.connect(self.sqlfile, timeout=30)
|
conn = sqlite3.connect(self.sqlfile, timeout=30)
|
||||||
|
|||||||
@@ -68,10 +68,17 @@ class ImageMeasure:
|
|||||||
self.filename = os.path.realpath(self.filename)
|
self.filename = os.path.realpath(self.filename)
|
||||||
|
|
||||||
def is_broken(self):
|
def is_broken(self):
|
||||||
|
"""Note: Size reading does not necessarily mean file is okay for reading"""
|
||||||
if self.broken is None:
|
if self.broken is None:
|
||||||
|
self.broken = False
|
||||||
try:
|
try:
|
||||||
read_image_size(self.filename)
|
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:
|
except Exception:
|
||||||
self.broken = True
|
self.broken = True
|
||||||
return self.broken
|
return self.broken
|
||||||
|
|||||||
Reference in New Issue
Block a user