| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
# Copyright 2026 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://batcave.biz/""" |
| 10 |
|
| 11 |
from .common import ChapterExtractor, MangaExtractor |
| 12 |
from .. import text, util |
| 13 |
|
| 14 |
BASE_PATTERN = r"(?:https?://)?(?:www\.)?batcave\.biz" |
| 15 |
|
| 16 |
|
| 17 |
class BatcaveBase(): |
| 18 |
"""Base class for batcave extractors""" |
| 19 |
category = "batcave" |
| 20 |
root = "https://batcave.biz" |
| 21 |
|
| 22 |
def _extract_window_data(self, html): |
| 23 |
data = text.extr(html, ">window.__DATA__ = {", "};</script>") |
| 24 |
return util.json_loads(f"{{{data}}}") |
| 25 |
|
| 26 |
|
| 27 |
class BatcaveIssueExtractor(BatcaveBase, ChapterExtractor): |
| 28 |
"""Extractor for batcave comic issues""" |
| 29 |
subcategory = "issue" |
| 30 |
directory_fmt = ("{category}", "{comic}", "{issue|issue_string:>03}") |
| 31 |
filename_fmt = "{comic}_{issue|issue_string:>03}_{page:>03}.{extension}" |
| 32 |
archive_fmt = "{issue_id}_{page}" |
| 33 |
pattern = BASE_PATTERN + r"(/reader/\d+/\d+)" |
| 34 |
example = "https://batcave.biz/reader/12345/123" |
| 35 |
|
| 36 |
def metadata(self, page): |
| 37 |
self.data = data = self._extract_window_data(page) |
| 38 |
|
| 39 |
comic = data["post_title"] |
| 40 |
comic_id = data["news_id"] |
| 41 |
chapter_id = data["chapter_id"] |
| 42 |
|
| 43 |
for chapter in data["chapters"]: |
| 44 |
if chapter.get("id") == chapter_id: |
| 45 |
if issue := chapter.get("title"): |
| 46 |
_, sep, inum = issue.rpartition(" Issue #") |
| 47 |
if sep: |
| 48 |
issue = "Issue #" + inum |
| 49 |
inum = text.parse_int(inum) |
| 50 |
else: |
| 51 |
issue = issue[issue.find(")")+2:] |
| 52 |
inum = 0 |
| 53 |
break |
| 54 |
else: |
| 55 |
inum = 0 |
| 56 |
issue = "" |
| 57 |
|
| 58 |
return { |
| 59 |
"comic" : comic, |
| 60 |
"comic_id": comic_id, |
| 61 |
"issue" : inum, |
| 62 |
"issue_id": chapter_id, |
| 63 |
"issue_string": issue, |
| 64 |
"lang" : text.extr(page, '"inLanguage":"', '"'), |
| 65 |
"date" : self.parse_datetime_iso(text.extr( |
| 66 |
page, '"datePublished":"', '"')) |
| 67 |
} |
| 68 |
|
| 69 |
def images(self, page): |
| 70 |
return [(url, None) for url in self.data["images"]] |
| 71 |
|
| 72 |
|
| 73 |
class BatcaveComicExtractor(BatcaveBase, MangaExtractor): |
| 74 |
"""Extractor for batcave comics""" |
| 75 |
subcategory = "comic" |
| 76 |
chapterclass = BatcaveIssueExtractor |
| 77 |
pattern = BASE_PATTERN + r"(/\d+(?:-[\w-]*)?\.html)" |
| 78 |
example = "https://batcave.biz/12345-SLUG.html" |
| 79 |
|
| 80 |
def chapters(self, page): |
| 81 |
data = self._extract_window_data(page) |
| 82 |
base = f"{self.root}/reader/{data['news_id']}/" |
| 83 |
return [ |
| 84 |
(base + str(chapter["id"]), chapter) |
| 85 |
for chapter in data["chapters"] |
| 86 |
] |