1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-24 03:32:33 +01:00
gallery-dl/gallery_dl/extractor/hiperdex.py

197 lines
7.2 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2023-01-26 12:01:16 +01:00
# Copyright 2020-2023 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.
2023-03-15 14:28:03 +01:00
"""Extractors for https://hiperdex.com/"""
from .common import ChapterExtractor, MangaExtractor
from .. import text
from ..cache import memcache
import re
2023-01-26 12:01:16 +01:00
BASE_PATTERN = (r"((?:https?://)?(?:www\.)?"
r"(?:1st)?hiperdex\d?\.(?:com|net|info))")
class HiperdexBase():
"""Base class for hiperdex extractors"""
category = "hiperdex"
2023-03-15 14:28:03 +01:00
root = "https://hiperdex.com"
@memcache(keyarg=1)
def manga_data(self, manga, page=None):
if not page:
url = "{}/manga/{}/".format(self.root, manga)
page = self.request(url).text
extr = text.extract_from(page)
return {
"manga" : text.unescape(extr(
2023-03-15 14:28:03 +01:00
"<title>", "<").rpartition(" - ")[0].strip()),
2023-03-25 18:18:27 +01:00
"url" : text.unescape(extr(
'property="og:url" content="', '"')),
"score" : text.parse_float(extr(
'id="averagerate">', '<')),
"author" : text.remove_html(extr(
'class="author-content">', '</div>')),
"artist" : text.remove_html(extr(
'class="artist-content">', '</div>')),
"genre" : text.split_html(extr(
'class="genres-content">', '</div>'))[::2],
"type" : extr(
'class="summary-content">', '<').strip(),
"release": text.parse_int(text.remove_html(extr(
'class="summary-content">', '</div>'))),
"status" : extr(
'class="summary-content">', '<').strip(),
"description": text.remove_html(text.unescape(extr(
'class="description-summary">', '</div>'))),
"language": "English",
"lang" : "en",
}
def chapter_data(self, chapter):
2023-01-26 12:01:16 +01:00
if chapter.startswith("chapter-"):
chapter = chapter[8:]
chapter, _, minor = chapter.partition("-")
data = {
"chapter" : text.parse_int(chapter),
"chapter_minor": "." + minor if minor and minor != "end" else "",
}
data.update(self.manga_data(self.manga.lower()))
return data
class HiperdexChapterExtractor(HiperdexBase, ChapterExtractor):
2023-03-15 14:28:03 +01:00
"""Extractor for manga chapters from hiperdex.com"""
pattern = BASE_PATTERN + r"(/manga/([^/?#]+)/([^/?#]+))"
test = (
2023-03-15 14:28:03 +01:00
("https://hiperdex.com/manga/domestic-na-kanojo/154-5/", {
2023-01-26 12:01:16 +01:00
"pattern": r"https://(1st)?hiperdex\d?.(com|net|info)"
r"/wp-content/uploads/WP-manga/data"
r"/manga_\w+/[0-9a-f]{32}/\d+\.webp",
"count": 9,
"keyword": {
"artist" : "Sasuga Kei",
"author" : "Sasuga Kei",
"chapter": 154,
"chapter_minor": ".5",
"description": "re:Natsuo Fujii is in love with his teacher, ",
"genre" : list,
"manga" : "Domestic na Kanojo",
"release": 2014,
"score" : float,
"type" : "Manga",
},
}),
2023-03-15 14:28:03 +01:00
("https://1sthiperdex.com/manga/domestic-na-kanojo/154-5/"),
2021-07-02 23:23:42 +02:00
("https://hiperdex2.com/manga/domestic-na-kanojo/154-5/"),
("https://hiperdex.net/manga/domestic-na-kanojo/154-5/"),
("https://hiperdex.info/manga/domestic-na-kanojo/154-5/"),
)
def __init__(self, match):
2021-07-02 23:23:42 +02:00
root, path, self.manga, self.chapter = match.groups()
self.root = text.ensure_http_scheme(root)
ChapterExtractor.__init__(self, match, self.root + path + "/")
def metadata(self, _):
return self.chapter_data(self.chapter)
def images(self, page):
return [
(url.strip(), None)
2020-04-03 21:25:25 +02:00
for url in re.findall(
r'id="image-\d+"\s+(?:data-)?src="([^"]+)', page)
]
class HiperdexMangaExtractor(HiperdexBase, MangaExtractor):
2023-03-15 14:28:03 +01:00
"""Extractor for manga from hiperdex.com"""
chapterclass = HiperdexChapterExtractor
pattern = BASE_PATTERN + r"(/manga/([^/?#]+))/?$"
test = (
2023-03-25 18:18:27 +01:00
("https://hiperdex.com/manga/1603231576-youre-not-that-special/", {
"count": 51,
"pattern": HiperdexChapterExtractor.pattern,
"keyword": {
"artist" : "Bolp",
"author" : "Abyo4",
"chapter": int,
"chapter_minor": "",
"description": "re:I didnt think much of the creepy girl in ",
"genre" : list,
"manga" : "Youre Not That Special!",
"release": 2019,
"score" : float,
"status" : "Completed",
"type" : "Manhwa",
},
}),
2023-03-25 18:18:27 +01:00
("https://hiperdex.com/manga/youre-not-that-special/"),
2023-03-15 14:28:03 +01:00
("https://1sthiperdex.com/manga/youre-not-that-special/"),
2021-07-02 23:23:42 +02:00
("https://hiperdex2.com/manga/youre-not-that-special/"),
("https://hiperdex.net/manga/youre-not-that-special/"),
("https://hiperdex.info/manga/youre-not-that-special/"),
)
def __init__(self, match):
2021-07-02 23:23:42 +02:00
root, path, self.manga = match.groups()
self.root = text.ensure_http_scheme(root)
MangaExtractor.__init__(self, match, self.root + path + "/")
def chapters(self, page):
2023-03-25 18:18:27 +01:00
data = self.manga_data(self.manga, page)
self.manga_url = url = data["url"]
url = self.manga_url + "ajax/chapters/"
headers = {
"Accept": "*/*",
"X-Requested-With": "XMLHttpRequest",
"Origin": self.root,
"Referer": self.manga_url,
}
html = self.request(url, method="POST", headers=headers).text
2020-04-12 02:27:13 +02:00
2023-03-25 18:18:27 +01:00
results = []
for item in text.extract_iter(
html, '<li class="wp-manga-chapter', '</li>'):
url = text.extr(item, 'href="', '"')
chapter = url.rstrip("/").rpartition("/")[2]
2020-04-12 02:27:13 +02:00
results.append((url, self.chapter_data(chapter)))
return results
class HiperdexArtistExtractor(HiperdexBase, MangaExtractor):
"""Extractor for an artists's manga on hiperdex.com"""
subcategory = "artist"
categorytransfer = False
chapterclass = HiperdexMangaExtractor
reverse = False
2021-07-02 23:23:42 +02:00
pattern = BASE_PATTERN + r"(/manga-a(?:rtist|uthor)/(?:[^/?#]+))"
test = (
2023-01-26 12:01:16 +01:00
("https://1sthiperdex.com/manga-artist/beck-ho-an/"),
("https://hiperdex.net/manga-artist/beck-ho-an/"),
2021-07-02 23:23:42 +02:00
("https://hiperdex2.com/manga-artist/beck-ho-an/"),
("https://hiperdex.info/manga-artist/beck-ho-an/"),
("https://hiperdex.com/manga-author/viagra/", {
"pattern": HiperdexMangaExtractor.pattern,
"count": ">= 6",
}),
)
def __init__(self, match):
2021-07-02 23:23:42 +02:00
self.root = text.ensure_http_scheme(match.group(1))
MangaExtractor.__init__(self, match, self.root + match.group(2) + "/")
def chapters(self, page):
results = []
for info in text.extract_iter(page, 'id="manga-item-', '<img'):
url = text.extr(info, 'href="', '"')
results.append((url, {}))
return results