Spaces:
Runtime error
Runtime error
File size: 24,399 Bytes
c19ca42 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 |
import hashlib
import json
import os
import sqlite3
from shutil import copy2
from modules import scripts, shared
from tempfile import gettempdir
from PIL import Image
from contextlib import contextmanager
version = 7
path_recorder_file = os.path.join(scripts.basedir(), "path_recorder.txt")
aes_cache_file = os.path.join(scripts.basedir(), "aes_scores.json")
exif_cache_file = os.path.join(scripts.basedir(), "exif_data.json")
ranking_file = os.path.join(scripts.basedir(), "ranking.json")
archive = os.path.join(scripts.basedir(), "archive")
source_db_file = os.path.join(scripts.basedir(), "wib.sqlite3")
tmp_db_file = os.path.join(gettempdir(), "sd-images-browser.sqlite3")
db_file = source_db_file
if getattr(shared.cmd_opts, "image_browser_tmp_db", False):
db_file = tmp_db_file
if os.path.exists(source_db_file):
copy2(source_db_file, tmp_db_file)
elif os.path.exists(tmp_db_file):
os.remove(tmp_db_file)
def backup_tmp_db():
if(db_file == tmp_db_file):
copy2(tmp_db_file, source_db_file)
np = "Negative prompt: "
st = "Steps: "
timeout = 30
@contextmanager
def transaction(db = db_file):
conn = sqlite3.connect(db, timeout=timeout)
try:
conn.isolation_level = None
cursor = conn.cursor()
cursor.execute("BEGIN")
yield cursor
cursor.execute("COMMIT")
finally:
conn.close()
backup_tmp_db()
def create_filehash(cursor):
cursor.execute('''
CREATE TABLE IF NOT EXISTS filehash (
file TEXT PRIMARY KEY,
hash TEXT,
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
''')
cursor.execute('''
CREATE TRIGGER filehash_tr
AFTER UPDATE ON filehash
BEGIN
UPDATE filehash SET updated = CURRENT_TIMESTAMP WHERE file = OLD.file;
END;
''')
return
def create_work_files(cursor):
cursor.execute('''
CREATE TABLE IF NOT EXISTS work_files (
file TEXT PRIMARY KEY
)
''')
return
def create_db(cursor):
cursor.execute('''
CREATE TABLE IF NOT EXISTS db_data (
key TEXT PRIMARY KEY,
value TEXT
)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS path_recorder (
path TEXT PRIMARY KEY,
depth INT,
path_display TEXT,
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
''')
cursor.execute('''
CREATE TRIGGER path_recorder_tr
AFTER UPDATE ON path_recorder
BEGIN
UPDATE path_recorder SET updated = CURRENT_TIMESTAMP WHERE path = OLD.path;
END;
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS exif_data (
file TEXT,
key TEXT,
value TEXT,
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (file, key)
)
''')
cursor.execute('''
CREATE INDEX IF NOT EXISTS exif_data_key ON exif_data (key)
''')
cursor.execute('''
CREATE TRIGGER exif_data_tr
AFTER UPDATE ON exif_data
BEGIN
UPDATE exif_data SET updated = CURRENT_TIMESTAMP WHERE file = OLD.file AND key = OLD.key;
END;
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS ranking (
file TEXT PRIMARY KEY,
name TEXT,
ranking TEXT,
created TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
''')
cursor.execute('''
CREATE INDEX IF NOT EXISTS ranking_name ON ranking (name)
''')
cursor.execute('''
CREATE TRIGGER ranking_tr
AFTER UPDATE ON ranking
BEGIN
UPDATE ranking SET updated = CURRENT_TIMESTAMP WHERE file = OLD.file;
END;
''')
create_filehash(cursor)
create_work_files(cursor)
return
def migrate_path_recorder(cursor):
if os.path.exists(path_recorder_file):
try:
with open(path_recorder_file) as f:
# json-version
path_recorder = json.load(f)
for path, values in path_recorder.items():
path = os.path.realpath(path)
depth = values["depth"]
path_display = f"{path} [{depth}]"
cursor.execute('''
INSERT INTO path_recorder (path, depth, path_display)
VALUES (?, ?, ?)
''', (path, depth, path_display))
except json.JSONDecodeError:
with open(path_recorder_file) as f:
# old txt-version
path = f.readline().rstrip("\n")
while len(path) > 0:
path = os.path.realpath(path)
cursor.execute('''
INSERT INTO path_recorder (path, depth, path_display)
VALUES (?, ?, ?)
''', (path, 0, f"{path} [0]"))
path = f.readline().rstrip("\n")
return
def update_exif_data(cursor, file, info):
prompt = "0"
negative_prompt = "0"
key_values = "0: 0"
if info != "0":
info_list = info.split("\n")
prompt = ""
negative_prompt = ""
key_values = ""
for info_item in info_list:
if info_item.startswith(st):
key_values = info_item
elif info_item.startswith(np):
negative_prompt = info_item.replace(np, "")
else:
if prompt == "":
prompt = info_item
else:
# multiline prompts
prompt = f"{prompt}\n{info_item}"
if key_values != "":
key_value_pairs = []
key_value = ""
quote_open = False
for char in key_values + ",":
key_value += char
if char == '"':
quote_open = not quote_open
if char == "," and not quote_open:
try:
k, v = key_value.strip(" ,").split(": ")
except ValueError:
k = key_value.strip(" ,").split(": ")[0]
v = ""
key_value_pairs.append((k, v))
key_value = ""
try:
cursor.execute('''
INSERT INTO exif_data (file, key, value)
VALUES (?, ?, ?)
''', (file, "prompt", prompt))
except sqlite3.IntegrityError:
# Duplicate, delete all "file" entries and try again
cursor.execute('''
DELETE FROM exif_data
WHERE file = ?
''', (file,))
cursor.execute('''
INSERT INTO exif_data (file, key, value)
VALUES (?, ?, ?)
''', (file, "prompt", prompt))
cursor.execute('''
INSERT INTO exif_data (file, key, value)
VALUES (?, ?, ?)
''', (file, "negative_prompt", negative_prompt))
for (key, value) in key_value_pairs:
try:
cursor.execute('''
INSERT INTO exif_data (file, key, value)
VALUES (?, ?, ?)
''', (file, key, value))
except sqlite3.IntegrityError:
pass
return
def migrate_exif_data(cursor):
if os.path.exists(exif_cache_file):
with open(exif_cache_file, 'r') as file:
exif_cache = json.load(file)
for file, info in exif_cache.items():
file = os.path.realpath(file)
update_exif_data(cursor, file, info)
return
def migrate_ranking(cursor):
if os.path.exists(ranking_file):
with open(ranking_file, 'r') as file:
ranking = json.load(file)
for file, info in ranking.items():
if info != "None":
file = os.path.realpath(file)
name = os.path.basename(file)
cursor.execute('''
INSERT INTO ranking (file, name, ranking)
VALUES (?, ?, ?)
''', (file, name, info))
return
def get_hash(file):
# Get filehash without exif info
try:
image = Image.open(file)
except Exception as e:
print(e)
hash = hashlib.sha512(image.tobytes()).hexdigest()
image.close()
return hash
def migrate_filehash(cursor, version):
if version <= "4":
create_filehash(cursor)
cursor.execute('''
SELECT file
FROM ranking
''')
for (file,) in cursor.fetchall():
if os.path.exists(file):
hash = get_hash(file)
cursor.execute('''
INSERT OR REPLACE
INTO filehash (file, hash)
VALUES (?, ?)
''', (file, hash))
return
def migrate_work_files(cursor):
create_work_files(cursor)
return
def update_db_data(cursor, key, value):
cursor.execute('''
INSERT OR REPLACE
INTO db_data (key, value)
VALUES (?, ?)
''', (key, value))
return
def get_version():
with transaction() as cursor:
cursor.execute('''
SELECT value
FROM db_data
WHERE key = 'version'
''',)
db_version = cursor.fetchone()
return db_version
def get_last_default_tab():
with transaction() as cursor:
cursor.execute('''
SELECT value
FROM db_data
WHERE key = 'last_default_tab'
''',)
last_default_tab = cursor.fetchone()
return last_default_tab
def migrate_path_recorder_dirs(cursor):
cursor.execute('''
SELECT path, path_display
FROM path_recorder
''')
for (path, path_display) in cursor.fetchall():
real_path = os.path.realpath(path)
if path != real_path:
update_from = path
update_to = real_path
try:
cursor.execute('''
UPDATE path_recorder
SET path = ?,
path_display = ? || SUBSTR(path_display, LENGTH(?) + 1)
WHERE path = ?
''', (update_to, update_to, update_from, update_from))
except sqlite3.IntegrityError as e:
# these are double keys, because the same file can be in the db with different path notations
(e_msg,) = e.args
if e_msg.startswith("UNIQUE constraint"):
cursor.execute('''
DELETE FROM path_recorder
WHERE path = ?
''', (update_from,))
else:
raise
return
def migrate_exif_data_dirs(cursor):
cursor.execute('''
SELECT file
FROM exif_data
''')
for (filepath,) in cursor.fetchall():
(path, file) = os.path.split(filepath)
real_path = os.path.realpath(path)
if path != real_path:
update_from = filepath
update_to = os.path.join(real_path, file)
try:
cursor.execute('''
UPDATE exif_data
SET file = ?
WHERE file = ?
''', (update_to, update_from))
except sqlite3.IntegrityError as e:
# these are double keys, because the same file can be in the db with different path notations
(e_msg,) = e.args
if e_msg.startswith("UNIQUE constraint"):
cursor.execute('''
DELETE FROM exif_data
WHERE file = ?
''', (update_from,))
else:
raise
return
def migrate_ranking_dirs(cursor, db_version):
if db_version == "1":
cursor.execute('''
ALTER TABLE ranking
ADD COLUMN name TEXT
''')
cursor.execute('''
CREATE INDEX IF NOT EXISTS ranking_name ON ranking (name)
''')
cursor.execute('''
SELECT file, ranking
FROM ranking
''')
for (filepath, ranking) in cursor.fetchall():
if filepath == "" or ranking == "None":
cursor.execute('''
DELETE FROM ranking
WHERE file = ?
''', (filepath,))
else:
(path, file) = os.path.split(filepath)
real_path = os.path.realpath(path)
name = file
update_from = filepath
update_to = os.path.join(real_path, file)
try:
cursor.execute('''
UPDATE ranking
SET file = ?,
name = ?
WHERE file = ?
''', (update_to, name, update_from))
except sqlite3.IntegrityError as e:
# these are double keys, because the same file can be in the db with different path notations
(e_msg,) = e.args
if e_msg.startswith("UNIQUE constraint"):
cursor.execute('''
DELETE FROM ranking
WHERE file = ?
''', (update_from,))
else:
raise
return
def check():
if not os.path.exists(db_file):
print("Image Browser: Creating database")
with transaction() as cursor:
create_db(cursor)
update_db_data(cursor, "version", version)
update_db_data(cursor, "last_default_tab", "Maintenance")
migrate_path_recorder(cursor)
migrate_exif_data(cursor)
migrate_ranking(cursor)
migrate_filehash(cursor, str(version))
print("Image Browser: Database created")
db_version = get_version()
with transaction() as cursor:
if db_version[0] <= "2":
# version 1 database had mixed path notations, changed them all to abspath
# version 2 database still had mixed path notations, because of windows short name, changed them all to realpath
print(f"Image Browser: Upgrading database from version {db_version[0]} to version {version}")
migrate_path_recorder_dirs(cursor)
migrate_exif_data_dirs(cursor)
migrate_ranking_dirs(cursor, db_version[0])
if db_version[0] <= "4":
migrate_filehash(cursor, db_version[0])
if db_version[0] <= "5":
migrate_work_files(cursor)
if db_version[0] <= "6":
update_db_data(cursor, "last_default_tab", "Others")
update_db_data(cursor, "version", version)
print(f"Image Browser: Database upgraded from version {db_version[0]} to version {version}")
return version
def load_path_recorder():
with transaction() as cursor:
cursor.execute('''
SELECT path, depth, path_display
FROM path_recorder
''')
path_recorder = {path: {"depth": depth, "path_display": path_display} for path, depth, path_display in cursor.fetchall()}
return path_recorder
def select_ranking(file):
with transaction() as cursor:
cursor.execute('''
SELECT ranking
FROM ranking
WHERE file = ?
''', (file,))
ranking_value = cursor.fetchone()
if ranking_value is None:
return_ranking = "None"
else:
(return_ranking,) = ranking_value
return return_ranking
def update_ranking(file, ranking):
name = os.path.basename(file)
with transaction() as cursor:
if ranking == "None":
cursor.execute('''
DELETE FROM ranking
WHERE file = ?
''', (file,))
else:
cursor.execute('''
INSERT OR REPLACE
INTO ranking (file, name, ranking)
VALUES (?, ?, ?)
''', (file, name, ranking))
hash = get_hash(file)
cursor.execute('''
INSERT OR REPLACE
INTO filehash (file, hash)
VALUES (?, ?)
''', (file, hash))
return
def update_path_recorder(path, depth, path_display):
with transaction() as cursor:
cursor.execute('''
INSERT OR REPLACE
INTO path_recorder (path, depth, path_display)
VALUES (?, ?, ?)
''', (path, depth, path_display))
return
def update_path_recorder(path, depth, path_display):
with transaction() as cursor:
cursor.execute('''
INSERT OR REPLACE
INTO path_recorder (path, depth, path_display)
VALUES (?, ?, ?)
''', (path, depth, path_display))
return
def delete_path_recorder(path):
with transaction() as cursor:
cursor.execute('''
DELETE FROM path_recorder
WHERE path = ?
''', (path,))
return
def update_path_recorder_mult(cursor, update_from, update_to):
cursor.execute('''
UPDATE path_recorder
SET path = ?,
path_display = ? || SUBSTR(path_display, LENGTH(?) + 1)
WHERE path = ?
''', (update_to, update_to, update_from, update_from))
return
def update_exif_data_mult(cursor, update_from, update_to):
update_from = update_from + os.path.sep
update_to = update_to + os.path.sep
cursor.execute('''
UPDATE exif_data
SET file = ? || SUBSTR(file, LENGTH(?) + 1)
WHERE file like ? || '%'
''', (update_to, update_from, update_from))
return
def update_ranking_mult(cursor, update_from, update_to):
update_from = update_from + os.path.sep
update_to = update_to + os.path.sep
cursor.execute('''
UPDATE ranking
SET file = ? || SUBSTR(file, LENGTH(?) + 1)
WHERE file like ? || '%'
''', (update_to, update_from, update_from))
return
def delete_exif_0(cursor):
cursor.execute('''
DELETE FROM exif_data
WHERE file IN (
SELECT file FROM exif_data a
WHERE value = '0'
GROUP BY file
HAVING COUNT(*) = (SELECT COUNT(*) FROM exif_data WHERE file = a.file)
)
''')
return
def get_ranking_by_file(cursor, file):
cursor.execute('''
SELECT ranking
FROM ranking
WHERE file = ?
''', (file,))
ranking_value = cursor.fetchone()
return ranking_value
def get_ranking_by_name(cursor, name):
cursor.execute('''
SELECT file, ranking
FROM ranking
WHERE name = ?
''', (name,))
ranking_value = cursor.fetchone()
if ranking_value is not None:
(file, _) = ranking_value
cursor.execute('''
SELECT hash
FROM filehash
WHERE file = ?
''', (file,))
hash_value = cursor.fetchone()
else:
hash_value = None
return ranking_value, hash_value
def insert_ranking(cursor, file, ranking, hash):
name = os.path.basename(file)
cursor.execute('''
INSERT INTO ranking (file, name, ranking)
VALUES (?, ?, ?)
''', (file, name, ranking))
cursor.execute('''
INSERT OR REPLACE
INTO filehash (file, hash)
VALUES (?, ?)
''', (file, hash))
return
def replace_ranking(cursor, file, alternate_file, hash):
name = os.path.basename(file)
cursor.execute('''
UPDATE ranking
SET file = ?
WHERE file = ?
''', (file, alternate_file))
cursor.execute('''
INSERT OR REPLACE
INTO filehash (file, hash)
VALUES (?, ?)
''', (file, hash))
return
def update_exif_data_by_key(cursor, file, key, value):
cursor.execute('''
INSERT OR REPLACE
INTO exif_data (file, key, value)
VALUES (?, ?, ?)
''', (file, key, value))
return
def select_prompts(file):
with transaction() as cursor:
cursor.execute('''
SELECT key, value
FROM exif_data
WHERE file = ?
AND KEY in ('prompt', 'negative_prompt')
''', (file,))
rows = cursor.fetchall()
prompt = ""
neg_prompt = ""
for row in rows:
(key, value) = row
if key == 'prompt':
prompt = value
elif key == 'negative_prompt':
neg_prompt = value
return prompt, neg_prompt
def load_exif_data(exif_cache):
with transaction() as cursor:
cursor.execute('''
SELECT file, group_concat(
case when key = 'prompt' or key = 'negative_prompt' then key || ': ' || value || '\n'
else key || ': ' || value
end, ', ') AS string
FROM (
SELECT *
FROM exif_data
ORDER BY
CASE WHEN key = 'prompt' THEN 0
WHEN key = 'negative_prompt' THEN 1
ELSE 2 END,
key
)
GROUP BY file
''')
rows = cursor.fetchall()
for row in rows:
exif_cache[row[0]] = row[1]
return exif_cache
def load_exif_data_by_key(cache, key1, key2):
with transaction() as cursor:
cursor.execute('''
SELECT file, value
FROM exif_data
WHERE key IN (?, ?)
''', (key1, key2))
rows = cursor.fetchall()
for row in rows:
cache[row[0]] = row[1]
return cache
def get_exif_dirs():
with transaction() as cursor:
cursor.execute('''
SELECT file
FROM exif_data
''')
rows = cursor.fetchall()
dirs = {}
for row in rows:
dir = os.path.dirname(row[0])
dirs[dir] = dir
return dirs
def fill_work_files(cursor, fileinfos):
filenames = [x[0] for x in fileinfos]
cursor.execute('''
DELETE
FROM work_files
''')
sql = '''
INSERT INTO work_files (file)
VALUES (?)
'''
cursor.executemany(sql, [(x,) for x in filenames])
return
def filter_aes(cursor, fileinfos, aes_filter_min_num, aes_filter_max_num):
key = "aesthetic_score"
cursor.execute('''
DELETE
FROM work_files
WHERE file not in (
SELECT file
FROM exif_data b
WHERE file = b.file
AND b.key = ?
AND CAST(b.value AS REAL) between ? and ?
)
''', (key, aes_filter_min_num, aes_filter_max_num))
cursor.execute('''
SELECT file
FROM work_files
''')
rows = cursor.fetchall()
fileinfos_dict = {pair[0]: pair[1] for pair in fileinfos}
fileinfos_new = []
for (file,) in rows:
if fileinfos_dict.get(file) is not None:
fileinfos_new.append((file, fileinfos_dict[file]))
return fileinfos_new
def filter_ranking(cursor, fileinfos, ranking_filter, ranking_filter_min_num, ranking_filter_max_num):
if ranking_filter == "None":
cursor.execute('''
DELETE
FROM work_files
WHERE file IN (
SELECT file
FROM ranking b
WHERE file = b.file
)
''')
elif ranking_filter == "Min-max":
cursor.execute('''
DELETE
FROM work_files
WHERE file NOT IN (
SELECT file
FROM ranking b
WHERE file = b.file
AND b.ranking BETWEEN ? AND ?
)
''', (ranking_filter_min_num, ranking_filter_max_num))
else:
cursor.execute('''
DELETE
FROM work_files
WHERE file NOT IN (
SELECT file
FROM ranking b
WHERE file = b.file
AND b.ranking = ?
)
''', (ranking_filter,))
cursor.execute('''
SELECT file
FROM work_files
''')
rows = cursor.fetchall()
fileinfos_dict = {pair[0]: pair[1] for pair in fileinfos}
fileinfos_new = []
for (file,) in rows:
if fileinfos_dict.get(file) is not None:
fileinfos_new.append((file, fileinfos_dict[file]))
return fileinfos_new
def select_x_y(cursor, file):
cursor.execute('''
SELECT value
FROM exif_data
WHERE file = ?
AND key = 'Size'
''', (file,))
size_value = cursor.fetchone()
if size_value is None:
x = "?"
y = "?"
else:
(size,) = size_value
parts = size.split("x")
x = parts[0]
y = parts[1]
return x, y |