From 0c304263be43ac7f37a663ec205b101485041a6c Mon Sep 17 00:00:00 2001 From: 4censord Date: Fri, 19 Jan 2024 16:27:55 +0100 Subject: [PATCH] [Hreads] Add support --- docs/supportedsites.md | 6 ++ gallery_dl/extractor/__init__.py | 1 + gallery_dl/extractor/hreads.py | 116 +++++++++++++++++++++++++++++++ scripts/supportedsites.py | 1 + 4 files changed, 124 insertions(+) create mode 100644 gallery_dl/extractor/hreads.py diff --git a/docs/supportedsites.md b/docs/supportedsites.md index 53c88335..1616a4a6 100644 --- a/docs/supportedsites.md +++ b/docs/supportedsites.md @@ -337,6 +337,12 @@ Consider all listed sites to potentially be NSFW. Categories, Creators, Posts, Search Results + + Hreads + https://Hreads.net/ + Chapters, Manga + + Idol Complex https://idol.sankakucomplex.com/ diff --git a/gallery_dl/extractor/__init__.py b/gallery_dl/extractor/__init__.py index 8e712961..e00a2757 100644 --- a/gallery_dl/extractor/__init__.py +++ b/gallery_dl/extractor/__init__.py @@ -65,6 +65,7 @@ modules = [ "hiperdex", "hitomi", "hotleak", + "hreads", "idolcomplex", "imagebam", "imagechest", diff --git a/gallery_dl/extractor/hreads.py b/gallery_dl/extractor/hreads.py new file mode 100644 index 00000000..8e810b11 --- /dev/null +++ b/gallery_dl/extractor/hreads.py @@ -0,0 +1,116 @@ +# -*- coding: utf-8 -*- + +# 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://Hreads.net/""" + +import re +from .common import MangaExtractor, ChapterExtractor +from .. import text + + +BASE_PATTERN = r"(?:https?://)?hreads\.net" + + +class HreadsBase: + """Base class for Hreads extractors""" + + category = "hreads" + root = "https://hreads.net/" + + def get_title(self, page): + """Gets the title of the manga""" + title = text.extr(page, "", "") + title = text.unescape(title).strip() + match = re.search( + r"(?:Read )?([\w\d ]+?)(?:(?: - Chapter [\d.]+)? - Hreads)", + title, + ) + if match: + title = match.group(1) + return title + + +class HreadsChapterExtractor(HreadsBase, ChapterExtractor): + """Extractor for manga chapters from Hreads.net""" + + subcategory = "chapter" + directory_fmt = ( + "{category}", + "{manga}", + "Chapter-{chapter:03}{chapter_minor}", + ) + archive_fmt = "{chapter:03}{chapter_minor}_{page}" + pattern = BASE_PATTERN + r"/comic/([\w\d-]+)\/chapter-(\d+-[\d+]|\d+)/?" + example = "https://hreads.net/comics/sex-stopwatch/chapter-1/" + + def __init__(self, match): + url = match.group(0) + self.gid, self.chapter = match.groups() + ChapterExtractor.__init__(self, match, url) + + def metadata(self, page): + chapter, sep, minor = self.chapter.partition("-") + + data = { + "manga": self.get_title(page), + "manga_id": self.gid, + "chapter": text.parse_int(chapter), + "chapter_id": f"{self.gid}-chapter-{self.chapter}", + "chapter_minor": sep + minor, + } + return data + + def images(self, page): + images = [] + first_img = text.extract(page, 'src="https://cdn.hreads.net', '"') + images.append((f"https://cdn.hreads.net{first_img[0].strip()}", None)) + + for url in text.extract_iter(page, 'data-src="', '"'): + images.append((url.strip(), None)) + return images + + +class HreadsMangaExtractor(HreadsBase, MangaExtractor): + """Extractor for manga from Hreads.net""" + + subcategory = "manga" + chapterclass = HreadsChapterExtractor + pattern = BASE_PATTERN + r"/comic/([\w\d-]+)/?$" + example = "https://hreads.net/comics/sex-stopwatch" + + def __init__(self, match): + url, self.gid = match.group(0), match.group(1) + MangaExtractor.__init__(self, match, url) + + def chapters(self, page): + chapters = set() + print("Chapter extraction") + for chapter_id in text.extract_iter( + page, f'