2015-10-28 16:24:35 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2021-09-03 01:01:59 +02:00
|
|
|
# Copyright 2015-2021 Mike Fährmann
|
2015-10-28 16:24:35 +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.
|
|
|
|
|
2020-02-02 17:14:20 +01:00
|
|
|
"""Extractors for https://hitomi.la/"""
|
2015-10-28 16:24:35 +01:00
|
|
|
|
2020-04-20 21:55:19 +02:00
|
|
|
from .common import GalleryExtractor, Extractor, Message
|
|
|
|
from .nozomi import decode_nozomi
|
2017-03-28 13:12:44 +02:00
|
|
|
from .. import text, util
|
2020-03-12 23:39:29 +01:00
|
|
|
import string
|
2019-10-29 16:23:20 +01:00
|
|
|
import json
|
2015-10-28 16:24:35 +01:00
|
|
|
|
2017-02-01 00:53:19 +01:00
|
|
|
|
2019-02-26 14:08:02 +01:00
|
|
|
class HitomiGalleryExtractor(GalleryExtractor):
|
2016-09-12 10:20:57 +02:00
|
|
|
"""Extractor for image galleries from hitomi.la"""
|
2015-11-21 04:26:30 +01:00
|
|
|
category = "hitomi"
|
2019-06-27 20:25:40 +02:00
|
|
|
root = "https://hitomi.la"
|
2019-11-01 21:40:10 +01:00
|
|
|
pattern = (r"(?:https?://)?hitomi\.la"
|
|
|
|
r"/(?:manga|doujinshi|cg|gamecg|galleries|reader)"
|
2020-10-22 15:15:34 +02:00
|
|
|
r"/(?:[^/?#]+-)?(\d+)")
|
2019-02-08 13:45:40 +01:00
|
|
|
test = (
|
2018-03-20 17:36:06 +01:00
|
|
|
("https://hitomi.la/galleries/867789.html", {
|
2020-10-22 15:15:34 +02:00
|
|
|
"pattern": r"https://[a-c]b.hitomi.la/images/./../[0-9a-f]+.jpg",
|
2020-09-20 21:54:39 +02:00
|
|
|
"keyword": "4873ef9a523621fc857b114e0b2820ba4066e9ae",
|
2019-10-09 17:21:37 +02:00
|
|
|
"count": 16,
|
2018-12-14 16:15:06 +01:00
|
|
|
}),
|
2020-02-02 17:14:20 +01:00
|
|
|
# download test
|
2019-05-01 10:54:42 +02:00
|
|
|
("https://hitomi.la/galleries/1401410.html", {
|
|
|
|
"range": "1",
|
|
|
|
"content": "b3ca8c6c8cc5826cf8b4ceb7252943abad7b8b4c",
|
|
|
|
}),
|
2020-02-02 17:14:20 +01:00
|
|
|
# Game CG with scenes (#321)
|
2019-06-27 20:25:40 +02:00
|
|
|
("https://hitomi.la/galleries/733697.html", {
|
2021-09-03 01:01:59 +02:00
|
|
|
"url": "e057652b40629d3d72b0ef059c6ec7556417139c",
|
2019-06-27 20:25:40 +02:00
|
|
|
"count": 210,
|
|
|
|
}),
|
2020-02-02 17:14:20 +01:00
|
|
|
# fallback for galleries only available through /reader/ URLs
|
2019-10-11 18:25:54 +02:00
|
|
|
("https://hitomi.la/galleries/1045954.html", {
|
2021-09-03 01:01:59 +02:00
|
|
|
"url": "779b94b47d5f0c2341db03499270d2b5370196f6",
|
2019-10-11 18:25:54 +02:00
|
|
|
"count": 1413,
|
|
|
|
}),
|
2020-02-02 17:14:20 +01:00
|
|
|
# gallery with "broken" redirect
|
|
|
|
("https://hitomi.la/cg/scathacha-sama-okuchi-ecchi-1291900.html", {
|
|
|
|
"count": 10,
|
|
|
|
}),
|
2020-04-19 23:06:55 +02:00
|
|
|
# no tags
|
|
|
|
("https://hitomi.la/cg/1615823.html", {
|
|
|
|
"count": 22,
|
|
|
|
}),
|
2019-11-01 21:40:10 +01:00
|
|
|
("https://hitomi.la/manga/amazon-no-hiyaku-867789.html"),
|
|
|
|
("https://hitomi.la/manga/867789.html"),
|
|
|
|
("https://hitomi.la/doujinshi/867789.html"),
|
|
|
|
("https://hitomi.la/cg/867789.html"),
|
|
|
|
("https://hitomi.la/gamecg/867789.html"),
|
2019-02-08 13:45:40 +01:00
|
|
|
("https://hitomi.la/reader/867789.html"),
|
|
|
|
)
|
2015-11-21 04:26:30 +01:00
|
|
|
|
2015-10-28 16:24:35 +01:00
|
|
|
def __init__(self, match):
|
2020-03-03 23:18:58 +01:00
|
|
|
gid = match.group(1)
|
|
|
|
url = "https://ltn.hitomi.la/galleries/{}.js".format(gid)
|
2019-02-26 14:08:02 +01:00
|
|
|
GalleryExtractor.__init__(self, match, url)
|
2020-03-12 23:39:29 +01:00
|
|
|
self.info = None
|
2020-02-02 17:14:20 +01:00
|
|
|
self.session.headers["Referer"] = "{}/reader/{}.html".format(
|
2020-03-03 23:18:58 +01:00
|
|
|
self.root, gid)
|
|
|
|
|
|
|
|
def metadata(self, page):
|
2020-03-12 23:39:29 +01:00
|
|
|
self.info = info = json.loads(page.partition("=")[2])
|
2020-03-03 23:18:58 +01:00
|
|
|
|
2020-03-12 23:39:29 +01:00
|
|
|
data = self._data_from_gallery_info(info)
|
|
|
|
if self.config("metadata", True):
|
|
|
|
data.update(self._data_from_gallery_page(info))
|
|
|
|
return data
|
|
|
|
|
|
|
|
def _data_from_gallery_info(self, info):
|
|
|
|
language = info.get("language")
|
2020-03-03 23:18:58 +01:00
|
|
|
if language:
|
|
|
|
language = language.capitalize()
|
|
|
|
|
2020-04-19 23:06:55 +02:00
|
|
|
date = info.get("date")
|
|
|
|
if date:
|
|
|
|
date += ":00"
|
|
|
|
|
2020-03-03 23:18:58 +01:00
|
|
|
tags = []
|
2020-04-19 23:06:55 +02:00
|
|
|
for tinfo in info.get("tags") or ():
|
|
|
|
tag = string.capwords(tinfo["tag"])
|
2020-03-03 23:18:58 +01:00
|
|
|
if tinfo.get("female"):
|
2020-03-12 23:39:29 +01:00
|
|
|
tag += " ♀"
|
2020-03-03 23:18:58 +01:00
|
|
|
elif tinfo.get("male"):
|
2020-03-12 23:39:29 +01:00
|
|
|
tag += " ♂"
|
2020-04-19 23:06:55 +02:00
|
|
|
tags.append(tag)
|
2020-03-03 23:18:58 +01:00
|
|
|
|
|
|
|
return {
|
2020-03-12 23:39:29 +01:00
|
|
|
"gallery_id": text.parse_int(info["id"]),
|
|
|
|
"title" : info["title"],
|
|
|
|
"type" : info["type"].capitalize(),
|
2020-03-03 23:18:58 +01:00
|
|
|
"language" : language,
|
|
|
|
"lang" : util.language_to_code(language),
|
2020-04-19 23:06:55 +02:00
|
|
|
"date" : text.parse_datetime(date, "%Y-%m-%d %H:%M:%S%z"),
|
2020-03-03 23:18:58 +01:00
|
|
|
"tags" : tags,
|
2020-03-12 23:39:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
def _data_from_gallery_page(self, info):
|
|
|
|
url = "{}/galleries/{}.html".format(self.root, info["id"])
|
|
|
|
|
|
|
|
# follow redirects
|
|
|
|
while True:
|
|
|
|
response = self.request(url, fatal=False)
|
|
|
|
if b"<title>Redirect</title>" not in response.content:
|
|
|
|
break
|
2020-08-22 23:02:15 +02:00
|
|
|
url = text.extract(
|
|
|
|
response.text, 'http-equiv="refresh" content="', '"',
|
|
|
|
)[0].partition("=")[2]
|
2020-03-12 23:39:29 +01:00
|
|
|
|
|
|
|
if response.status_code >= 400:
|
|
|
|
return {}
|
|
|
|
|
|
|
|
def prep(value):
|
|
|
|
return [
|
|
|
|
text.unescape(string.capwords(v))
|
|
|
|
for v in text.extract_iter(value or "", '.html">', '<')
|
|
|
|
]
|
|
|
|
|
|
|
|
extr = text.extract_from(response.text)
|
|
|
|
return {
|
|
|
|
"artist" : prep(extr('<h2>', '</h2>')),
|
|
|
|
"group" : prep(extr('<td>Group</td><td>', '</td>')),
|
|
|
|
"parody" : prep(extr('<td>Series</td><td>', '</td>')),
|
|
|
|
"characters": prep(extr('<td>Characters</td><td>', '</td>')),
|
2015-10-28 16:24:35 +01:00
|
|
|
}
|
|
|
|
|
2020-03-03 23:18:58 +01:00
|
|
|
def images(self, _):
|
2020-01-14 12:04:48 +01:00
|
|
|
result = []
|
2020-03-12 23:39:29 +01:00
|
|
|
for image in self.info["files"]:
|
2020-01-14 12:04:48 +01:00
|
|
|
ihash = image["hash"]
|
|
|
|
idata = text.nameext_from_url(image["name"])
|
|
|
|
|
|
|
|
# see https://ltn.hitomi.la/common.js
|
2020-02-22 21:40:37 +01:00
|
|
|
inum = int(ihash[-3:-1], 16)
|
2021-10-30 21:45:01 +02:00
|
|
|
offset = 1 if inum < 0x7c else 0
|
2020-02-22 21:40:37 +01:00
|
|
|
|
2020-10-22 15:15:34 +02:00
|
|
|
url = "https://{}b.hitomi.la/images/{}/{}/{}.{}".format(
|
2021-07-09 18:01:49 +02:00
|
|
|
chr(97 + offset),
|
2020-01-14 12:04:48 +01:00
|
|
|
ihash[-1], ihash[-3:-1], ihash,
|
|
|
|
idata["extension"],
|
|
|
|
)
|
|
|
|
result.append((url, idata))
|
|
|
|
return result
|
2020-04-20 21:55:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
class HitomiTagExtractor(Extractor):
|
|
|
|
"""Extractor for galleries from tag searches on hitomi.la"""
|
|
|
|
category = "hitomi"
|
|
|
|
subcategory = "tag"
|
|
|
|
pattern = (r"(?:https?://)?hitomi\.la/"
|
|
|
|
r"(tag|artist|group|series|type|character)/"
|
2020-10-22 23:12:59 +02:00
|
|
|
r"([^/?#]+)\.html")
|
2020-04-20 21:55:19 +02:00
|
|
|
test = (
|
2020-08-25 21:56:24 +02:00
|
|
|
("https://hitomi.la/tag/screenshots-japanese.html", {
|
2020-04-20 21:55:19 +02:00
|
|
|
"pattern": HitomiGalleryExtractor.pattern,
|
|
|
|
"count": ">= 35",
|
|
|
|
}),
|
|
|
|
("https://hitomi.la/artist/a1-all-1.html"),
|
|
|
|
("https://hitomi.la/group/initial%2Dg-all-1.html"),
|
|
|
|
("https://hitomi.la/series/amnesia-all-1.html"),
|
|
|
|
("https://hitomi.la/type/doujinshi-all-1.html"),
|
|
|
|
("https://hitomi.la/character/a2-all-1.html"),
|
|
|
|
)
|
|
|
|
|
|
|
|
def __init__(self, match):
|
|
|
|
Extractor.__init__(self, match)
|
|
|
|
self.type, self.tag = match.groups()
|
|
|
|
|
2020-08-25 21:56:24 +02:00
|
|
|
tag, _, num = self.tag.rpartition("-")
|
|
|
|
if num.isdecimal():
|
|
|
|
self.tag = tag
|
|
|
|
|
2020-04-20 21:55:19 +02:00
|
|
|
def items(self):
|
|
|
|
url = "https://ltn.hitomi.la/{}/{}.nozomi".format(self.type, self.tag)
|
|
|
|
data = {"_extractor": HitomiGalleryExtractor}
|
|
|
|
|
|
|
|
for gallery_id in decode_nozomi(self.request(url).content):
|
|
|
|
url = "https://hitomi.la/galleries/{}.html".format(gallery_id)
|
|
|
|
yield Message.Queue, url, data
|