Skip to content
This repository was archived by the owner on Nov 20, 2021. It is now read-only.

Commit 4038bef

Browse files
committed
Doing (get more)s (Fix #5)
1 parent 3a9c570 commit 4038bef

File tree

2 files changed

+61
-6
lines changed

2 files changed

+61
-6
lines changed

‎src/RainOfSnow/RainOfSnow.ts

+30-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const BASE = "https://rainofsnow.com"
1515

1616
export const RainOfSnowInfo: SourceInfo = {
1717
icon: "icon.png",
18-
version: "1.3.3",
18+
version: "1.4.0",
1919
name: "RainOfSnow",
2020
author: "PythonCoderAS",
2121
authorWebsite: "https://github.com/PythonCoderAS",
@@ -95,11 +95,39 @@ export class RainOfSnow extends Source {
9595
});
9696
let response = await this.requestManager.schedule(options, 1);
9797
let $ = this.cheerio.load(response.data);
98+
let more: boolean = true;
99+
let pages: string[] = this.parser.parsePages($, $("div.bb-item[style=\"display: block;\"]").first().toArray()[0])
100+
let more_data = this.parser.parseMoreData($);
101+
let offset;
102+
if (!more_data){
103+
more = false;
104+
} else {
105+
offset = more_data.offset;
106+
}
107+
while (more){
108+
const ajax: Request = createRequestObject({
109+
url: `${BASE}/wp-admin/admin-ajax.php`,
110+
method: 'POST',
111+
data: Object.entries(this.urlEncodeObject({
112+
action: "my_repeater_show_more",
113+
post_id: Number(more_data?.post_id),
114+
offset: Number(offset),
115+
nonce: more_data?.nonce
116+
})).map(e => e.join('=')).join('&')
117+
// This is important because otherwise it gives me a 400, and I don't know why
118+
});
119+
let ajaxResponse = await this.requestManager.schedule(ajax, 1);
120+
let ajaxData = typeof ajaxResponse.data === "string" ? JSON.parse(ajaxResponse.data) : ajaxResponse.data
121+
let $ajax = this.cheerio.load(ajaxData.content);
122+
pages = pages.concat(this.parser.parsePages($ajax, $ajax.root().toArray()[0]))
123+
more = ajaxData.more;
124+
offset = ajaxData.offset;
125+
}
98126
return createChapterDetails({
99127
id: chapterId,
100128
longStrip: true,
101129
mangaId: mangaId,
102-
pages: this.parser.parsePages($)
130+
pages: pages
103131
})
104132
}
105133

‎src/RainOfSnow/RainOfSnowParser.ts

+31-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import {Chapter, LanguageCode, Manga, MangaStatus, MangaTile, Tag} from "paperback-extensions-common";
22

3+
interface morePageData {
4+
post_id: string,
5+
offset: string,
6+
nonce: string
7+
}
8+
39
export class RainOfSnowParser {
410

511
decodeHTMLEntity(str: string): string {
@@ -30,11 +36,32 @@ export class RainOfSnowParser {
3036
return mangaTiles;
3137
}
3238

33-
parsePages($: CheerioStatic) {
39+
private static repeater_field_regex(field_name: string){
40+
return new RegExp(`(var|let|const) my_repeater_field_${field_name}\\s*=\\s*["'\`]?([^"'\`\\n;]+)["'\`]?`, "i")
41+
}
42+
43+
parseMoreData($: CheerioStatic): morePageData | null{
44+
const data = $("div.bb-item[style=\"display: block;\"] script").first().html()
45+
if (data){
46+
const post_id = data.match(RainOfSnowParser.repeater_field_regex("post_id"))
47+
const offset = data.match(RainOfSnowParser.repeater_field_regex("offset"))
48+
const nonce = data.match(RainOfSnowParser.repeater_field_regex("nonce"))
49+
if (post_id && offset && nonce){
50+
return {
51+
post_id: post_id[2],
52+
offset: offset[2],
53+
nonce: nonce[2]
54+
}
55+
}
56+
}
57+
return null;
58+
}
59+
60+
parsePages($: CheerioStatic, element: CheerioElement) {
3461
const pages: string[] = [];
35-
$("div.bb-item[style=\"display: block;\"] img").map((index, element) => {
36-
if ("attribs" in element && element.attribs["src"]){
37-
pages.push(element.attribs["src"])
62+
$("img", element).map((index, element1) => {
63+
if ("attribs" in element1 && element1.attribs["src"]){
64+
pages.push(element1.attribs["src"])
3865
}
3966
});
4067
return pages;

0 commit comments

Comments
 (0)