Debian Codegraph @

gallery_dl/extractor/komikcast.py

raw
1 # -*- coding: utf-8 -*-
2
3 # Copyright 2018-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://komikcast.li/"""
10
11 from .common import ChapterExtractor, MangaExtractor
12 from .. import text
13
14 BASE_PATTERN = (r"(?:https?://)?(?:www\.)?"
15 r"komikcast\d*\.(?:l(?:i|a|ol)|com|cz|site|mo?e)")
16
17
18 class KomikcastBase():
19 """Base class for komikcast extractors"""
20 category = "komikcast"
21 root = "https://komikcast.li"
22
23 def parse_chapter_string(self, chapter_string, data=None):
24 """Parse 'chapter_string' value and add its info to 'data'"""
25 if data is None:
26 data = {}
27
28 pattern = text.re(r"(?:(.*) Chapter )?0*(\d+)([^ ]*)(?: (?:- )?(.+))?")
29 match = pattern.match(text.unescape(chapter_string))
30 manga, chapter, data["chapter_minor"], title = match.groups()
31
32 if manga:
33 data["manga"] = manga.partition(" Chapter ")[0]
34 if title and not title.lower().startswith("bahasa indonesia"):
35 data["title"] = title.strip()
36 else:
37 data["title"] = ""
38 data["chapter"] = text.parse_int(chapter)
39 data["lang"] = "id"
40 data["language"] = "Indonesian"
41
42 return data
43
44
45 class KomikcastChapterExtractor(KomikcastBase, ChapterExtractor):
46 """Extractor for komikcast manga chapters"""
47 pattern = BASE_PATTERN + r"(/chapter/[^/?#]+/)"
48 example = "https://komikcast.li/chapter/TITLE/"
49
50 def metadata(self, page):
51 info = text.extr(page, "<title>", " - Komikcast<")
52 return self.parse_chapter_string(info)
53
54 def images(self, page):
55 readerarea = text.extr(
56 page, '<div class="main-reading-area', '</div')
57 pattern = text.re(r"<img[^>]* src=[\"']([^\"']+)")
58 return [
59 (text.unescape(url), None)
60 for url in pattern.findall(readerarea)
61 ]
62
63
64 class KomikcastMangaExtractor(KomikcastBase, MangaExtractor):
65 """Extractor for komikcast manga"""
66 chapterclass = KomikcastChapterExtractor
67 pattern = BASE_PATTERN + r"(/(?:komik/)?[^/?#]+/?)$"
68 example = "https://komikcast.li/komik/TITLE"
69
70 def chapters(self, page):
71 results = []
72 data = self.metadata(page)
73
74 for item in text.extract_iter(
75 page, '<a class="chapter-link-item" href="', '</a'):
76 url, _, chapter = item.rpartition('">Chapter')
77 chapter, sep, minor = chapter.strip().partition(".")
78 data["chapter"] = text.parse_int(chapter)
79 data["chapter_minor"] = sep + minor
80 results.append((url, data.copy()))
81 return results
82
83 def metadata(self, page):
84 """Return a dict with general metadata"""
85 manga , pos = text.extract(page, "<title>" , " - Komikcast<")
86 genres, pos = text.extract(
87 page, 'class="komik_info-content-genre">', "</span>", pos)
88 author, pos = text.extract(page, ">Author:", "</span>", pos)
89 mtype , pos = text.extract(page, ">Type:" , "</span>", pos)
90
91 return {
92 "manga": text.unescape(manga),
93 "genres": text.split_html(genres),
94 "author": text.remove_html(author),
95 "type": text.remove_html(mtype),
96 }