-
-
Notifications
You must be signed in to change notification settings - Fork 307
/
Copy pathlnmtlfr.py
106 lines (86 loc) · 3.55 KB
/
lnmtlfr.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import logging
from lncrawl.core.crawler import Crawler
logger = logging.getLogger(__name__)
class Lnmtlfr(Crawler):
base_url = ["https://lnmtlfr.com/"]
has_manga = False
has_mtl = True
def search_novel(self, query):
query = query.replace(" ", "+")
soup = self.get_soup(f"https://lnmtlfr.com/?s={query}&post_type=wp-manga")
result = []
for novel in soup.find_all("div", {"class": "row c-tabs-item__content"}):
title = novel.find("div", {"class": "post-title"}).find("a")
authors = (
novel.find(
"div",
{"class": lambda x: x.startswith("post-content_item mg_author")},
)
.find("div", {"class": "summary-content"})
.find_all("a")
)
author_names = ", ".join([a.text for a in authors])
result.append(
{
"title": title.text,
"url": title.get("href"),
"info": f"Author{'s' if len(authors) > 1 else ''}: {author_names}",
}
)
return result
def read_novel_info(self):
soup = self.get_soup(self.novel_url)
self.novel_title = (
soup.find("div", {"class": "post-title"}).find("h1").text.strip()
)
self.novel_cover = self.absolute_url(
soup.find("div", {"class": "summary_image"}).find("img").get("src")
)
self.novel_synopsis = self.cleaner.extract_contents(soup.find("div", {"class": "summary__content"}).find("p"))
self.language = "fr"
self.novel_author = ", ".join(
[
e.text.strip()
for e in soup.find("div", {"class": "author-content"}).find_all("a")
]
)
# Chapter are recuperated from a post request.
id = soup.find("input", {"class": "rating-post-id"}).get("value")
url = "https://lnmtlfr.com/wp-admin/admin-ajax.php"
data = f"action=manga_get_chapters&manga={id}"
resp = self.submit_form(url, data=data)
soup = self.make_soup(resp)
list_vol = soup.find_all("ul", {"class": "sub-chap list-chap"})
if list_vol:
self.volumes = []
for vol in reversed(list_vol):
vol_id = len(self.volumes) + 1
self.volumes.append({"id": vol_id})
list_chap = vol.find_all("li")
for chap in reversed(list_chap):
chap_id = len(self.chapters) + 1
self.chapters.append(
{
"id": chap_id,
"volume": vol_id,
"title": chap.find("a").text,
"url": self.absolute_url(chap.find("a").get("href")),
}
)
else:
self.volumes = [{"id": 1}]
list_chap = soup.find_all("li")
for chap in reversed(list_chap):
chap_id = len(self.chapters) + 1
self.chapters.append(
{
"id": chap_id,
"volume": 1,
"title": chap.find("a").text,
"url": self.absolute_url(chap.find("a").get("href")),
}
)
def download_chapter_body(self, chapter):
soup = self.get_soup(chapter["url"])
content = soup.find("div", {"class": "text-left"})
return self.cleaner.extract_contents(content)