From 26af5286dcf06f1a0eb2d771097fce614de37758 Mon Sep 17 00:00:00 2001 From: xenofem Date: Tue, 6 Feb 2024 13:20:56 -0500 Subject: [PATCH] handle combinations of versions, and cases where things have versions but not numbers --- dlibrary/dlibrary.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/dlibrary/dlibrary.py b/dlibrary/dlibrary.py index 4e2eea6..8dee4bd 100755 --- a/dlibrary/dlibrary.py +++ b/dlibrary/dlibrary.py @@ -26,7 +26,7 @@ FAKKU_ID_REGEX = re.compile('.*_FAKKU$') TEXTLESS_REGEX = re.compile('(台詞|セリフ)(な|無)し|notext|textless') EPILOGUE_REGEX = re.compile('after|後日談') -ALT_VERSIONS = ['褐色', '日焼け', 'pink', '金髪', '白肌'] +ALT_VERSIONS = ['褐色', '日焼け', 'pink', '金髪', '白肌', 'うつろ目'] IMAGE_FILE_EXTENSIONS = ['.png', '.jpg', '.jpeg', '.gif', '.tiff'] @@ -202,8 +202,11 @@ def complete_prefix_number_ordering(entries): entries_by_version = {} for entry in entries: - version = next(ver for ver in (ALT_VERSIONS + ['']) if ver in entry.name) - entries_by_version.setdefault(version, []).append(entry) + version_code = 0 + for (i, version) in enumerate(ALT_VERSIONS): + if version in entry.name: + version_code |= (1 << i) + entries_by_version.setdefault(version_code, []).append(entry) numberings_by_version = {ver: unique_hierarchical_prefix_numbering(entries_by_version[ver]) for ver in entries_by_version} @@ -212,6 +215,7 @@ def complete_prefix_number_ordering(entries): if numbering is None: return None unified_indices |= set(numbering.keys()) + unified_indices.discard(None) unified_indices = list(unified_indices) unified_indices.sort() @@ -225,6 +229,8 @@ def complete_prefix_number_ordering(entries): return None break + unified_indices.append(None) + versions = list(numberings_by_version.keys()) versions.sort() @@ -245,6 +251,9 @@ def complete_prefix_number_ordering(entries): return result def unique_hierarchical_prefix_numbering(entries, start_point=0): + if len(entries) == 1 and not NUMBER_REGEX.search(entries[0].name): + return {None: entries} + longest_entry = max(entries, key=lambda e: len(e.name)) matches = reversed(list(NUMBER_REGEX.finditer(longest_entry.name))) for m in matches: