From e1613fc0f419404d256862c8f3f0d1dfe889a1aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Fri, 6 Dec 2024 22:12:08 +0100 Subject: [PATCH] [nhentai] select random file servers for download URLs (#6620) i1, i2, i3, i4 instead of just i.nhentai.net --- gallery_dl/extractor/nhentai.py | 16 ++++++++++------ test/results/nhentai.py | 13 +++++++------ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/gallery_dl/extractor/nhentai.py b/gallery_dl/extractor/nhentai.py index 90c5420f..0d656d04 100644 --- a/gallery_dl/extractor/nhentai.py +++ b/gallery_dl/extractor/nhentai.py @@ -11,6 +11,7 @@ from .common import GalleryExtractor, Extractor, Message from .. import text, util import collections +import random class NhentaiGalleryExtractor(GalleryExtractor): @@ -59,15 +60,18 @@ class NhentaiGalleryExtractor(GalleryExtractor): } def images(self, _): - ufmt = ("https://i.nhentai.net/galleries/" + - self.data["media_id"] + "/{}.{}") - extdict = {"j": "jpg", "p": "png", "g": "gif", "w": "webp"} + exts = {"j": "jpg", "p": "png", "g": "gif", "w": "webp", "a": "avif"} + + data = self.data + ufmt = ("https://i{}.nhentai.net/galleries/" + + data["media_id"] + "/{}.{}").format return [ - (ufmt.format(num, extdict.get(img["t"], "jpg")), { - "width": img["w"], "height": img["h"], + (ufmt(random.randint(1, 4), num, exts.get(img["t"], "jpg")), { + "width" : img["w"], + "height": img["h"], }) - for num, img in enumerate(self.data["images"]["pages"], 1) + for num, img in enumerate(data["images"]["pages"], 1) ] diff --git a/test/results/nhentai.py b/test/results/nhentai.py index 02667ac4..e10d8679 100644 --- a/test/results/nhentai.py +++ b/test/results/nhentai.py @@ -12,7 +12,8 @@ __tests__ = ( "#url" : "https://nhentai.net/g/147850/", "#category": ("", "nhentai", "gallery"), "#class" : nhentai.NhentaiGalleryExtractor, - "#sha1_url": "5179dbf0f96af44005a0ff705a0ad64ac26547d0", + "#pattern" : r"https://i[1-4]\.nhentai\.net/galleries/867789/\d+\.jpg", + "#count" : 16, "title" : r"re:\[Morris\] Amazon no Hiyaku \| Amazon Elixir", "title_en" : str, @@ -39,11 +40,11 @@ __tests__ = ( "#comment" : "webp (#6442)", "#class" : nhentai.NhentaiGalleryExtractor, "#range" : "4-7", - "#urls" : ( - "https://i.nhentai.net/galleries/3115523/4.jpg", - "https://i.nhentai.net/galleries/3115523/5.webp", - "https://i.nhentai.net/galleries/3115523/6.webp", - "https://i.nhentai.net/galleries/3115523/7.jpg", + "#pattern" : ( + r"https://i\d\.nhentai.net/galleries/3115523/4\.jpg", + r"https://i\d\.nhentai.net/galleries/3115523/5\.webp", + r"https://i\d\.nhentai.net/galleries/3115523/6\.webp", + r"https://i\d\.nhentai.net/galleries/3115523/7\.jpg", ), },