From 2ab99c9a4b61764667b16b1d2b5f33091da0117c Mon Sep 17 00:00:00 2001 From: xenofem Date: Mon, 22 Jan 2024 07:56:45 -0500 Subject: [PATCH] don't get tripped up as much by random extra files during collation --- dlibrary.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/dlibrary.py b/dlibrary.py index cccf5e1..2e5019c 100755 --- a/dlibrary.py +++ b/dlibrary.py @@ -19,6 +19,9 @@ NUMBER_REGEX = re.compile('[0-9]+') IMAGE_FILE_EXTENSIONS = ['.png', '.jpg', '.jpeg', '.gif', '.tiff'] +IGNOREABLE_FILES = ['Thumbs.db', '__MACOSX', '.DS_Store'] +IGNOREABLE_EXTENSIONS = ['.txt', '.html', '.htm'] + def open_zipfile_with_encoding(path): try: return zipfile.ZipFile(path, metadata_encoding="utf-8") @@ -151,6 +154,12 @@ def link_ordered_files(ordering, dest, start_index=0): link_path = dest / f'{idx:04d}{ext}' link_path.symlink_to(relpath(src_path, dest)) +def ls_ignore(directory): + return [ + path for path in directory.iterdir() + if path.name not in IGNOREABLE_FILES and path.suffix.lower() not in IGNOREABLE_EXTENSIONS + ] + def collate(args): con = sqlite3.connect(args.destdir / 'meta.db') cur = con.cursor() @@ -171,11 +180,11 @@ def collate(args): if work_id in hint_map: hint = hint_map[work_id] - entries = list(hint.iterdir()) if hint.is_dir() else [hint] + entries = ls_ignore(hint) if hint.is_dir() else [hint] else: search_dir = work_path while True: - entries = list(search_dir.iterdir()) + entries = ls_ignore(search_dir) if len(entries) == 1 and entries[0].is_dir(): search_dir = entries[0] else: