Debian Codegraph @

gallery_dl/extractor/madokami.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 # Copyright 2025 Mike Fährmann
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://manga.madokami.al/"""
10
11 from .common import Extractor, Message
12 from .. import text, util
13
14 BASE_PATTERN = r"(?:https?://)?manga\.madokami\.al"
15
16
17 class MadokamiExtractor(Extractor):
18 """Base class for madokami extractors"""
19 category = "madokami"
20 root = "https://manga.madokami.al"
21
22
23 class MadokamiMangaExtractor(MadokamiExtractor):
24 """Extractor for madokami manga"""
25 subcategory = "manga"
26 directory_fmt = ("{category}", "{manga}")
27 archive_fmt = "{chapter_id}"
28 pattern = BASE_PATTERN + r"/Manga/(\w/\w{2}/\w{4}/.+)"
29 example = "https://manga.madokami.al/Manga/A/AB/ABCD/ABCDE_TITLE"
30
31 def items(self):
32 username, password = self._get_auth_info()
33 if not username:
34 raise self.exc.AuthRequired("username & password")
35 self.session.auth = util.HTTPBasicAuth(username, password)
36
37 url = f"{self.root}/Manga/{self.groups[0]}"
38 page = self.request(url).text
39 extr = text.extract_from(page)
40
41 chapters = []
42 while True:
43 if not (cid := extr('<tr data-record="', '"')):
44 break
45 chapters.append({
46 "chapter_id": text.parse_int(cid),
47 "path": text.unescape(extr('href="', '"')),
48 "chapter_string": text.unescape(extr(">", "<")),
49 "size": text.parse_bytes(extr("<td>", "</td>")),
50 "date": self.parse_datetime_iso(extr("<td>", "</td>").strip()),
51 })
52
53 if self.config("chapter-reverse"):
54 chapters.reverse()
55
56 self.kwdict.update({
57 "manga" : text.unescape(extr('itemprop="name">', "<")),
58 "year" : text.parse_int(extr(
59 'itemprop="datePublished" content="', "-")),
60 "author": text.split_html(extr('<p class="staff', "</p>"))[1::2],
61 "genre" : text.split_html(extr("<h3>Genres</h3>", "</div>")),
62 "tags" : text.split_html(extr("<h3>Tags</h3>", "</div>")),
63 "complete": extr('span class="scanstatus">', "<").lower() == "yes",
64 })
65
66 search_chstr = text.re(
67 r"(?i)((?:v(?:ol)?\.?\s*(\d+))"
68 r"(?:\s+ch?\.?\s*(\d+)(?:-(\d+))?)?)").search
69 search_chstr_min = text.re(
70 r"(?i)(ch?\.?\s*(\d+)(?:-(\d+))?)").search
71
72 for ch in chapters:
73
74 chstr = ch["chapter_string"]
75 if match := search_chstr(chstr):
76 ch["chapter_string"], volume, chapter, end = match.groups()
77 ch["volume"] = text.parse_int(volume)
78 ch["chapter"] = text.parse_int(chapter)
79 ch["chapter_end"] = text.parse_int(end)
80 elif match := search_chstr_min(chstr):
81 ch["chapter_string"], chapter, end = match.groups()
82 ch["volume"] = 0
83 ch["chapter"] = text.parse_int(chapter)
84 ch["chapter_end"] = text.parse_int(end)
85 else:
86 ch["volume"] = ch["chapter"] = ch["chapter_end"] = 0
87
88 url = self.root + ch["path"]
89 text.nameext_from_url(url, ch)
90
91 yield Message.Directory, "", ch
92 yield Message.Url, url, ch