From f5c6a2d7f54aa9eda00a07419d08b1f4ac878f28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Wed, 21 Mar 2018 12:37:46 +0100 Subject: [PATCH] [nhentai] use API to get gallery info --- gallery_dl/extractor/mangapark.py | 4 ++-- gallery_dl/extractor/nhentai.py | 25 +++++++------------------ test/test_results.py | 2 +- 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/gallery_dl/extractor/mangapark.py b/gallery_dl/extractor/mangapark.py index 690f8db4..4752d1f5 100644 --- a/gallery_dl/extractor/mangapark.py +++ b/gallery_dl/extractor/mangapark.py @@ -80,11 +80,11 @@ class MangaparkChapterExtractor(MangaparkExtractor, ChapterExtractor): (("https://mangapark.me/manga/" "ad-astra-per-aspera-hata-kenjirou/s5/c1.2"), { "count": 40, - "keyword": "fb5082bb60e19cae0a194b89f69f333888a9325d", + "keyword": "f7f7fb1ca8b26a59a47d8ec60c5eaaf69a43a3f6", }), ("https://mangapark.me/manga/gekkan-shoujo-nozaki-kun/s2/c70/e2/1", { "count": 15, - "keyword": "dc9233cdd83d8659300f0a20ec3c493873f71741", + "keyword": "8d5d1608d4182495ea43ad665e25b755b6468be2", }), ] diff --git a/gallery_dl/extractor/nhentai.py b/gallery_dl/extractor/nhentai.py index 82020442..ce7fdf31 100644 --- a/gallery_dl/extractor/nhentai.py +++ b/gallery_dl/extractor/nhentai.py @@ -9,8 +9,6 @@ """Extract images from https://nhentai.net/""" from .common import Extractor, Message -from .. import text -import json class NhentaiGalleryExtractor(Extractor): @@ -21,9 +19,9 @@ class NhentaiGalleryExtractor(Extractor): filename_fmt = "{category}_{gallery_id}_{num:>03}.{extension}" archive_fmt = "{gallery_id}_{num}" pattern = [r"(?:https?://)?(?:www\.)?nhentai\.net/g/(\d+)"] - test = [("http://nhentai.net/g/147850/", { + test = [("https://nhentai.net/g/147850/", { "url": "5179dbf0f96af44005a0ff705a0ad64ac26547d0", - "keyword": "82751294e75fc203b019ffd94d8c1f94a5b86494", + "keyword": "2f94976e657f3043a89997e22f4de8e1b22d9175", })] def __init__(self, match): @@ -33,8 +31,8 @@ class NhentaiGalleryExtractor(Extractor): def items(self): ginfo = self.get_gallery_info() data = self.get_job_metadata(ginfo) - urlfmt = "{}galleries/{}/{{}}.{{}}".format( - ginfo["media_url"], data["media_id"]) + urlfmt = "https://i.nhentai.net/galleries/{}/{{}}.{{}}".format( + data["media_id"]) extdict = {"j": "jpg", "p": "png", "g": "gif"} yield Message.Version, 1 yield Message.Directory, data @@ -47,24 +45,15 @@ class NhentaiGalleryExtractor(Extractor): def get_gallery_info(self): """Extract and return gallery-info""" - page = self.request("https://nhentai.net/g/" + self.gid + "/1/").text - media_url, pos = text.extract( - page, "media_url: '", "'") - json_data, pos = text.extract( - page, "gallery: ", ",\n", pos) - if json_data.startswith("b'"): - json_data = json_data[2:-1].replace(r"\\u", r"\u") - - json_dict = json.loads(json_data) - json_dict["media_url"] = media_url - return json_dict + url = "https://nhentai.net/api/gallery/" + self.gid + return self.request(url).json() def get_job_metadata(self, ginfo): """Collect metadata for extractor-job""" title_en = ginfo["title"].get("english", "") title_ja = ginfo["title"].get("japanese", "") return { - "gallery_id": self.gid, + "gallery_id": ginfo["id"], "upload_date": ginfo["upload_date"], "media_id": ginfo["media_id"], "scanlator": ginfo["scanlator"], diff --git a/test/test_results.py b/test/test_results.py index 3962d689..d1b5514a 100644 --- a/test/test_results.py +++ b/test/test_results.py @@ -21,7 +21,7 @@ TRAVIS_SKIP = { # temporary issues, etc. BROKEN = { - "mangapark", + "mangahere", # invalid SSL cert "puremashiro", # online reader down }