cleaner handling of better/worse image quality versions

This commit is contained in:
xenofem 2024-02-20 17:23:33 -05:00
parent 1457168951
commit 15410ca8ba

View file

@ -28,7 +28,15 @@ FANZA_ID_REGEX = re.compile('^d_[0-9]+$')
FAKKU_ID_REGEX = re.compile('.*_FAKKU$')
HI_RES_REGEX = re.compile('高解像度', re.IGNORECASE)
NO_TONE_REGEX = re.compile('トーン.*[な無]し|グレースケール')
NO_TONE_REGEX = re.compile('トーン(効果)?[な無]し|グレースケール', re.IGNORECASE)
TONE_REGEX = re.compile('トーン(版|(効果)?[有あ]り)', re.IGNORECASE)
COLOR_REGEX = re.compile('カラー', re.IGNORECASE)
MONOCHROME_REGEX = re.compile('モノクロ', re.IGNORECASE)
IMAGE_QUALITY_REGEXES = [
{ 'better': HI_RES_REGEX },
{ 'better': NO_TONE_REGEX, 'worse': TONE_REGEX },
{ 'better': COLOR_REGEX, 'worse': MONOCHROME_REGEX },
]
TEXTLESS_REGEX = re.compile('(台詞|セリフ|せりふ|テキスト|文字)((な|無)し|抜き)|notext|textless', re.IGNORECASE)
FRONT_COVER_REGEX = re.compile('(^|[^裏])表紙|cover|hyoushi', re.IGNORECASE)
@ -556,12 +564,19 @@ def collate_from_paths(srcs, dest, start_index, exclude):
return 0
if len(srcs) == 2 and all(src.is_dir() for src in srcs):
better_version_dirs = [src for src in srcs if HI_RES_REGEX.search(nname(src)) or NO_TONE_REGEX.search(nname(src))]
if len(better_version_dirs) == 1:
better_version_dir = better_version_dirs[0]
worse_version_dir = next(src for src in srcs if src != better_version_dir)
if len(descendant_files_ignore(worse_version_dir, exclude)) == len(descendant_files_ignore(better_version_dir, exclude)):
return collate_from_paths([better_version_dir], dest, start_index, exclude)
for quality in IMAGE_QUALITY_REGEXES:
def a_not_b(a, b, src):
if a in quality:
return quality[a].search(nname(src))
else:
return not quality[b].search(nname(src))
better_srcs = [src for src in srcs if a_not_b('better', 'worse', src)]
worse_srcs = [src for src in srcs if a_not_b('worse', 'better', src)]
if len(better_srcs) == 1 and len(worse_srcs) == 1 and better_srcs[0] != worse_srcs[0]:
better = better_srcs[0]
worse = worse_srcs[0]
if len(descendant_files_ignore(better, exclude)) == len(descendant_files_ignore(worse, exclude)):
return collate_from_paths([better], dest, start_index, exclude)
images_vs_pdf = try_collate_images_vs_pdf(srcs, dest, start_index, exclude)
if images_vs_pdf != False: