From bca52c546f6662a9b54efad2ab18cee607865b6b Mon Sep 17 00:00:00 2001 From: Dreu LaVelle Date: Fri, 8 Nov 2024 23:00:10 -0600 Subject: [PATCH] fix: separate anime handler for now --- PTT/__init__.py | 5 +- PTT/anime.py | 225 ++++++++++++++++++++++++++++++++++++++++++++ PTT/handlers.py | 3 +- tests/test_anime.py | 17 +--- tests/test_main.py | 7 ++ 5 files changed, 240 insertions(+), 17 deletions(-) create mode 100644 PTT/anime.py diff --git a/PTT/__init__.py b/PTT/__init__.py index df75c27..970ef11 100644 --- a/PTT/__init__.py +++ b/PTT/__init__.py @@ -1,12 +1,11 @@ from .handlers import add_defaults from .parse import Parser -from .anime import anime_handler _parser = Parser() add_defaults(_parser) -def parse_title(raw_title: str, translate_languages: bool = False, parse_anime: bool = False) -> dict: +def parse_title(raw_title: str, translate_languages: bool = False) -> dict: """ Parse the given input string using the initialized parser instance. @@ -19,8 +18,6 @@ def parse_title(raw_title: str, translate_languages: bool = False, parse_anime: If `parse_anime` is True, the anime handlers will be added to the parser instance. This can add more time to the parsing process. """ - if parse_anime: - anime_handler(_parser) # add anime handlers to the parser instance return _parser.parse(raw_title, translate_languages) diff --git a/PTT/anime.py b/PTT/anime.py new file mode 100644 index 0000000..7397d9f --- /dev/null +++ b/PTT/anime.py @@ -0,0 +1,225 @@ +import regex + +from PTT.parse import Parser +from PTT.transformers import ( + boolean +) + + +def anime_handler(parser: Parser): + """Anime handlers.""" + # Episode Code + parser.add_handler("anime", regex.compile(r"\b\[([A-F0-9]{8})\]\b", regex.IGNORECASE), boolean, {"remove": True}) + + # Anime type check + parser.add_handler("anime", regex.compile(r"\[Yameii\]|-Yameii\b"), boolean, {"remove": False, "skipIfAlreadyFound": True}) + parser.add_handler("anime", regex.compile(r"\[Legion\]|-Legion\b"), boolean, {"remove": False, "skipIfAlreadyFound": True}) + parser.add_handler("anime", regex.compile(r"\[sam\]|-sam\b"), boolean, {"remove": False, "skipIfAlreadyFound": True}) + parser.add_handler("anime", regex.compile(r"\b(LostYears)\b"), boolean, {"remove": False, "skipIfAlreadyFound": True}) + parser.add_handler("anime", regex.compile(r"\[Spark\]|-Spark\b"), boolean, {"remove": False, "skipIfAlreadyFound": True}) + parser.add_handler("anime", regex.compile(r"\b(HorribleRips)\b"), boolean, {"remove": False, "skipIfAlreadyFound": True}) + parser.add_handler("anime", regex.compile(r"\b(HorribleSubs)\b"), boolean, {"remove": False, "skipIfAlreadyFound": True}) + parser.add_handler("anime", regex.compile(r"\[EMBER\]|-EMBER\b"), boolean, {"remove": False, "skipIfAlreadyFound": True}) + parser.add_handler("anime", regex.compile(r"\[Judas\]|-Judas"), boolean, {"remove": False, "skipIfAlreadyFound": True}) + parser.add_handler("anime", regex.compile(r"\[Tsundere\]|-Tsundere(?!-)\b"), boolean, {"remove": False, "skipIfAlreadyFound": True}) + parser.add_handler("anime", regex.compile(r"\b(BlueLobster)\b"), boolean, {"remove": False, "skipIfAlreadyFound": True}) + parser.add_handler("anime", regex.compile(r"\b(Erai-raws)\b"), boolean, {"remove": False, "skipIfAlreadyFound": True}) + parser.add_handler("anime", regex.compile(r"\[GHOST\]|-GHOST\b"), boolean, {"remove": False, "skipIfAlreadyFound": True}) + parser.add_handler("anime", regex.compile(r"\b(?:Ani(?:me|s)|[Аа]ниме)\b"), boolean, {"remove": False, "skipIfAlreadyFound": True}) + parser.add_handler("anime", regex.compile(r"\[Aergia\]|-Aergia(?!-raws)\b"), boolean, {"remove": False, "skipIfAlreadyFound": True}) + parser.add_handler("anime", regex.compile(r"\b(Arg0)\b"), boolean, {"remove": False, "skipIfAlreadyFound": True}) + parser.add_handler("anime", regex.compile(r"\b(LYS1TH3A)\b"), boolean, {"remove": False, "skipIfAlreadyFound": True}) + parser.add_handler("anime", regex.compile(r"\b(OZR)\b"), boolean, {"remove": False, "skipIfAlreadyFound": True}) + parser.add_handler("anime", regex.compile(r"\b(SCY)\b"), boolean, {"remove": False, "skipIfAlreadyFound": True}) + parser.add_handler("anime", regex.compile(r"\[smol\]|-smol\b"), boolean, {"remove": False, "skipIfAlreadyFound": True}) + parser.add_handler("anime", regex.compile(r"\[Vanilla\]|-Vanilla\b"), boolean, {"remove": False, "skipIfAlreadyFound": True}) + parser.add_handler("anime", regex.compile(r"\[Vodes\]|(?