| 1 |
|
| 2 |
|
| 3 |
n |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
"""Extractors for https://www.simply-hentai.com/""" |
| 10 |
|
| 11 |
from .common import Extractor, GalleryExtractor, Message |
| 12 |
from .. import text, util |
| 13 |
|
| 14 |
BASE_PATTERN = r"(?:https?://)?(?:www\.)?simply-hentai\.com" |
| 15 |
|
| 16 |
|
| 17 |
class SimplyhentaiExtractor(Extractor): |
| 18 |
"""Base class for simplyhentai extractors""" |
| 19 |
category = "simplyhentai" |
| 20 |
root = "https://www.simply-hentai.com" |
| 21 |
root_api = "https://api-v3.simply-hentai.com" |
| 22 |
browser = "firefox" |
| 23 |
|
| 24 |
def items(self): |
| 25 |
for gallery in self.galleries(): |
| 26 |
gallery["_extractor"] = SimplyhentaiGalleryExtractor |
| 27 |
series = (s["slug"] if (s := gallery.get("series")) else |
| 28 |
"8-original-work") |
| 29 |
url = f"{self.root}/{series}/{gallery['slug']}" |
| 30 |
yield Message.Queue, url, gallery |
| 31 |
|
| 32 |
def request_api(self, endpoint, params=None): |
| 33 |
url = f"{self.root_api}/v3{endpoint}" |
| 34 |
return self.request_json(url, params=params) |
| 35 |
|
| 36 |
def _pagination(self, endpoint, params): |
| 37 |
params["page"] = text.parse_int(params.get("page"), 1) |
| 38 |
|
| 39 |
while True: |
| 40 |
data = self.request_api(endpoint, params) |
| 41 |
|
| 42 |
if isinstance(data["data"], dict): |
| 43 |
yield from data["data"]["albums"] |
| 44 |
else: |
| 45 |
yield from data["data"] |
| 46 |
|
| 47 |
try: |
| 48 |
if params["page"] >= data["pagination"]["pages"]: |
| 49 |
break |
| 50 |
except Exception: |
| 51 |
break |
| 52 |
params["page"] += 1 |
| 53 |
|
| 54 |
|
| 55 |
class SimplyhentaiSeriesExtractor(SimplyhentaiExtractor): |
| 56 |
subcategory = "series" |
| 57 |
pattern = (BASE_PATTERN + r"/series/([^/?#]+)" |
| 58 |
r"(?:/tag-([^/?#]+))?(?:/sort-([^/?#]+))?(?:/page-(\d+))?" |
| 59 |
r"(?:\?([^#]+))?") |
| 60 |
example = "https://www.simply-hentai.com/series/SLUG" |
| 61 |
|
| 62 |
def galleries(self): |
| 63 |
slug, tag, sort, pnum, qs = self.groups |
| 64 |
params = text.parse_query(qs) |
| 65 |
if tag is not None: |
| 66 |
params["tag_slug"] = tag |
| 67 |
if sort is not None: |
| 68 |
params["sort"] = sort |
| 69 |
if pnum is not None: |
| 70 |
params["page"] = pnum |
| 71 |
return self._pagination("/series/" + slug, params) |
| 72 |
|
| 73 |
|
| 74 |
class SimplyhentaiMangaExtractor(SimplyhentaiExtractor): |
| 75 |
subcategory = "manga" |
| 76 |
pattern = (BASE_PATTERN + r"/2-mangas" |
| 77 |
r"(?:/sort-([^/?#]+))?(?:/page-(\d+))?(?:\?([^#]+))?") |
| 78 |
example = "https://www.simply-hentai.com/2-mangas" |
| 79 |
|
| 80 |
def galleries(self): |
| 81 |
sort, pnum, qs = self.groups |
| 82 |
params = text.parse_query(qs) |
| 83 |
if sort is not None: |
| 84 |
params["sort"] = sort |
| 85 |
if pnum is not None: |
| 86 |
params["page"] = pnum |
| 87 |
return self._pagination("/mangas", params) |
| 88 |
|
| 89 |
|
| 90 |
class SimplyhentaiTagExtractor(SimplyhentaiExtractor): |
| 91 |
subcategory = "tag" |
| 92 |
pattern = (BASE_PATTERN + |
| 93 |
r"/(parody|tag|character|collection|artist|translator)" |
| 94 |
r"/([^/?#]+)" |
| 95 |
r"(?:/tag-([^/?#]+))?(?:/sort-([^/?#]+))?(?:/page-(\d+))?" |
| 96 |
r"(?:\?([^#]+))?") |
| 97 |
example = "https://www.simply-hentai.com/tag/TAG" |
| 98 |
|
| 99 |
def galleries(self): |
| 100 |
type, slug, tag, sort, pnum, qs = self.groups |
| 101 |
params = text.parse_query(qs) |
| 102 |
if type == "collection": |
| 103 |
endpoint = "/collection/" + slug |
| 104 |
else: |
| 105 |
endpoint = "/tag/" + slug |
| 106 |
params["type"] = type |
| 107 |
if tag is not None: |
| 108 |
params["tag_slug"] = tag |
| 109 |
if sort is not None: |
| 110 |
params["sort"] = sort |
| 111 |
if pnum is not None: |
| 112 |
params["page"] = pnum |
| 113 |
return self._pagination(endpoint, params) |
| 114 |
|
| 115 |
|
| 116 |
class SimplyhentaiLanguageExtractor(SimplyhentaiExtractor): |
| 117 |
subcategory = "language" |
| 118 |
pattern = (BASE_PATTERN + r"/language/([^/?#]+)" |
| 119 |
r"(?:/sort-([^/?#]+))?(?:/page-(\d+))?(?:\?([^#]+))?") |
| 120 |
example = "https://www.simply-hentai.com/language/LANG" |
| 121 |
|
| 122 |
def galleries(self): |
| 123 |
language, sort, pnum, qs = self.groups |
| 124 |
params = text.parse_query(qs) |
| 125 |
params["type"] = "language" |
| 126 |
if sort is not None: |
| 127 |
params["sort"] = sort |
| 128 |
if pnum is not None: |
| 129 |
params["page"] = pnum |
| 130 |
return self._pagination("/tag/" + language, params) |
| 131 |
|
| 132 |
|
| 133 |
class SimplyhentaiGalleryExtractor(GalleryExtractor, SimplyhentaiExtractor): |
| 134 |
"""Extractor for simplyhentai galleries""" |
| 135 |
archive_fmt = "{id}" |
| 136 |
pattern = BASE_PATTERN + r"/[^/?#]+/([^/?#]+)" |
| 137 |
example = "https://www.simply-hentai.com/SERIES/SLUG" |
| 138 |
|
| 139 |
def metadata(self, _): |
| 140 |
endpoint = "/manga/" + self.groups[0] |
| 141 |
data = self.request_api(endpoint)["data"] |
| 142 |
data["gallery_id"] = data.pop("id") |
| 143 |
data["series"] = (s := data.get("series")) and s.get("title") |
| 144 |
data["date"] = self.parse_datetime_iso(data.get("created_at")) |
| 145 |
|
| 146 |
for key in ("artists", "characters", "parodies", |
| 147 |
"tags", "translators"): |
| 148 |
data[key] = [t["title"] for t in data.get(key) or ()] |
| 149 |
|
| 150 |
data.pop("related", None) |
| 151 |
self._images = data.pop("images", ()) |
| 152 |
if data.get("image_count", 32) > 12: |
| 153 |
self._images = endpoint + "/pages" |
| 154 |
|
| 155 |
try: |
| 156 |
data["language"] = language = data["language"]["name"] |
| 157 |
data["lang"] = util.language_to_code(language) |
| 158 |
except Exception: |
| 159 |
pass |
| 160 |
|
| 161 |
try: |
| 162 |
data["cover"] = data.pop("preview")["sizes"]["full"] |
| 163 |
except Exception: |
| 164 |
pass |
| 165 |
|
| 166 |
return data |
| 167 |
|
| 168 |
def images(self, _): |
| 169 |
imgs = self._images |
| 170 |
if isinstance(imgs, str): |
| 171 |
imgs = self.request_api(imgs)["data"]["pages"] |
| 172 |
return [(img["sizes"]["full"], {"id": img["id"]}) for img in imgs] |