Skip to content

Commit da2a6a8

Browse files
committed
[imhentai] use alternate strategy for galleries without image data (#8951)
1 parent 71680fe commit da2a6a8

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

gallery_dl/extractor/imhentai.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,18 +123,29 @@ def _split(self, html):
123123
return results
124124

125125
def images(self, page):
126+
base = text.extr(page, 'data-src="', '"').rpartition("/")[0] + "/"
127+
exts = {"j": "jpg", "p": "png", "g": "gif", "w": "webp", "a": "avif"}
128+
126129
try:
127130
data = util.json_loads(text.extr(page, "$.parseJSON('", "'"))
128131
except Exception:
132+
data = None
133+
134+
if data is None:
129135
self.log.warning("%s: Missing image data", self.gallery_id)
130-
return ()
131-
base = text.extr(page, 'data-src="', '"').rpartition("/")[0] + "/"
132-
exts = {"j": "jpg", "p": "png", "g": "gif", "w": "webp", "a": "avif"}
136+
137+
def _fallback_exts(i):
138+
for ext in util.advance(exts.values(), 1):
139+
yield f"{base}{i}.{ext}"
140+
cnt = text.parse_int(text.extr(
141+
page, 'id="load_pages" value="', '"'))
142+
return [(f"{base}{i}.jpg", {"_fallback": _fallback_exts(i)})
143+
for i in range(1, cnt+1)]
133144

134145
results = []
135146
for i in map(str, range(1, len(data)+1)):
136147
ext, width, height = data[i].split(",")
137-
url = base + i + "." + exts[ext]
148+
url = f"{base}{i}.{exts[ext]}"
138149
results.append((url, {
139150
"width" : text.parse_int(width),
140151
"height": text.parse_int(height),

0 commit comments

Comments
 (0)