-
-
Notifications
You must be signed in to change notification settings - Fork 305
/
flyinglines.py
101 lines (86 loc) · 3.53 KB
/
flyinglines.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
# -*- coding: utf-8 -*-
import logging
from datetime import datetime
from hashlib import md5
from urllib.parse import urlparse
from lncrawl.core.crawler import Crawler
logger = logging.getLogger(__name__)
class FlyingLinesCrawler(Crawler):
base_url = "https://www.flying-lines.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(".novel-info .title h2")
assert possible_title, "No novel title"
self.novel_title = possible_title.text
logger.info("Novel title: %s", self.novel_title)
self.novel_cover = self.absolute_url(
soup.select_one(".novel .novel-thumb img")["data-src"]
)
logger.info("Novel cover: %s", self.novel_cover)
authors = [x.text.strip() for x in soup.select(".novel-info ul.profile li")]
self.novel_author = ", ".join(authors)
logger.info("%s", self.novel_author)
self.novel_id = urlparse(self.novel_url).path.split("/")[2]
logger.info("Novel id: %s", self.novel_id)
for a in soup.select("ul.volume-chapters li a"):
chap_id = int(a["data-chapter-number"])
vol_id = 1 + (chap_id - 1) // 100
if len(self.chapters) % 100 == 0:
self.volumes.append({"id": vol_id})
self.chapters.append(
{
"id": chap_id,
"volume": vol_id,
"title": a.text.strip(),
"url": self.absolute_url(a["href"]),
}
)
def download_chapter_body(self, chapter):
# How to get the key?
# - check `app.js` (Sources/cdn.flying-lines.com/front/../js/app.js)
# - locate the mapped value of `./what` (e.g.: "./what": 57,)
# - locate the mapped valued function. (e.g: search `57:`)
# - Copy key from the function. (return "4ec781a70c3f11ea9b46f23c918347ac")
key = "4ec781a70c3f11ea9b46f23c918347ac"
# How to find the sign generation method?
# - check `app.js`
# - search the mapped value of `./nobody`
# - locate the mapped valued function. (e.g: search `48:`)
time = str(int(datetime.now().timestamp() * 1000))
sign = "chapterNum=%s&novelPath=%s&time=%s&webdriver=0&key=%s" % (
chapter["id"],
self.novel_id,
time,
key,
)
sign = md5(sign.encode("utf8")).hexdigest()
# How to generate the URL?
# - check `app.js`
# - search for `e.data.meta`
url = (
"%s/h5/novel/%s/%s?accessToken=&isFirstEnter=1&webdriver=0&time=%s&sign=%s"
)
url = url % (self.home_url.strip("/"), self.novel_id, chapter["id"], time, sign)
logger.info("Downloading %s", url)
data = self.post_json(
url,
headers={
"Origin": self.home_url.strip("/"),
"Referer": self.home_url.strip("/") + "/novel/" + self.novel_id,
},
)
# How to find the decryption method?
# - check `app.js`
# - search for `TurnCharIntoString:` function
encrypted = data["data"]["content"]
n = data["data"]["nowTime"]
even_shift = int(n[-1])
odd_shift = int(n[-2])
content = ""
for i, ch in enumerate(encrypted):
if i % 2 == 0:
content += chr(ord(ch) - even_shift)
else:
content += chr(ord(ch) - odd_shift)
return content