Debian Codegraph @

gallery_dl/extractor/sakuhentai.py

raw
1 # -*- coding: utf-8 -*-
2
3 # Copyright 2026 Shinei Nouzen
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License version 2 as
7 # published by the Free Software Foundation.
8
9 """Extractors for https://www.sakuhentai.net/"""
10
11 from .common import GalleryExtractor
12 from .. import text
13
14
15 class SakuhentaiGalleryExtractor(GalleryExtractor):
16 """Extractor for image galleries from sakuhentai.net"""
17 category = "sakuhentai"
18 root = "https://www.sakuhentai.net"
19 pattern = r"(?:https?://)?(?:www\.)?sakuhentai\.net/([^/?&#]+)/?$"
20 example = "https://www.sakuhentai.net/GALLERY-SLUG/"
21
22 def __init__(self, match):
23 url = f"{self.root}/{match[1]}/"
24 GalleryExtractor.__init__(self, match, url)
25
26 def metadata(self, page):
27 self.ld = ld = self._extract_jsonld(page)
28 extr = text.extract_from(page)
29 return {
30 "gallery_id": text.parse_int(extr("?p=", "'")),
31 "title" : text.unescape(extr("entry-title\">", "<")),
32 "anime" : text.unescape(extr(
33 "cat-serie\"><h2 title=\"", '"'))[:-7],
34 "character" : text.unescape(extr(
35 "cat-character\"><h2 title=\"", '"'))[:-7],
36 "artist" : text.unescape(extr(
37 "support-artist\"><h2 title=\"", '"'))[:-7],
38 "date": self.parse_datetime_iso(ld.get("datePublished"))
39 }
40
41 def images(self, _):
42 return [(url, None) for url in self.ld["image"]]