diff --git a/comicfn2dict/parse.py b/comicfn2dict/parse.py index 3783fc6..2dd0f19 100644 --- a/comicfn2dict/parse.py +++ b/comicfn2dict/parse.py @@ -77,27 +77,9 @@ class ComicFilenameParser: value = value.strip("'").strip() return value.strip('"').strip() - def _parenthify_double_underscores(self) -> str: - """Replace double underscores with parens.""" - parts = self._unparsed_path.split("__") - num_parts = len(parts) - print(f"{num_parts=} {num_parts % 2}") - if num_parts < 3 or not num_parts % 2: - return self._unparsed_path - index = 0 - mode = " (" - parenthified = parts[index] - index += 1 - while index < len(parts): - parenthified += mode + parts[index] - print(f"{parenthified=}") - mode = ") " if mode == " (" else ") " - index += 1 - return parenthified.strip() - def _clean_dividers(self): """Replace non space dividers and clean extra spaces out of string.""" - data = self._parenthify_double_underscores() + data = self._unparsed_path # Simple substitutions for regex, pair in REGEX_SUBS.items(): diff --git a/comicfn2dict/regex.py b/comicfn2dict/regex.py index f9a456e..c17ecd8 100644 --- a/comicfn2dict/regex.py +++ b/comicfn2dict/regex.py @@ -86,8 +86,10 @@ _SPACE_EQUIVALENT_RE = re_compile(r"_") _EXTRA_SPACES_RE = re_compile(r"\s\s+") _LEFT_PAREN_EQUIVALENT_RE = re_compile(r"\[") _RIGHT_PAREN_EQUIVALENT_RE = re_compile(r"\]") +_DOUBLE_UNDERSCORE_RE = re_compile(r"__(.*)__") REGEX_SUBS: MappingProxyType[re.Pattern, tuple[str, int]] = MappingProxyType( { + _DOUBLE_UNDERSCORE_RE: (r"(\1)", 0), _TOKEN_DIVIDERS_RE: (TOKEN_DELIMETER, 1), _SPACE_EQUIVALENT_RE: (r" ", 0), _EXTRA_SPACES_RE: (r" ", 0),