handle combinations of versions, and cases where things have versions but not numbers

This commit is contained in:
xenofem 2024-02-06 13:20:56 -05:00
parent 85ac6bc35c
commit 26af5286dc

View file

@ -26,7 +26,7 @@ FAKKU_ID_REGEX = re.compile('.*_FAKKU$')
TEXTLESS_REGEX = re.compile('(台詞|セリフ)(な|無)し|notext|textless') TEXTLESS_REGEX = re.compile('(台詞|セリフ)(な|無)し|notext|textless')
EPILOGUE_REGEX = re.compile('after|後日談') EPILOGUE_REGEX = re.compile('after|後日談')
ALT_VERSIONS = ['褐色', '日焼け', 'pink', '金髪', '白肌'] ALT_VERSIONS = ['褐色', '日焼け', 'pink', '金髪', '白肌', 'うつろ目']
IMAGE_FILE_EXTENSIONS = ['.png', '.jpg', '.jpeg', '.gif', '.tiff'] IMAGE_FILE_EXTENSIONS = ['.png', '.jpg', '.jpeg', '.gif', '.tiff']
@ -202,8 +202,11 @@ def complete_prefix_number_ordering(entries):
entries_by_version = {} entries_by_version = {}
for entry in entries: for entry in entries:
version = next(ver for ver in (ALT_VERSIONS + ['']) if ver in entry.name) version_code = 0
entries_by_version.setdefault(version, []).append(entry) 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} 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: if numbering is None:
return None return None
unified_indices |= set(numbering.keys()) unified_indices |= set(numbering.keys())
unified_indices.discard(None)
unified_indices = list(unified_indices) unified_indices = list(unified_indices)
unified_indices.sort() unified_indices.sort()
@ -225,6 +229,8 @@ def complete_prefix_number_ordering(entries):
return None return None
break break
unified_indices.append(None)
versions = list(numberings_by_version.keys()) versions = list(numberings_by_version.keys())
versions.sort() versions.sort()
@ -245,6 +251,9 @@ def complete_prefix_number_ordering(entries):
return result return result
def unique_hierarchical_prefix_numbering(entries, start_point=0): 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)) longest_entry = max(entries, key=lambda e: len(e.name))
matches = reversed(list(NUMBER_REGEX.finditer(longest_entry.name))) matches = reversed(list(NUMBER_REGEX.finditer(longest_entry.name)))
for m in matches: for m in matches: