1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 18:53:21 +01:00
gallery-dl/gallery_dl/extractor/hentai2read.py

98 lines
3.7 KiB
Python
Raw Normal View History

2016-02-19 15:24:49 +01:00
# -*- coding: utf-8 -*-
# Copyright 2016-2018 Mike Fährmann
2016-02-19 15:24:49 +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 hentai-manga from https://hentai2read.com/"""
2016-02-19 15:24:49 +01:00
from .common import ChapterExtractor, MangaExtractor
from .. import text, util
2016-02-19 15:24:49 +01:00
import re
2017-02-26 02:25:36 +01:00
import json
2016-02-19 15:24:49 +01:00
2017-02-01 00:53:19 +01:00
class Hentai2readMangaExtractor(MangaExtractor):
"""Extractor for hmanga from hentai2read.com"""
category = "hentai2read"
2017-08-02 18:31:21 +02:00
scheme = "https"
pattern = [r"(?:https?://)?(?:www\.)?(hentai2read\.com/[^/]+/?)$"]
test = [
("http://hentai2read.com/amazon_elixir/", {
2017-08-02 18:31:21 +02:00
"url": "273073752d418ec887d7f7211e42b832e8c403ba",
2017-09-20 13:28:57 +02:00
"keyword": "13c1ce7e15cbb941f01c843b0e89adc993d939ac",
}),
("http://hentai2read.com/oshikage_riot/", {
2017-08-02 18:31:21 +02:00
"url": "6595f920a3088a15c2819c502862d45f8eb6bea6",
2017-09-20 13:28:57 +02:00
"keyword": "675c7b7a4fa52cf569c283553bd16b4200a5cd36",
2017-08-02 18:31:21 +02:00
}),
]
def chapters(self, page):
2017-09-20 13:28:57 +02:00
results = []
manga, pos = text.extract(
page, '<span itemprop="name">', '</span>')
2017-09-20 13:28:57 +02:00
mtype, pos = text.extract(
page, '<small class="text-danger">[', ']</small>', pos)
manga_id = util.safe_int(text.extract(page, 'data-mid="', '"', pos)[0])
2017-09-20 13:28:57 +02:00
while True:
chapter_id, pos = text.extract(page, ' data-cid="', '"', pos)
if not chapter_id:
return results
_ , pos = text.extract(page, ' href="', '"', pos)
url, pos = text.extract(page, ' href="', '"', pos)
chapter, pos = text.extract(page, '>', '<', pos)
2017-09-20 13:28:57 +02:00
chapter, _, title = text.unescape(chapter).strip().partition(" - ")
results.append((url, {
"manga_id": manga_id, "manga": manga, "type": mtype,
"chapter_id": util.safe_int(chapter_id),
"chapter": util.safe_int(chapter),
2017-09-20 13:28:57 +02:00
"title": title, "lang": "en", "language": "English",
}))
class Hentai2readChapterExtractor(ChapterExtractor):
"""Extractor for a single manga chapter from hentai2read.com"""
2016-02-19 15:24:49 +01:00
category = "hentai2read"
pattern = [r"(?:https?://)?(?:www\.)?hentai2read\.com/([^/]+)/(\d+)"]
test = [("http://hentai2read.com/amazon_elixir/1/", {
2017-08-02 18:31:21 +02:00
"url": "964b942cf492b3a129d2fe2608abfc475bc99e71",
"keyword": "9845105898d28c6a540cffdea60a1a20fab52431",
2016-02-19 15:24:49 +01:00
})]
def __init__(self, match):
2017-02-26 02:25:36 +01:00
url_title, self.chapter = match.groups()
url = "https://hentai2read.com/{}/{}/".format(url_title, self.chapter)
ChapterExtractor.__init__(self, url)
2016-02-19 15:24:49 +01:00
def get_metadata(self, page):
title, pos = text.extract(page, "<title>", "</title>")
manga_id, pos = text.extract(page, 'data-mid="', '"', pos)
chapter_id, pos = text.extract(page, 'data-cid="', '"', pos)
match = re.match(r"Reading (.+) \(([^)]+)\) Hentai(?: by (.+))? - "
r"(\d+): (.+) . Page 1 ", title)
2016-02-19 15:24:49 +01:00
return {
"manga": match.group(1),
"manga_id": util.safe_int(manga_id),
"chapter": util.safe_int(self.chapter),
"chapter_id": util.safe_int(chapter_id),
"type": match.group(2),
"author": match.group(3),
"title": match.group(5),
2016-02-19 15:24:49 +01:00
"lang": "en",
"language": "English",
}
2017-02-26 02:25:36 +01:00
@staticmethod
def get_images(page):
2017-02-26 02:25:36 +01:00
"""Extract and return a list of all image-urls"""
images = text.extract(page, "'images' : ", ",\n")[0]
return [
("https://hentaicdn.com/hentai" + part, None)
for part in json.loads(images)
]