From 83d99f4585ce727a19c6d9b1aa70f2ad103cc387 Mon Sep 17 00:00:00 2001 From: xenofem Date: Tue, 6 Feb 2024 09:26:39 -0500 Subject: [PATCH] smarter automatic collation of textless versions --- dlibrary/dlibrary.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/dlibrary/dlibrary.py b/dlibrary/dlibrary.py index 9952429..7d100df 100755 --- a/dlibrary/dlibrary.py +++ b/dlibrary/dlibrary.py @@ -24,6 +24,8 @@ DLSITE_ID_REGEX = re.compile('^[BR]J[0-9]+$') FANZA_ID_REGEX = re.compile('^d_[0-9]+$') FAKKU_ID_REGEX = re.compile('.*_FAKKU$') +TEXTLESS_REGEX = re.compile('(台詞|セリフ)(な|無)し|notext|textless') + IMAGE_FILE_EXTENSIONS = ['.png', '.jpg', '.jpeg', '.gif', '.tiff'] IGNOREABLE_FILES = ['Thumbs.db', '__MACOSX', '.DS_Store'] @@ -191,6 +193,9 @@ def link_pdf(src, dest, start_index=0): f.write(image["image"]) def complete_prefix_number_ordering(entries): + if len(entries) == 1: + return entries + matches = reversed(list(NUMBER_REGEX.finditer(entries[0].name))) for m in matches: pos = m.start() @@ -266,6 +271,19 @@ def collate(args): if all(entry.is_file() and entry.suffix.lower() in IMAGE_FILE_EXTENSIONS for entry in entries): ordering = complete_prefix_number_ordering(entries) + if not ordering: + with_text = [] + textless = [] + for entry in entries: + if TEXTLESS_REGEX.search(entry.name): + textless.append(entry) + else: + with_text.append(entry) + if with_text and textless: + with_text_ordering = complete_prefix_number_ordering(with_text) + textless_ordering = complete_prefix_number_ordering(textless) + if with_text_ordering and textless_ordering: + ordering = with_text_ordering + textless_ordering if ordering: print(f'Symlinking image files for {work_id}') link_ordered_files(ordering, collation_dir)