Debian Codegraph @

gallery_dl/extractor/rawkuma.py

raw
1 # -*- coding: utf-8 -*-
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License version 2 as
5 # published by the Free Software Foundation.
6
7 """Extractors for https://rawkuma.net/"""
8
9 from .common import MangaExtractor, ChapterExtractor
10 from .. import text
11
12 BASE_PATTERN = r"(?:https?://)?rawkuma\.(?:net|com)"
13
14
15 class RawkumaBase():
16 """Base class for rawkuma extractors"""
17 category = "rawkuma"
18 root = "https://rawkuma.net"
19
20
21 class RawkumaChapterExtractor(RawkumaBase, ChapterExtractor):
22 """Extractor for manga chapters from rawkuma.net"""
23 archive_fmt = "{chapter_id}_{page}"
24 pattern = BASE_PATTERN + r"(/manga/[^/?#]+/chapter-\d+(?:.\d+)?\.(\d+))"
25 example = "https://rawkuma.net/manga/7TITLE/chapter-123.321"
26
27 def __init__(self, match):
28 url = f"{self.root}/{match[1]}/"
29 ChapterExtractor.__init__(self, match, url)
30
31 def metadata(self, page):
32 manga, _, chapter = text.extr(
33 page, '<title>', "<").rpartition(" Chapter ")
34 chapter, sep, minor = chapter.partition(" &#8211; ")[0].partition(".")
35
36 return {
37 "manga" : text.unescape(manga),
38 "manga_id" : text.parse_int(text.extr(page, "manga_id=", "&")),
39 "chapter" : text.parse_int(chapter),
40 "chapter_minor": sep + minor,
41 "chapter_id" : text.parse_int(self.groups[-1]),
42 # "title" : text.unescape(title),
43 "date" : self.parse_datetime_iso(text.extr(
44 page, 'datetime="', '"')),
45 "lang" : "ja",
46 "language" : "Japanese",
47 }
48
49 def images(self, page):
50 return [(url, None) for url in text.extract_iter(
51 page, "<img src='", "'")]
52
53
54 class RawkumaMangaExtractor(RawkumaBase, MangaExtractor):
55 """Extractor for manga from rawkuma.net"""
56 chapterclass = RawkumaChapterExtractor
57 pattern = BASE_PATTERN + r"/manga/([^/?#]+)"
58 example = "https://rawkuma.net/manga/TITLE/"
59
60 def __init__(self, match):
61 url = f"{self.root}/manga/{match[1]}/"
62 MangaExtractor.__init__(self, match, url)
63
64 def chapters(self, page):
65 manga = text.unescape(text.extr(page, "<title>", " &#8211; "))
66 manga_id = text.parse_int(text.extr(page, "manga_id=", "&"))
67
68 url = self.root + "/wp-admin/admin-ajax.php"
69 params = {
70 "manga_id": manga_id,
71 "page" : "1",
72 "action" : "chapter_list",
73 }
74 headers = {
75 "HX-Request" : "true",
76 "HX-Trigger" : "chapter-list",
77 "HX-Target" : "chapter-list",
78 "HX-Current-URL": self.page_url,
79 "Sec-Fetch-Dest": "empty",
80 "Sec-Fetch-Mode": "cors",
81 "Sec-Fetch-Site": "same-origin",
82 }
83 html = self.request(url, params=params, headers=headers).text
84
85 results = []
86 for url in text.extract_iter(html, '<a href="', '"'):
87 info = url[url.rfind("-")+1:-1]
88 chapter, _, chapter_id = info.rpartition(".")
89 chapter, sep, minor = chapter.partition(".")
90
91 results.append((url, {
92 "manga" : manga,
93 "manga_id" : manga_id,
94 "chapter" : text.parse_int(chapter),
95 "chapter-minor": sep + minor,
96 "chapter_id" : text.parse_int(chapter_id),
97 }))
98 return results