diff --git a/dlibrary/dlibrary.py b/dlibrary/dlibrary.py index ebeb216..223ed45 100755 --- a/dlibrary/dlibrary.py +++ b/dlibrary/dlibrary.py @@ -32,8 +32,6 @@ import requests NUMBER_REGEX = re.compile('[0-90-9]+') ALPHABETIC_NUMBERING_REGEX = re.compile('^(?P[^a-za-z0-90-9]*)((?P[a-za-z])(?P[^a-za-z0-90-9]*))?$', re.I) -EXTRA_NORMALIZATION_TABLE = str.maketrans({'\u301c': '\uff5e'}) - DLSITE_ID_REGEX = re.compile('^[BR]J[0-9]+$') FANZA_ID_REGEX = re.compile('^d_[0-9]+$') FAKKU_ID_REGEX = re.compile('.*_FAKKU$') @@ -482,10 +480,6 @@ class Collator: if len(srcs) == 0: return True - if all(src.is_dir() and nname(src) == nname(srcs[0]) for src in srcs): - debug(f'Merging unicode-fucked directories for {srcs[0]}') - return self.collate_from_paths([item for src in srcs for item in ls_ignore(src, self.exclude)]) - debug(f'Auto-collating {srcs}') select_language = self.try_collate_select_language(srcs) @@ -802,14 +796,11 @@ def pdf_image_extractors(pdf, strategy): return image_extractors -def normalize_string(s): - return unicodedata.normalize('NFKC', s.translate(EXTRA_NORMALIZATION_TABLE)) +def nfc(s): + return unicodedata.normalize('NFC', s) def nname(entry): - return normalize_string(entry.name) - -def nstem(entry): - return normalize_string(entry.stem) + return nfc(entry.name) def complete_prefix_number_ordering(entries): if len(entries) == 1: @@ -878,13 +869,13 @@ def unique_hierarchical_prefix_numbering(entries, start_point=0): for m in matches: pos = m.start() if pos < start_point: - break + return None prefix = nname(longest_entry)[:pos] debug(f'Checking prefix {prefix}') - if all(nname(e).startswith(prefix) or prefix.startswith(nstem(e)) for e in entries): + if all(nname(e).startswith(prefix) or prefix.startswith(nfc(e.stem)) for e in entries): numbering = {} for e in entries: - if pos >= len(nstem(e)): + if pos >= len(nfc(e.stem)): i = 0 else: n = NUMBER_REGEX.match(nname(e)[pos:]) @@ -918,7 +909,7 @@ def alphabetic_numbering(entries, start_point): alphabetized = {} prefix_suffix = None for entry in entries: - ending = nstem(entry)[start_point:] + ending = nfc(entry.stem)[start_point:] debug(f'{entry} has ending {ending}') ending_match = ALPHABETIC_NUMBERING_REGEX.fullmatch(ending)