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

Commit 2a12325

Browse files
committed
VoidScans fixes
1 parent d220999 commit 2a12325

File tree

3 files changed

+63
-19
lines changed

3 files changed

+63
-19
lines changed

src/VoidScans/VoidScans.ts

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const BASE = "https://voidscans.net"
1515

1616
export const VoidScansInfo: SourceInfo = {
1717
icon: "icon.svg",
18-
version: "1.2.1",
18+
version: "1.3.0",
1919
name: "VoidScans",
2020
author: "PythonCoderAS",
2121
authorWebsite: "https://github.com/PythonCoderAS",
@@ -53,25 +53,14 @@ export class VoidScans extends Source {
5353
});
5454
}
5555

56-
async getChapterPage(mangaId: string, chapterId: string, page: number = 1): Promise<string | null>{
56+
async getChapterDetails(mangaId: string, chapterId: string): Promise<ChapterDetails> {
5757
const options: Request = createRequestObject({
58-
url: `${BASE}/read/${mangaId}/${chapterId}/${page}`,
58+
url: `${BASE}/read/${mangaId}/${chapterId}`,
5959
method: 'GET'
6060
});
6161
let response = await this.requestManager.schedule(options, 1);
6262
let $ = this.cheerio.load(response.data);
63-
return this.parser.parsePage($)
64-
}
65-
66-
async getChapterDetails(mangaId: string, chapterId: string): Promise<ChapterDetails> {
67-
const pages: string[] = [];
68-
let page = await this.getChapterPage(mangaId, chapterId);
69-
let num = 2;
70-
while (page && !pages.includes(page)){
71-
pages.push(page)
72-
page = await this.getChapterPage(mangaId, chapterId, num);
73-
num++;
74-
}
63+
const pages = this.parser.parsePages($)
7564
return createChapterDetails({
7665
id: chapterId,
7766
longStrip: true,
@@ -119,8 +108,14 @@ export class VoidScans extends Source {
119108

120109

121110
async filterUpdatedManga(mangaUpdatesFoundCallback: (updates: MangaUpdates) => void, time: Date, ids: string[]): Promise<void> {
111+
const options: Request = createRequestObject({
112+
url: `${BASE}`,
113+
method: 'GET'
114+
});
115+
let response = await this.requestManager.schedule(options, 1);
116+
let $ = this.cheerio.load(response.data);
122117
mangaUpdatesFoundCallback(createMangaUpdates({
123-
ids: ids
118+
ids: this.parser.parseUpdatedManga($, BASE, time)
124119
}));
125120
}
126121
}

src/VoidScans/VoidScansParser.ts

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class VoidScansParser {
1010
mangaTiles.push(createMangaTile({
1111
id: linkId.replace(`${base}/library/`, ""),
1212
title: createIconText({
13-
text: ""
13+
text: $("h2", element).text()
1414
}),
1515
image: $("img", element).attr("src") || "",
1616
primaryText: createIconText({
@@ -22,8 +22,50 @@ export class VoidScansParser {
2222
return mangaTiles;
2323
}
2424

25-
parsePage($: CheerioStatic): string | null {
26-
return $("img").attr("src") || null;
25+
parseUpdatedManga($: CheerioStatic, base: string, dateToCheck: Date){
26+
const ids: string[] = [];
27+
$("div.col").map((index, element) => {
28+
const link = $("a.btn", element);
29+
const linkId = link.attr("href");
30+
if (linkId){
31+
const dateUpdated = $("small.text-muted").text();
32+
const parts = dateUpdated.split(" ");
33+
if (parts.length === 2){
34+
const date = parts[0];
35+
const dateParts = date.split("/");
36+
let day = 0, month = 0, year = 0;
37+
if (dateParts.length === 3){
38+
year = Number(dateParts[0]);
39+
month = Number(dateParts[1]) - 1;
40+
day = Number(dateParts[2]);
41+
}
42+
const time = parts[1];
43+
const timeParts = time.split("/");
44+
let second = 0, minute = 0, hour = 0;
45+
if (timeParts.length === 3){
46+
hour = Number(timeParts[0])
47+
minute = Number(timeParts[1])
48+
second = Number(timeParts[2])
49+
const dateObj = new Date(Date.UTC(year, month, day, hour, minute, second));
50+
if (dateObj > dateToCheck){
51+
ids.push(linkId.replace(`${base}/library/`, ""))
52+
}
53+
}
54+
}
55+
}
56+
})
57+
return ids;
58+
}
59+
60+
parsePages($: CheerioStatic): string[] {
61+
const pages: string[] = [];
62+
$("div[data-image]").map((index, element) => {
63+
const url = element.attribs["data-image"];
64+
if (url){
65+
pages.push(url);
66+
}
67+
})
68+
return pages;
2769
}
2870

2971
parseChapterList($: CheerioStatic, mangaId: string) {

src/tests/VoidScans.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,11 @@ describe("VoidScans Tests", function () {
7777
expect(subitem.image, "No Image found for homepage item").to.not.be.empty;
7878
}
7979
})
80+
81+
it("Testing Notifications", async () => {
82+
let updates = await wrapper.filterUpdatedManga(source, new Date("2021-1-27"), [mangaId])
83+
expect(updates, "No server response").to.exist
84+
expect(updates, "Empty server response").to.not.be.empty
85+
expect(updates[0], "No updates").to.not.be.empty;
86+
})
8087
});

0 commit comments

Comments
 (0)