1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-23 11:12:40 +01:00
gallery-dl/gallery_dl/extractor/hentaihere.py

99 lines
3.6 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# Copyright 2016-2018 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.
"""Extract hentai-manga from https://hentaihere.com/"""
from .common import ChapterExtractor, MangaExtractor
from .. import text
import re
import json
2017-02-01 00:53:19 +01:00
class HentaihereMangaExtractor(MangaExtractor):
"""Extractor for hmanga from hentaihere.com"""
category = "hentaihere"
pattern = [r"(?:https?://)?(?:www\.)?(hentaihere\.com/m/S\d+)/?$"]
scheme = "https"
test = [
2017-02-10 21:28:17 +01:00
("https://hentaihere.com/m/S13812", {
"url": "d1ba6e28bb2162e844f8559c2b2725ba0a093559",
2017-09-20 12:26:53 +02:00
"keyword": "13c1ce7e15cbb941f01c843b0e89adc993d939ac",
}),
2017-02-10 21:28:17 +01:00
("https://hentaihere.com/m/S7608", {
"url": "6c5239758dc93f6b1b4175922836c10391b174f7",
2017-09-20 12:26:53 +02:00
"keyword": "675c7b7a4fa52cf569c283553bd16b4200a5cd36",
}),
]
def chapters(self, page):
2017-09-20 12:26:53 +02:00
results = []
manga_id = text.parse_int(
self.url.rstrip("/").rpartition("/")[2][1:])
2017-09-20 12:26:53 +02:00
manga, pos = text.extract(
page, '<span itemprop="name">', '</span>')
mtype, pos = text.extract(
page, '<span class="mngType text-danger">[', ']</span>', pos)
while True:
marker, pos = text.extract(
page, '<li class="sub-chp clearfix">', '', pos)
if marker is None:
2017-09-20 12:26:53 +02:00
return results
url, pos = text.extract(page, '<a href="', '"', pos)
2017-09-20 12:26:53 +02:00
chapter, pos = text.extract(page, 'title="Tagged: -">\n', '<', pos)
chapter_id, pos = text.extract(page, '/C', '"', pos)
chapter, _, title = text.unescape(chapter).strip().partition(" - ")
results.append((url, {
"manga_id": manga_id, "manga": manga, "type": mtype,
"chapter_id": text.parse_int(chapter_id),
"chapter": text.parse_int(chapter),
2017-09-20 12:26:53 +02:00
"title": title, "lang": "en", "language": "English",
}))
class HentaihereChapterExtractor(ChapterExtractor):
"""Extractor for a single manga chapter from hentaihere.com"""
category = "hentaihere"
2018-02-12 23:09:34 +01:00
archive_fmt = "{chapter_id}_{page}"
pattern = [r"(?:https?://)?(?:www\.)?hentaihere\.com/m/S(\d+)/(\d+)"]
2017-02-10 21:28:17 +01:00
test = [("https://hentaihere.com/m/S13812/1/1/", {
2017-08-02 18:31:21 +02:00
"url": "964b942cf492b3a129d2fe2608abfc475bc99e71",
"keyword": "e9382a9be337abce3db2b1132e85751379dc05c5",
})]
def __init__(self, match):
self.manga_id, self.chapter = match.groups()
url = "https://hentaihere.com/m/S{}/{}/1".format(
self.manga_id, self.chapter)
ChapterExtractor.__init__(self, url)
def get_metadata(self, page):
title = text.extract(page, "<title>", "</title>")[0]
2017-09-20 12:26:53 +02:00
chapter_id = text.extract(page, 'report/C', '"')[0]
pattern = r"Page 1 \| (.+) \(([^)]+)\) - Chapter \d+: (.+) by (.+) at "
match = re.match(pattern, title)
return {
"manga": match.group(1),
"manga_id": text.parse_int(self.manga_id),
"chapter": text.parse_int(self.chapter),
"chapter_id": text.parse_int(chapter_id),
"type": match.group(2),
"title": match.group(3),
"author": match.group(4),
"lang": "en",
"language": "English",
}
@staticmethod
def get_images(page):
images = text.extract(page, "var rff_imageList = ", ";")[0]
return [
("https://hentaicdn.com/hentai" + part, None)
for part in json.loads(images)
]