Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes source teanovel.com #2478

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 23 additions & 32 deletions sources/en/t/teanovel.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@


class TeaNovelCrawler(Crawler):
base_url = ["https://www.teanovel.com/", "https://www.teanovel.net/"]
base_url = "https://www.teanovel.com"

def initialize(self):
self.init_executor(
workers=4
)

def read_novel_info(self):
soup = self.get_soup(self.novel_url)
Expand All @@ -22,40 +27,26 @@ def read_novel_info(self):

next_data = json.loads(script_tag.get_text())

build_id = next_data["buildId"]
novel_data = next_data["props"]["pageProps"]["novelData"]["novel"]
novel_data = next_data["props"]["pageProps"]["novel"]

self.novel_title = novel_data["name"]
self.novel_author = novel_data["author"]

# img_tag = soup.select_one("main img[src*='_next/']")
# if isinstance(img_tag, Tag):
# self.novel_cover = self.absolute_url(img_tag["src"])

slug = novel_data["slug"]

toc_url = f"{self.home_url}api/chapters/{slug}?slug={slug}&orderBy=asc"
toc_json = self.get_json(toc_url)

while True:
for chapter in toc_json["data"]:
chapter_id = len(self.chapters) + 1
self.chapters.append(
{
"id": chapter_id,
"title": f"Chapter {chapter_id}: {chapter['title']}",
"url": (
f"{self.home_url}_next/data/{build_id}/novel/{slug}/{chapter['slug']}.json"
),
}
)
if "nextId" in toc_json:
toc_json = self.get_json(toc_url + f"&nextId={toc_json['nextId']}")
else:
break
img_tag = soup.select_one("main img[src*='_next/']")
if isinstance(img_tag, Tag):
self.novel_cover = self.absolute_url(img_tag["src"])

chapters = self.get_soup(self.novel_url + "/chapter-list").select("a.border-b")
for chapter in chapters:
chapter_id = len(self.chapters) + 1
self.chapters.append(
{
"id": chapter_id,
"title": chapter.select_one("p").get_text(strip=True),
"url": self.absolute_url(chapter["href"]),
}
)

def download_chapter_body(self, chapter):
chapter_json = self.get_json(chapter["url"])
chapter_data = chapter_json["pageProps"]["chapterData"]

return chapter_data["content"].replace("\n", "<br>")
chapter = self.get_soup(chapter["url"])
return self.cleaner.extract_contents(chapter.select_one("div.prose"))