summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorWolfgang Müller2024-11-15 14:20:46 +0100
committerWolfgang Müller2024-11-15 14:20:46 +0100
commite93aaec29b8b572ca4cbb6ed5fda79af1495ea08 (patch)
tree44ccf11519336bb6fb5398ae6392601cc93cd76a /src
parent33cff31a4927dc2f36b8e1327bf0786f0676d5c1 (diff)
downloadhircine-e93aaec29b8b572ca4cbb6ed5fda79af1495ea08.tar.gz
backend/plugins: Have E-Hentai raise an error from status_code early
This makes the code clearer and saves a whole indentation level.
Diffstat (limited to 'src')
-rw-r--r--src/hircine/plugins/scrapers/ehentai_api.py38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/hircine/plugins/scrapers/ehentai_api.py b/src/hircine/plugins/scrapers/ehentai_api.py
index 86b6cfa..e34d80c 100644
--- a/src/hircine/plugins/scrapers/ehentai_api.py
+++ b/src/hircine/plugins/scrapers/ehentai_api.py
@@ -55,23 +55,23 @@ class EHentaiAPIScraper(Scraper):
request = requests.post(API_URL, data=data)
- if request.status_code == requests.codes.ok:
- try:
- response = json.loads(request.text)["gmetadata"][0]
- except json.JSONDecodeError as err:
- raise ScrapeError("Could not parse JSON response") from err
- except (KeyError, IndexError) as err:
- raise ScrapeError("Response is missing 'gmetadata' field") from err
-
- title = response.get("title")
- if title:
- response["title"] = html.unescape(title)
-
- title_jpn = response.get("title_jpn")
- if title_jpn:
- response["title_jpn"] = html.unescape(title_jpn)
-
- handler = ExHentaiHandler()
- yield from handler.scrape(response)
- else:
+ if request.status_code != requests.codes.ok:
raise ScrapeError(f"Request failed with status code {request.status_code}")
+
+ try:
+ response = json.loads(request.text)["gmetadata"][0]
+ except json.JSONDecodeError as err:
+ raise ScrapeError("Could not parse JSON response") from err
+ except (KeyError, IndexError) as err:
+ raise ScrapeError("Response is missing 'gmetadata' field") from err
+
+ title = response.get("title")
+ if title:
+ response["title"] = html.unescape(title)
+
+ title_jpn = response.get("title_jpn")
+ if title_jpn:
+ response["title_jpn"] = html.unescape(title_jpn)
+
+ handler = ExHentaiHandler()
+ yield from handler.scrape(response)