diff options
author | Wolfgang Müller | 2024-11-14 23:28:21 +0100 |
---|---|---|
committer | Wolfgang Müller | 2024-11-14 23:28:21 +0100 |
commit | 6a138ebe25d4d22e35a10cdf1b90c9b40aa224b7 (patch) | |
tree | 65f1fd5f7553dabcb18d33d172d0dfb3b7f444a7 | |
parent | a495162ab6d0bf324c300eca398532ee397cf9a1 (diff) | |
download | hircine-6a138ebe25d4d22e35a10cdf1b90c9b40aa224b7.tar.gz |
backend/plugins: Use language parser from scraper utils
Now that we have this in our utility suite, we can make use of it in the
built-in scraper plugins. This increases coverage and removes a lot of
duplicate code.
-rw-r--r-- | src/hircine/plugins/scrapers/handlers/dynastyscans.py | 10 | ||||
-rw-r--r-- | src/hircine/plugins/scrapers/handlers/e621.py | 6 | ||||
-rw-r--r-- | src/hircine/plugins/scrapers/handlers/exhentai.py | 11 | ||||
-rw-r--r-- | src/hircine/plugins/scrapers/handlers/mangadex.py | 10 |
4 files changed, 5 insertions, 32 deletions
diff --git a/src/hircine/plugins/scrapers/handlers/dynastyscans.py b/src/hircine/plugins/scrapers/handlers/dynastyscans.py index ded015b..fd9bf42 100644 --- a/src/hircine/plugins/scrapers/handlers/dynastyscans.py +++ b/src/hircine/plugins/scrapers/handlers/dynastyscans.py @@ -1,5 +1,3 @@ -import hircine.enums as enums -from hircine.scraper import ScrapeWarning from hircine.scraper.types import ( Artist, Circle, @@ -16,7 +14,7 @@ class DynastyScansHandler: def scrape(self, data): parsers = { "date": Date.from_iso, - "lang": self.parse_language, + "lang": Language.from_iso_639_3, "author": Artist, "group": Circle, } @@ -33,9 +31,3 @@ class DynastyScansHandler: title = title + f": {subtitle}" yield Title(title) - - def parse_language(self, input): - try: - return Language(value=enums.Language[input.upper()]) - except (KeyError, ValueError) as e: - raise ScrapeWarning(f"Could not parse language: '{input}'") from e diff --git a/src/hircine/plugins/scrapers/handlers/e621.py b/src/hircine/plugins/scrapers/handlers/e621.py index 6b798fd..b7cd83a 100644 --- a/src/hircine/plugins/scrapers/handlers/e621.py +++ b/src/hircine/plugins/scrapers/handlers/e621.py @@ -1,5 +1,4 @@ import hircine.enums as enums -from hircine.scraper import ScrapeWarning from hircine.scraper.types import ( URL, Artist, @@ -75,7 +74,4 @@ class E621Handler: if input.endswith("_text"): lang, _ = input.split("_text", 1) - try: - return Language(value=enums.Language(lang.capitalize())) - except ValueError as e: - raise ScrapeWarning(f"Could not parse language: '{input}'") from e + return Language.from_name(lang) diff --git a/src/hircine/plugins/scrapers/handlers/exhentai.py b/src/hircine/plugins/scrapers/handlers/exhentai.py index 12c22d7..33733be 100644 --- a/src/hircine/plugins/scrapers/handlers/exhentai.py +++ b/src/hircine/plugins/scrapers/handlers/exhentai.py @@ -1,7 +1,6 @@ import re import hircine.enums as enums -from hircine.scraper import ScrapeWarning from hircine.scraper.types import ( URL, Artist, @@ -39,7 +38,7 @@ class ExHentaiHandler: category_field: self.parse_category, "posted": Date.from_timestamp, "date": Date.from_iso, - "lang": self.parse_language, + "lang": Language.from_iso_639_3, "tags": self.parse_tag, "title": lambda t: Title(sanitize(t, split=True)), "title_jpn": lambda t: OriginalTitle(sanitize(t)), @@ -130,10 +129,4 @@ class ExHentaiHandler: if not input or input in ["translated", "speechless", "N/A"]: return - try: - if from_value: - return Language(value=enums.Language(input.capitalize())) - else: - return Language(value=enums.Language[input.upper()]) - except (KeyError, ValueError) as e: - raise ScrapeWarning(f"Could not parse language: '{input}'") from e + return Language.from_name(input) diff --git a/src/hircine/plugins/scrapers/handlers/mangadex.py b/src/hircine/plugins/scrapers/handlers/mangadex.py index bb93538..4a8d5fd 100644 --- a/src/hircine/plugins/scrapers/handlers/mangadex.py +++ b/src/hircine/plugins/scrapers/handlers/mangadex.py @@ -1,5 +1,3 @@ -import hircine.enums as enums -from hircine.scraper import ScrapeWarning from hircine.scraper.types import ( URL, Artist, @@ -18,7 +16,7 @@ class MangadexHandler: def scrape(self, data): parsers = { "date": Date.from_iso, - "lang": self.parse_language, + "lang": Language.from_iso_639_3, "tags": Tag.from_string, "artist": Artist, "author": Artist, @@ -46,9 +44,3 @@ class MangadexHandler: title = title + f": {subtitle}" yield Title(title) - - def parse_language(self, input): - try: - return Language(value=enums.Language[input.upper()]) - except (KeyError, ValueError) as e: - raise ScrapeWarning(f"Could not parse language: '{input}'") from e |