2015-10-28 12:08:27 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2021-09-02 17:40:41 +02:00
|
|
|
# Copyright 2015-2021 Mike Fährmann
|
2015-10-28 12:08:27 +01:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License version 2 as
|
|
|
|
# published by the Free Software Foundation.
|
|
|
|
|
2021-09-02 17:40:41 +02:00
|
|
|
"""Extractors for https://nhentai.net/"""
|
2015-10-28 12:08:27 +01:00
|
|
|
|
2019-02-27 16:54:25 +01:00
|
|
|
from .common import GalleryExtractor, Extractor, Message
|
|
|
|
from .. import text, util
|
|
|
|
import collections
|
2019-01-14 07:51:05 +01:00
|
|
|
import json
|
2015-10-28 12:08:27 +01:00
|
|
|
|
2017-02-01 00:53:19 +01:00
|
|
|
|
2021-10-14 16:45:53 +02:00
|
|
|
class NhentaiGalleryExtractor(GalleryExtractor):
|
|
|
|
"""Extractor for image galleries from nhentai.net"""
|
2015-11-21 04:26:30 +01:00
|
|
|
category = "nhentai"
|
2018-03-28 17:21:44 +02:00
|
|
|
root = "https://nhentai.net"
|
2021-09-02 17:40:41 +02:00
|
|
|
pattern = r"(?:https?://)?nhentai\.net/g/(\d+)"
|
2019-02-08 13:45:40 +01:00
|
|
|
test = ("https://nhentai.net/g/147850/", {
|
2017-01-27 22:43:50 +01:00
|
|
|
"url": "5179dbf0f96af44005a0ff705a0ad64ac26547d0",
|
2019-02-27 16:54:25 +01:00
|
|
|
"keyword": {
|
|
|
|
"title" : r"re:\[Morris\] Amazon no Hiyaku \| Amazon Elixir",
|
|
|
|
"title_en" : str,
|
|
|
|
"title_ja" : str,
|
|
|
|
"gallery_id": 147850,
|
|
|
|
"media_id" : 867789,
|
2019-03-01 23:13:40 +01:00
|
|
|
"count" : 16,
|
2019-02-27 16:54:25 +01:00
|
|
|
"date" : 1446050915,
|
|
|
|
"scanlator" : "",
|
|
|
|
"artist" : ["morris"],
|
|
|
|
"group" : list,
|
|
|
|
"parody" : list,
|
|
|
|
"characters": list,
|
|
|
|
"tags" : list,
|
|
|
|
"type" : "manga",
|
|
|
|
"lang" : "en",
|
2019-03-01 23:13:40 +01:00
|
|
|
"language" : "English",
|
2019-02-27 16:54:25 +01:00
|
|
|
"width" : int,
|
|
|
|
"height" : int,
|
|
|
|
},
|
2019-02-08 13:45:40 +01:00
|
|
|
})
|
2015-11-21 04:26:30 +01:00
|
|
|
|
2015-10-28 12:08:27 +01:00
|
|
|
def __init__(self, match):
|
2021-09-02 17:40:41 +02:00
|
|
|
url = self.root + "/api/gallery/" + match.group(1)
|
|
|
|
GalleryExtractor.__init__(self, match, url)
|
2015-10-28 12:08:27 +01:00
|
|
|
|
2019-02-27 16:54:25 +01:00
|
|
|
def metadata(self, page):
|
2021-09-02 17:40:41 +02:00
|
|
|
self.data = data = json.loads(page)
|
2019-02-27 16:54:25 +01:00
|
|
|
|
|
|
|
title_en = data["title"].get("english", "")
|
|
|
|
title_ja = data["title"].get("japanese", "")
|
|
|
|
|
|
|
|
info = collections.defaultdict(list)
|
|
|
|
for tag in data["tags"]:
|
|
|
|
info[tag["type"]].append(tag["name"])
|
|
|
|
|
2019-03-01 23:13:40 +01:00
|
|
|
language = ""
|
2019-02-27 16:54:25 +01:00
|
|
|
for language in info["language"]:
|
|
|
|
if language != "translated":
|
2019-03-01 23:13:40 +01:00
|
|
|
language = language.capitalize()
|
2019-02-27 16:54:25 +01:00
|
|
|
break
|
|
|
|
|
|
|
|
return {
|
|
|
|
"title" : title_en or title_ja,
|
|
|
|
"title_en" : title_en,
|
|
|
|
"title_ja" : title_ja,
|
|
|
|
"gallery_id": data["id"],
|
|
|
|
"media_id" : text.parse_int(data["media_id"]),
|
|
|
|
"date" : data["upload_date"],
|
|
|
|
"scanlator" : data["scanlator"],
|
|
|
|
"artist" : info["artist"],
|
|
|
|
"group" : info["group"],
|
|
|
|
"parody" : info["parody"],
|
|
|
|
"characters": info["character"],
|
|
|
|
"tags" : info["tag"],
|
|
|
|
"type" : info["category"][0] if info["category"] else "",
|
2019-03-01 23:13:40 +01:00
|
|
|
"lang" : util.language_to_code(language),
|
|
|
|
"language" : language,
|
2019-02-27 16:54:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
def images(self, _):
|
2021-10-14 16:45:53 +02:00
|
|
|
ufmt = ("https://i.nhentai.net/galleries/" +
|
|
|
|
self.data["media_id"] + "/{}.{}")
|
2015-10-28 12:08:27 +01:00
|
|
|
extdict = {"j": "jpg", "p": "png", "g": "gif"}
|
2019-02-27 16:54:25 +01:00
|
|
|
|
|
|
|
return [
|
|
|
|
(ufmt.format(num, extdict.get(img["t"], "jpg")), {
|
|
|
|
"width": img["w"], "height": img["h"],
|
|
|
|
})
|
|
|
|
for num, img in enumerate(self.data["images"]["pages"], 1)
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2021-10-14 16:45:53 +02:00
|
|
|
class NhentaiExtractor(Extractor):
|
|
|
|
"""Base class for nhentai extractors"""
|
|
|
|
category = "nhentai"
|
|
|
|
root = "https://nhentai.net"
|
2021-10-14 16:23:47 +02:00
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
Extractor.__init__(self, match)
|
|
|
|
self.path, self.query = match.groups()
|
|
|
|
|
|
|
|
def items(self):
|
|
|
|
data = {"_extractor": NhentaiGalleryExtractor}
|
|
|
|
for gallery_id in self._pagination():
|
|
|
|
url = "{}/g/{}/".format(self.root, gallery_id)
|
|
|
|
yield Message.Queue, url, data
|
|
|
|
|
|
|
|
def _pagination(self):
|
|
|
|
url = self.root + self.path
|
|
|
|
params = text.parse_query(self.query)
|
|
|
|
params["page"] = text.parse_int(params.get("page"), 1)
|
|
|
|
|
|
|
|
while True:
|
|
|
|
page = self.request(url, params=params).text
|
|
|
|
yield from text.extract_iter(page, 'href="/g/', '/')
|
|
|
|
if 'class="next"' not in page:
|
|
|
|
return
|
|
|
|
params["page"] += 1
|
|
|
|
|
|
|
|
|
2021-10-14 16:45:53 +02:00
|
|
|
class NhentaiTagExtractor(NhentaiExtractor):
|
|
|
|
"""Extractor for nhentai tag searches"""
|
|
|
|
subcategory = "tag"
|
|
|
|
pattern = (r"(?:https?://)?nhentai\.net("
|
|
|
|
r"/(?:artist|category|character|group|language|parody|tag)"
|
|
|
|
r"/[^/?#]+(?:/popular[^/?#]*)?/?)(?:\?([^#]+))?")
|
|
|
|
test = (
|
|
|
|
("https://nhentai.net/tag/sole-female/", {
|
|
|
|
"pattern": NhentaiGalleryExtractor.pattern,
|
|
|
|
"count": 30,
|
|
|
|
"range": "1-30",
|
|
|
|
}),
|
|
|
|
("https://nhentai.net/artist/itou-life/"),
|
|
|
|
("https://nhentai.net/group/itou-life/"),
|
|
|
|
("https://nhentai.net/parody/touhou-project/"),
|
|
|
|
("https://nhentai.net/character/patchouli-knowledge/popular"),
|
|
|
|
("https://nhentai.net/category/doujinshi/popular-today"),
|
|
|
|
("https://nhentai.net/language/english/popular-week"),
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class NhentaiSearchExtractor(NhentaiExtractor):
|
2018-03-28 17:21:44 +02:00
|
|
|
"""Extractor for nhentai search results"""
|
|
|
|
subcategory = "search"
|
2021-10-14 16:45:53 +02:00
|
|
|
pattern = r"(?:https?://)?nhentai\.net(/search/?)\?([^#]+)"
|
2019-02-08 13:45:40 +01:00
|
|
|
test = ("https://nhentai.net/search/?q=touhou", {
|
|
|
|
"pattern": NhentaiGalleryExtractor.pattern,
|
2019-01-14 07:51:05 +01:00
|
|
|
"count": 30,
|
|
|
|
"range": "1-30",
|
2019-02-08 13:45:40 +01:00
|
|
|
})
|
2018-03-28 17:21:44 +02:00
|
|
|
|
2021-09-02 18:26:22 +02:00
|
|
|
|
2021-10-14 16:45:53 +02:00
|
|
|
class NhentaiFavoriteExtractor(NhentaiExtractor):
|
2021-09-02 18:26:22 +02:00
|
|
|
"""Extractor for nhentai favorites"""
|
|
|
|
subcategory = "favorite"
|
2021-10-14 16:45:53 +02:00
|
|
|
pattern = r"(?:https?://)?nhentai\.net(/favorites/?)(?:\?([^#]+))?"
|
2021-09-02 18:26:22 +02:00
|
|
|
test = ("https://nhentai.net/favorites/",)
|