# -*- coding: utf-8 -*- # Copyright 2015-2020 Mike Fährmann # # 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. """Extractors for https://hitomi.la/""" from .common import GalleryExtractor from .. import text, util import string import json class HitomiGalleryExtractor(GalleryExtractor): """Extractor for image galleries from hitomi.la""" category = "hitomi" root = "https://hitomi.la" pattern = (r"(?:https?://)?hitomi\.la" r"/(?:manga|doujinshi|cg|gamecg|galleries|reader)" r"/(?:[^/?]+-)?(\d+)") test = ( ("https://hitomi.la/galleries/867789.html", { "pattern": r"https://[a-c]a.hitomi.la/images/./../[0-9a-f]+.jpg", "keyword": "6701f8f588f119ef84cd29bdf99a399417b0a6a2", "count": 16, }), # download test ("https://hitomi.la/galleries/1401410.html", { "range": "1", "content": "b3ca8c6c8cc5826cf8b4ceb7252943abad7b8b4c", }), # Game CG with scenes (#321) ("https://hitomi.la/galleries/733697.html", { "url": "21064f9e3c244aca87f1a91967a3fbe79032c4ce", "count": 210, }), # fallback for galleries only available through /reader/ URLs ("https://hitomi.la/galleries/1045954.html", { "url": "0a67f5e6c3c6a384b578e328f4817fa6ccdf856a", "count": 1413, }), # gallery with "broken" redirect ("https://hitomi.la/cg/scathacha-sama-okuchi-ecchi-1291900.html", { "count": 10, }), ("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"), ("https://hitomi.la/reader/867789.html"), ) def __init__(self, match): self.gallery_id = match.group(1) url = "https://ltn.hitomi.la/galleries/{}.js".format(self.gallery_id) GalleryExtractor.__init__(self, match, url) self.session.headers["Referer"] = "{}/reader/{}.html".format( self.root, self.gallery_id) def metadata(self, _): # try galleries page first url = "{}/galleries/{}.html".format(self.root, self.gallery_id) response = self.request(url, fatal=False) # follow redirects if b"