| 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://kaliscan.me/""" |
| 8 |
|
| 9 |
from .common import ChapterExtractor, MangaExtractor |
| 10 |
from .. import text |
| 11 |
|
| 12 |
BASE_PATTERN = r"(?:https?://)?kaliscan\.me" |
| 13 |
|
| 14 |
|
| 15 |
class KaliscanBase(): |
| 16 |
"""Base class for kaliscan extractors""" |
| 17 |
category = "kaliscan" |
| 18 |
root = "https://kaliscan.me" |
| 19 |
|
| 20 |
def manga_data(self, manga_slug, page=None): |
| 21 |
if page is None: |
| 22 |
url = f"{self.root}/manga/{manga_slug}" |
| 23 |
page = self.request(url).text |
| 24 |
extr = text.extract_from(page) |
| 25 |
|
| 26 |
manga_id = text.parse_int(extr("bookId =", ";")) |
| 27 |
title = text.unescape(extr("<h1>", "<")) |
| 28 |
if alt_titles := extr("<h2>", "<"): |
| 29 |
alt_titles = [t.strip() for t in alt_titles.split(",")] |
| 30 |
else: |
| 31 |
alt_titles = () |
| 32 |
|
| 33 |
author = text.remove_html(extr( |
| 34 |
"Authors :</strong>", "</p>")) |
| 35 |
status = text.remove_html(extr( |
| 36 |
"Status :</strong>", "</p>")) |
| 37 |
genres = [g.strip(" ,") for g in text.split_html(extr( |
| 38 |
"Genres :</strong>", "</p>"))] |
| 39 |
|
| 40 |
if descr := extr('class="content"', '<div class="readmore"'): |
| 41 |
descr = text.remove_html(descr[descr.find(">")+1:]).strip() |
| 42 |
else: |
| 43 |
descr = "" |
| 44 |
|
| 45 |
return { |
| 46 |
"manga" : title, |
| 47 |
"manga_id" : manga_id, |
| 48 |
"manga_slug" : manga_slug, |
| 49 |
"manga_titles": alt_titles, |
| 50 |
"author" : author, |
| 51 |
"status" : status, |
| 52 |
"genres" : genres, |
| 53 |
"description" : descr, |
| 54 |
"lang" : "en", |
| 55 |
"language" : "English", |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
class KaliscanChapterExtractor(KaliscanBase, ChapterExtractor): |
| 60 |
"""Extractor for kaliscan manga chapters""" |
| 61 |
pattern = BASE_PATTERN + r"(/manga/([\w-]+)/chapter-([\d.]+))" |
| 62 |
example = "https://kaliscan.me/manga/ID-MANGA/chapter-1" |
| 63 |
|
| 64 |
def metadata(self, page): |
| 65 |
extr = text.extract_from(page) |
| 66 |
|
| 67 |
manga_id = text.parse_int(extr("bookId =", ";")) |
| 68 |
extr("bookSlug =", ";") |
| 69 |
chapter_id = text.parse_int(extr("chapterId =", ";")) |
| 70 |
extr("chapterSlug =", ";") |
| 71 |
chapter_number = extr("chapterNumber =", ";").strip(' "\'') |
| 72 |
|
| 73 |
chapter, sep, minor = chapter_number.partition(".") |
| 74 |
|
| 75 |
data = { |
| 76 |
**self.cache(self.manga_data, self.groups[1]), |
| 77 |
"chapter" : text.parse_int(chapter), |
| 78 |
"chapter_minor": sep + minor, |
| 79 |
"chapter_id" : chapter_id, |
| 80 |
} |
| 81 |
if manga_id and not data["manga_id"]: |
| 82 |
data["manga_id"] = manga_id |
| 83 |
return data |
| 84 |
|
| 85 |
def images(self, page): |
| 86 |
images_str = text.extr(page, 'var chapImages = "', '"') |
| 87 |
if not images_str: |
| 88 |
return () |
| 89 |
return [ |
| 90 |
(url, None) |
| 91 |
for url in (u.strip() for u in images_str.split(",")) |
| 92 |
if url |
| 93 |
] |
| 94 |
|
| 95 |
|
| 96 |
class KaliscanMangaExtractor(KaliscanBase, MangaExtractor): |
| 97 |
"""Extractor for kaliscan manga""" |
| 98 |
chapterclass = KaliscanChapterExtractor |
| 99 |
pattern = BASE_PATTERN + r"(/manga/([\w-]+))/?$" |
| 100 |
example = "https://kaliscan.me/manga/ID-MANGA" |
| 101 |
|
| 102 |
def chapters(self, page): |
| 103 |
data = self.cache(self.manga_data, self.groups[1], page) |
| 104 |
|
| 105 |
chapter_list = text.extr(page, 'id="chapter-list">', '</ul>') |
| 106 |
if not chapter_list: |
| 107 |
return () |
| 108 |
|
| 109 |
results = [] |
| 110 |
for li in text.extract_iter(chapter_list, "<li", "</li>"): |
| 111 |
url = text.extr(li, 'href="', '"') |
| 112 |
if not url: |
| 113 |
continue |
| 114 |
if url[0] == "/": |
| 115 |
url = self.root + url |
| 116 |
|
| 117 |
chapter, sep, minor = url.rpartition( |
| 118 |
"/chapter-")[2].partition(".") |
| 119 |
|
| 120 |
results.append((url, { |
| 121 |
"chapter" : text.parse_int(chapter), |
| 122 |
"chapter_minor": sep + minor, |
| 123 |
**data, |
| 124 |
})) |
| 125 |
return results |