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

Commit 631e898

Browse files
committed
Fix RainOfSnow
1 parent 207e398 commit 631e898

File tree

2 files changed

+54
-32
lines changed

2 files changed

+54
-32
lines changed

‎src/RainOfSnow/RainOfSnow.ts

+38-16
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.2.0",
18+
version: "1.3.0",
1919
name: "RainOfSnow",
2020
author: "PythonCoderAS",
2121
authorWebsite: "https://github.com/PythonCoderAS",
@@ -34,30 +34,52 @@ export class RainOfSnow extends Source {
3434
}
3535

3636
async getHomePageSections(sectionCallback: (section: HomeSection) => void): Promise<void> {
37+
const options: Request = createRequestObject({
38+
url: `${BASE}`,
39+
method: 'GET'
40+
});
41+
let response = await this.requestManager.schedule(options, 1);
42+
let $ = this.cheerio.load(response.data);
43+
let tiles: MangaTile[] = this.parser.parseMangaList($, BASE, $($("div.row").toArray()[2]));
3744
sectionCallback(createHomeSection({
38-
id: "1",
39-
items: (await this.getWebsiteMangaDirectory(null)).results,
40-
title: "All Comics"
45+
id: "comics",
46+
items: tiles,
47+
title: "Popular Comics",
48+
view_more: true
4149
}));
4250
}
4351

44-
async doGetWebsiteMangaDirectory(page: number = 1){
52+
async getWebsiteMangaDirectory(metadata: any): Promise<PagedResults> {
53+
if (typeof metadata !== "object" && metadata !== null){
54+
metadata = {page: metadata};
55+
} else if (metadata === null){
56+
metadata = {};
57+
}
58+
let page = 1;
59+
if (metadata.page){
60+
page = metadata.page;
61+
}
62+
if (page === null){
63+
return createPagedResults({results: []});
64+
}
4565
const options: Request = createRequestObject({
46-
url: `${BASE}/comics-library/page/${page}`,
66+
url: `${BASE}/comics/page/${page}`,
4767
method: 'GET'
4868
});
4969
let response = await this.requestManager.schedule(options, 1);
5070
let $ = this.cheerio.load(response.data);
5171
let tiles: MangaTile[] = this.parser.parseMangaList($, BASE);
52-
if ($("a.next").length !== 0){
53-
tiles = tiles.concat(await this.doGetWebsiteMangaDirectory(page+1))
72+
let newPage: number | null = page + 1;
73+
if ($("a.next").length === 0){
74+
newPage = null;
75+
}
76+
metadata.page = newPage
77+
if (newPage === null){
78+
return createPagedResults({results: []});
5479
}
55-
return tiles;
56-
}
57-
58-
async getWebsiteMangaDirectory(metadata: any): Promise<PagedResults> {
5980
return createPagedResults({
60-
results: await this.doGetWebsiteMangaDirectory()
81+
results: tiles,
82+
metadata: metadata
6183
});
6284
}
6385

@@ -97,9 +119,9 @@ export class RainOfSnow extends Source {
97119
}
98120

99121
async searchRequest(query: SearchRequest, metadata: any): Promise<PagedResults> {
100-
let url = `${BASE}/?serchfor=comics`
122+
let url = `${BASE}/`
101123
if (query.title){
102-
url += `&s=${query.title}`
124+
url += `?s=${query.title}`
103125
}
104126
const options: Request = createRequestObject({
105127
url: url,
@@ -108,7 +130,7 @@ export class RainOfSnow extends Source {
108130
let response = await this.requestManager.schedule(options, 1);
109131
let $ = this.cheerio.load(response.data);
110132
return createPagedResults({
111-
results: this.parser.parseSearchResult($, BASE)
133+
results: this.parser.parseMangaList($, BASE)
112134
});
113135
}
114136

‎src/RainOfSnow/RainOfSnowParser.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import {Chapter, LanguageCode, Manga, MangaStatus, MangaTile, Tag} from "paperba
22

33
export class RainOfSnowParser {
44

5-
parseMangaList($: CheerioStatic, base: string) {
5+
parseMangaList($: CheerioStatic, base: string, filterElement: Cheerio | null = null) {
6+
if (filterElement === null){
7+
filterElement = $.root()
8+
}
69
const mangaTiles: MangaTile[] = [];
7-
$("ul.boxhover1 li").map(((index, element) => {
8-
const link = $("h4 a", element).first();
10+
$("div.col-xs-6.col-md-3.col-lg-2", filterElement).map(((index, element) => {
11+
const link = $("h3 a", element).first();
912
const linkId = link.attr("href");
1013
const imgSrc = $("a img", element).first().attr("src");
11-
if (linkId) {
14+
if (linkId && linkId.includes("comic")) {
1215
mangaTiles.push(createMangaTile({
1316
id: linkId.replace(`${base}/comic/`, "").slice(0, -1),
1417
image: imgSrc || "",
@@ -33,16 +36,18 @@ export class RainOfSnowParser {
3336

3437
parseChapterList($: CheerioStatic, mangaId: string, base: string) {
3538
const chapters: Chapter[] = [];
36-
$("ul.chapter1 li").map((index, element) => {
39+
$("div#chapter li").map((index, element) => {
3740
const link = $("a", element).first();
3841
const linkId = link.attr("href");
3942
if (linkId) {
43+
const chapParts = link.text().split(".");
4044
chapters.push(createChapter({
41-
chapNum: Number(link.text().split(".")[0]),
45+
chapNum: Number(chapParts[0]),
4246
id: linkId.replace(base + "/comic_chapters/", ""),
4347
langCode: LanguageCode.ENGLISH,
4448
mangaId: mangaId,
4549
time: new Date($("small", element).first().text()),
50+
name: chapParts[1] || undefined
4651
}))
4752
}
4853
})
@@ -56,14 +61,9 @@ export class RainOfSnowParser {
5661
}
5762

5863
parseManga($: CheerioStatic, mangaId: string, base: string) {
59-
const items = $("ul.rat1 li");
6064
const tagList: Tag[] = [];
61-
let summary: string = ""
62-
$("div.summery div.text p").map(((index, element) => {
63-
summary += $(element).text() + "\n"
64-
}))
65-
summary = summary.trim();
66-
$("a[rel=\"tag\"]", items).map(((index, element) => {
65+
const summary: string = $("div#synop").text().replace(/\s{2,}/, "").trim();
66+
$("a[rel=\"tag\"]", $("ul.vbtcolor1").first()).map(((index, element) => {
6767
if ("attribs" in element) {
6868
tagList.push(createTag({
6969
id: element.attribs["href"].replace(`${base}/tag/`, "").slice(0, -1),
@@ -73,13 +73,13 @@ export class RainOfSnowParser {
7373
}))
7474
const chapterList = this.parseChapterList($, mangaId, base)
7575
const mangaObj: Manga = {
76-
author: $(".n2", items.first()).text(),
76+
author: $("small", $("ul.vbtcolor1 li").first()).text().trim(),
7777
desc: summary,
7878
id: mangaId,
79-
image: $("div.imgbox img").first().attr("src") || "",
79+
image: $("img", $("div.container div.row").first()).first().attr("src") || "",
8080
rating: 0,
8181
status: MangaStatus.ONGOING,
82-
titles: [$("div.container h3").first().text()],
82+
titles: [$("div.text h2").first().text()],
8383
tags: [createTagSection({
8484
id: "1",
8585
label: "1",

0 commit comments

Comments
 (0)