Skip to content

Commit

Permalink
merge #6865: [lofter] improve error handling
Browse files Browse the repository at this point in the history
- Add 'NotFoundError' when the lofter blog returns a 404
- Stop extractor if the blog is empty, because this returns
  {offset: -1} in the data which previously infinity-looped
  the extractor.
- Prevent errors when the blog is locked, the posts in
  self.posts() are None
  • Loading branch information
mikf committed Jan 21, 2025
2 parents 4d609e2 + b05fa66 commit 783cb83
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions gallery_dl/extractor/lofter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def _init(self):

def items(self):
for post in self.posts():
if post is None:
continue
if "post" in post:
post = post["post"]

Expand Down Expand Up @@ -129,6 +131,9 @@ def _call(self, endpoint, data):
url, method="POST", params=params, data=data)
info = response.json()

if info["meta"]["status"] == 4200:
raise exception.NotFoundError("blog")

if info["meta"]["status"] != 200:
self.extractor.log.debug("Server response: %s", info)
raise exception.StopExtraction("API request failed")
Expand All @@ -142,6 +147,9 @@ def _pagination(self, endpoint, params):

yield from posts

if data["offset"] < 0:
break

if params["offset"] + len(posts) < data["offset"]:
break
params["offset"] = data["offset"]

0 comments on commit 783cb83

Please sign in to comment.