2015-10-28 16:24:35 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2019-02-08 13:45:40 +01:00
|
|
|
# Copyright 2015-2019 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.
|
|
|
|
|
|
|
|
"""Extract images from https://hitomi.la/"""
|
|
|
|
|
2019-02-26 14:08:02 +01:00
|
|
|
from .common import GalleryExtractor
|
2017-03-28 13:12:44 +02:00
|
|
|
from .. import text, util
|
2015-10-29 17:53: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)"
|
|
|
|
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", {
|
2019-10-09 17:21:37 +02:00
|
|
|
"pattern": r"https://aa.hitomi.la/galleries/867789/\d+.jpg",
|
2019-10-16 18:12:07 +02:00
|
|
|
"keyword": "6701f8f588f119ef84cd29bdf99a399417b0a6a2",
|
2019-10-09 17:21:37 +02:00
|
|
|
"count": 16,
|
2018-12-14 16:15:06 +01:00
|
|
|
}),
|
2019-05-01 10:54:42 +02:00
|
|
|
("https://hitomi.la/galleries/1401410.html", {
|
|
|
|
# download test
|
|
|
|
"range": "1",
|
|
|
|
"content": "b3ca8c6c8cc5826cf8b4ceb7252943abad7b8b4c",
|
|
|
|
}),
|
2019-06-27 20:25:40 +02:00
|
|
|
("https://hitomi.la/galleries/733697.html", {
|
|
|
|
# Game CG with scenes (#321)
|
|
|
|
"url": "c2a84185f467450b8b9b72fbe40c0649029ce007",
|
|
|
|
"count": 210,
|
|
|
|
}),
|
2019-10-11 18:25:54 +02:00
|
|
|
("https://hitomi.la/galleries/1045954.html", {
|
|
|
|
# fallback for galleries only available through /reader/ URLs
|
|
|
|
"url": "055c898a36389719799d6bce76889cc4ea4421fc",
|
|
|
|
"count": 1413,
|
|
|
|
}),
|
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):
|
2019-10-09 17:21:37 +02:00
|
|
|
self.gallery_id = match.group(1)
|
2019-10-11 18:25:54 +02:00
|
|
|
self.fallback = False
|
2019-06-27 20:25:40 +02:00
|
|
|
url = "{}/galleries/{}.html".format(self.root, self.gallery_id)
|
2019-02-26 14:08:02 +01:00
|
|
|
GalleryExtractor.__init__(self, match, url)
|
2015-10-28 16:24:35 +01:00
|
|
|
|
2019-10-11 18:25:54 +02:00
|
|
|
def request(self, url, **kwargs):
|
|
|
|
response = GalleryExtractor.request(self, url, fatal=False, **kwargs)
|
|
|
|
if response.status_code == 404:
|
|
|
|
self.fallback = True
|
|
|
|
url = url.replace("/galleries/", "/reader/")
|
|
|
|
response = GalleryExtractor.request(self, url, **kwargs)
|
2019-11-01 21:40:10 +01:00
|
|
|
elif b"<title>Redirect</title>" in response.content:
|
|
|
|
url = text.extract(response.text, "href='", "'")[0]
|
|
|
|
if not url.startswith("http"):
|
|
|
|
url = text.urljoin(self.root, url)
|
|
|
|
response = self.request(url, **kwargs)
|
2019-10-11 18:25:54 +02:00
|
|
|
return response
|
|
|
|
|
2019-02-11 18:38:47 +01:00
|
|
|
def metadata(self, page):
|
2019-10-11 18:25:54 +02:00
|
|
|
if self.fallback:
|
|
|
|
return {
|
|
|
|
"gallery_id": text.parse_int(self.gallery_id),
|
|
|
|
"title": text.unescape(text.extract(
|
|
|
|
page, "<title>", "<")[0].rpartition(" | ")[0]),
|
|
|
|
}
|
|
|
|
|
2019-05-01 11:14:21 +02:00
|
|
|
extr = text.extract_from(page, page.index('<h1><a href="/reader/'))
|
|
|
|
data = {
|
2019-10-09 17:21:37 +02:00
|
|
|
"gallery_id": text.parse_int(self.gallery_id),
|
2019-05-01 11:14:21 +02:00
|
|
|
"title" : text.unescape(extr('.html">', '<').strip()),
|
|
|
|
"artist" : self._prep(extr('<h2>', '</h2>')),
|
|
|
|
"group" : self._prep(extr('<td>Group</td><td>', '</td>')),
|
|
|
|
"type" : self._prep_1(extr('<td>Type</td><td>', '</td>')),
|
|
|
|
"language" : self._prep_1(extr('<td>Language</td><td>', '</td>')),
|
|
|
|
"parody" : self._prep(extr('<td>Series</td><td>', '</td>')),
|
|
|
|
"characters": self._prep(extr('<td>Characters</td><td>', '</td>')),
|
|
|
|
"tags" : self._prep(extr('<td>Tags</td><td>', '</td>')),
|
2019-06-17 19:59:43 +02:00
|
|
|
"date" : self._date(extr('<span class="date">', '</span>')),
|
2015-10-28 16:24:35 +01:00
|
|
|
}
|
2019-06-17 19:59:43 +02:00
|
|
|
if data["language"] == "N/a":
|
2019-05-01 11:14:21 +02:00
|
|
|
data["language"] = None
|
|
|
|
data["lang"] = util.language_to_code(data["language"])
|
|
|
|
return data
|
2015-10-28 16:24:35 +01:00
|
|
|
|
2019-02-11 18:38:47 +01:00
|
|
|
def images(self, page):
|
2018-12-14 16:15:06 +01:00
|
|
|
# see https://ltn.hitomi.la/common.js
|
2019-10-09 17:21:37 +02:00
|
|
|
offset = text.parse_int(self.gallery_id[-1]) % 3
|
2018-12-14 16:15:06 +01:00
|
|
|
subdomain = chr(97 + offset) + "a"
|
2019-10-29 16:23:20 +01:00
|
|
|
base = "https://{}.hitomi.la/galleries/{}/".format(
|
|
|
|
subdomain, self.gallery_id)
|
2018-12-14 16:15:06 +01:00
|
|
|
|
2019-05-01 10:54:42 +02:00
|
|
|
# set Referer header before image downloads (#239)
|
2019-10-16 18:12:07 +02:00
|
|
|
self.session.headers["Referer"] = self.gallery_url
|
2019-05-01 10:54:42 +02:00
|
|
|
|
2019-10-29 16:23:20 +01:00
|
|
|
# get 'galleryinfo'
|
|
|
|
url = "https://ltn.hitomi.la/galleries/{}.js".format(self.gallery_id)
|
|
|
|
page = self.request(url).text
|
2019-06-27 20:25:40 +02:00
|
|
|
|
2016-09-23 08:21:49 +02:00
|
|
|
return [
|
2019-10-29 16:23:20 +01:00
|
|
|
(base + image["name"], None)
|
|
|
|
for image in json.loads(page.partition("=")[2])
|
2016-09-23 08:21:49 +02:00
|
|
|
]
|
2018-03-20 17:36:06 +01:00
|
|
|
|
|
|
|
@staticmethod
|
2019-05-01 11:14:21 +02:00
|
|
|
def _prep(value):
|
2019-03-01 23:13:40 +01:00
|
|
|
return [
|
|
|
|
text.unescape(string.capwords(v))
|
|
|
|
for v in text.extract_iter(value or "", '.html">', '<')
|
|
|
|
]
|
2019-05-01 11:14:21 +02:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _prep_1(value):
|
|
|
|
return text.remove_html(value).capitalize()
|
2019-06-17 19:59:43 +02:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _date(value):
|
|
|
|
return text.parse_datetime(value + ":00", "%Y-%m-%d %H:%M:%S%z")
|