-
-
Notifications
You must be signed in to change notification settings - Fork 300
/
steambun.py
58 lines (45 loc) · 1.82 KB
/
steambun.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# -*- coding: utf-8 -*-
import logging
from lncrawl.core.crawler import Crawler
logger = logging.getLogger(__name__)
class SteambunCrawler(Crawler):
base_url = "https://steambunlightnovel.com/"
def read_novel_info(self):
logger.debug("Visiting %s", self.novel_url)
soup = self.get_soup(self.novel_url)
possible_title = soup.select_one("h1.entry-title")
assert possible_title, "No novel title"
self.novel_title = possible_title.text
logger.info("Novel title: %s", self.novel_title)
self.novel_author = "by SteamBun Translations"
logger.info("Novel author: %s", self.novel_author)
# Site does not list covers.
volumes = set([])
for a in reversed(
soup.select('div.w4pl-inner li a[href*="steambunlightnovel.com"]')
):
title = a.text.strip()
chapter_id = len(self.chapters) + 1
volume_id = 1 + (chapter_id - 1) // 100
volumes.add(volume_id)
self.chapters.append(
{
"id": chapter_id,
"volume": volume_id,
"title": title,
"url": a["href"],
}
)
self.chapters.sort(key=lambda x: x["id"])
self.volumes = [{"id": x, "title": ""} for x in volumes]
def download_chapter_body(self, chapter):
soup = self.get_soup(chapter["url"])
content = soup.select_one("div.entry-content")
assert content, "No chapter content"
self.cleaner.clean_contents(content)
body = content.select("p")
body = [str(p) for p in body if self.should_take(p)]
return "<p>" + "</p><p>".join(body) + "</p>"
def should_take(self, p):
txt = p.text.strip().lower()
return txt and txt != "advertisement"