[hentai2read] fix exception for chapters without artist (#7355)

This commit is contained in:
Mike Fährmann
2025-04-12 20:14:31 +02:00
parent 81ff0219a1
commit feacdd5d87
2 changed files with 39 additions and 10 deletions

View File

@@ -25,26 +25,30 @@ class Hentai2readChapterExtractor(Hentai2readBase, ChapterExtractor):
pattern = r"(?:https?://)?(?:www\.)?hentai2read\.com(/[^/?#]+/([^/?#]+))" pattern = r"(?:https?://)?(?:www\.)?hentai2read\.com(/[^/?#]+/([^/?#]+))"
example = "https://hentai2read.com/TITLE/1/" example = "https://hentai2read.com/TITLE/1/"
def __init__(self, match):
self.chapter = match.group(2)
ChapterExtractor.__init__(self, match)
def metadata(self, page): def metadata(self, page):
title, pos = text.extract(page, "<title>", "</title>") title, pos = text.extract(page, "<title>", "</title>")
manga_id, pos = text.extract(page, 'data-mid="', '"', pos) manga_id, pos = text.extract(page, 'data-mid="', '"', pos)
chapter_id, pos = text.extract(page, 'data-cid="', '"', pos) chapter_id, pos = text.extract(page, 'data-cid="', '"', pos)
chapter, sep, minor = self.chapter.partition(".") chapter, sep, minor = self.groups[1].partition(".")
match = re.match(r"Reading (.+) \(([^)]+)\) Hentai(?: by (.+))? - "
match = re.match(r"Reading (.+) \(([^)]+)\) Hentai(?: by (.*))? - "
r"([^:]+): (.+) . Page 1 ", title) r"([^:]+): (.+) . Page 1 ", title)
if match:
manga, type, author, _, title = match.groups()
else:
self.log.warning("Failed to extract 'manga', 'type', 'author', "
"and 'title' metadata")
manga = type = author = title = ""
return { return {
"manga": match.group(1), "manga": manga,
"manga_id": text.parse_int(manga_id), "manga_id": text.parse_int(manga_id),
"chapter": text.parse_int(chapter), "chapter": text.parse_int(chapter),
"chapter_minor": sep + minor, "chapter_minor": sep + minor,
"chapter_id": text.parse_int(chapter_id), "chapter_id": text.parse_int(chapter_id),
"type": match.group(2), "type": type,
"author": match.group(3), "author": author,
"title": match.group(5), "title": title,
"lang": "en", "lang": "en",
"language": "English", "language": "English",
} }

View File

@@ -37,6 +37,31 @@ __tests__ = (
"type" : "Original", "type" : "Original",
}, },
{
"#url" : "https://hentai2read.com/nozoki_ana/1/",
"#category": ("", "hentai2read", "chapter"),
"#class" : hentai2read.Hentai2readChapterExtractor,
"#pattern" : r"https://hentaicdn\.com/hentai/2720/1/hcdn00\d+\.jpg",
"#count" : 203,
"author" : "",
"chapter" : 1,
"chapter_id" : 2965,
"chapter_minor": "",
"count" : 203,
"extension" : "jpg",
"filename" : str,
"lang" : "en",
"language" : "English",
"manga" : "Nozoki Ana [Ecchi]",
"manga_id" : 2720,
"page" : range(1, 203),
"subcategory" : "chapter",
"title" : "Nozoki Ana 1",
"type" : "Original",
},
{ {
"#url" : "https://hentai2read.com/amazon_elixir/", "#url" : "https://hentai2read.com/amazon_elixir/",
"#category": ("", "hentai2read", "manga"), "#category": ("", "hentai2read", "manga"),