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 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__":
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ class DB:
|
|||||||
# last version without config
|
# last version without config
|
||||||
config_version = "0.0.6"
|
config_version = "0.0.6"
|
||||||
self.migrated = True
|
self.migrated = True
|
||||||
if config_version == "0.0.6": # => 0.0.7
|
if config_version == "0.0.6": # => 0.0.7
|
||||||
try:
|
try:
|
||||||
with sqlite3.connect(self.sqlfile, timeout=30) as db:
|
with sqlite3.connect(self.sqlfile, timeout=30) as db:
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
@@ -96,16 +96,21 @@ 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
|
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"
|
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)
|
||||||
|
|||||||
@@ -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:
|
||||||
self.p_hash = str(imagehash.phash(self.get_image("PIL"), hash_size=8))
|
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
|
return self.p_hash
|
||||||
|
|
||||||
def get_sharpness(self):
|
def get_sharpness(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user