Skip to content

Commit 52c6ddd

Browse files
committed
Merge branch 'version-2.0.0'
2 parents 09f0016 + 57dc224 commit 52c6ddd

File tree

7 files changed

+84
-22
lines changed

7 files changed

+84
-22
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "NovelScraper",
3-
"version": "2.0.5",
3+
"version": "2.0.6",
44
"description": "App for downloading novels from pirate sites.",
55
"homepage": "https://github.com/HanaDigital/NovelScraper",
66
"author": {

src/app/resources/sourceList.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { sourcesList } from "./types"
33
export const sources: sourcesList = [
44
{ name: "NovelFull", link: "https://novelfull.com", icon: "assets/img/sources/novelfull-logo.png" },
55
{ name: "BoxNovel", link: "https://boxnovel.com", icon: "assets/img/sources/boxnovel-logo.png" },
6-
{ name: "ReadLightNovel", link: "https://www.readlightnovel.org", icon: "assets/img/sources/readlightnovel-logo.png" },
6+
{ name: "ReadLightNovel", link: "https://www.readlightnovel.me", icon: "assets/img/sources/readlightnovel-logo.png" },
77
];
88

99
export const deprecatedSources: sourcesList = [

src/app/services/novel-factory.service.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const epubGen = require("nodepub");
99
import mime from "mime";
1010
import { writeFileSync, createWriteStream, writeFile } from "fs";
1111
import request from "request";
12+
import { async } from "@angular/core/testing";
1213

1314
@Injectable({
1415
providedIn: "root",
@@ -38,6 +39,18 @@ export class NovelFactoryService {
3839
// Download the cover and get its path
3940
const coverPath = await this.downloadCover(novel.cover, novelFolder);
4041

42+
// If the novel doesn't have a genre we default "Unknown"; empty or null will crash the epub creation
43+
if (novel.genre == null || novel.genre == "") {
44+
novel.genre = 'unknown'
45+
}
46+
47+
// If the novel doesnt have a author we default "Unknown"; empty or null will crash the epub creation
48+
if (novel.author == null || novel.author == "") {
49+
novel.author = 'unknown'
50+
}
51+
console.log("Creating Epub with metadata");
52+
console.log(novel)
53+
4154
// Set some meta data for the epub file
4255
const metadata = {
4356
id: "0000-0000-0001",
@@ -59,13 +72,14 @@ export class NovelFactoryService {
5972
for (const chapter of chapters)
6073
epub.addSection(chapter.title, chapter.data);
6174

62-
setTimeout(async () => {
63-
await epub.writeEPUB(novelFolder, novelFile);
64-
65-
this.database.updateDownloading(novel.link, false);
66-
this.database.updateDownloaded(novel.link, true);
67-
this.database.updateIsUpdated(novel.link, true);
68-
this.database.setDownloaded(downloadID);
75+
setTimeout(() => {
76+
(async () => {
77+
await epub.writeEPUB(novelFolder, novelFile);
78+
this.database.updateDownloading(novel.link, false);
79+
this.database.updateDownloaded(novel.link, true);
80+
this.database.updateIsUpdated(novel.link, true);
81+
this.database.setDownloaded(downloadID);
82+
})();
6983
}, 2000);
7084
}
7185

src/app/services/sources/boxnovel.service.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,20 @@ export class BoxnovelService extends sourceService {
3535
}
3636

3737
try {
38+
39+
3840
const html = await this.getHtml(link); // Get HTML from the link
3941

4042
// Link
4143
if (!updatingInfo) novel.link = link;
4244

45+
//boxnovel uses some lower level ajax call now to store the chapters.
46+
const chapter_link = link + (link.slice(-1) == '/' ? "" : "/") + "ajax/chapters/";
47+
48+
const chapters = await this.postHtml(chapter_link) // we get the subpage listing all the chapters.
49+
50+
51+
4352
// Source
4453
if (!updatingInfo) novel.source = source;
4554

@@ -56,18 +65,23 @@ export class BoxnovelService extends sourceService {
5665
novel.name = title.textContent.trim();
5766

5867
// LatestChapter
59-
novel.latestChapter = html
60-
.getElementsByClassName("wp-manga-chapter")[0]
61-
.getElementsByTagName("a")[0]
62-
.innerText.trim();
68+
try {
69+
novel.latestChapter = chapters
70+
.getElementsByClassName("wp-manga-chapter")[0]
71+
.getElementsByTagName("a")[0]
72+
.innerText.trim();
73+
} catch (error) {
74+
console.log("Unknown find latest chapter");
75+
novel.latestChapter = "Unknown"
76+
}
6377

6478
// Cover
6579
novel.cover = html
6680
.getElementsByClassName("summary_image")[0]
6781
.getElementsByTagName("img")[0].src;
6882

6983
// TotalChapters
70-
novel.totalChapters = html.getElementsByClassName(
84+
novel.totalChapters = chapters.getElementsByClassName(
7185
"wp-manga-chapter"
7286
).length;
7387

@@ -238,9 +252,10 @@ export class BoxnovelService extends sourceService {
238252
let downloadedChapters: chapterObj[] = []; // List of download chapters
239253

240254
try {
241-
const html = await this.getHtml(novel.link);
255+
const chapter_link = novel.link + (novel.link.slice(-1) == '/' ? "" : "/") + "ajax/chapters/"
256+
const chapter_html = await this.postHtml(chapter_link) // we get the sub-page listing all the chapters.
242257

243-
const chapters = html.getElementsByClassName("wp-manga-chapter");
258+
const chapters = chapter_html.getElementsByClassName("wp-manga-chapter");
244259

245260
// Get chapter links and names
246261
let chapterLinks = [];

src/app/services/sources/novelfull.service.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,17 @@ export class NovelfullService extends sourceService {
9090
// FIXME: Genre(s)
9191
const genres = html
9292
.getElementsByClassName("info")[0]
93-
.getElementsByTagName("div")[1]
93+
.getElementsByTagName("div")[2]
9494
.getElementsByTagName("a");
9595
let genre = "";
9696
for (let i = 0; i < genres.length; i++) {
9797
genre += genres[i].innerText + ", ";
9898
}
9999
novel.genre = genre.slice(0, -2);
100100

101+
// defaulting if none is found.
102+
if (!novel.genre) novel.genre = "Unknown"
103+
101104
// FIXME: Summary
102105
const summaryList = html
103106
.getElementsByClassName("desc-text")[0]
@@ -113,6 +116,9 @@ export class NovelfullService extends sourceService {
113116
console.log(error);
114117
}
115118

119+
// defaulting if none is found.
120+
if (!novel.summary) novel.summary = "Unknown"
121+
116122
//////////////////////// YOUR CODE ENDS HERE /////////////////////////////////
117123

118124
this.pushOrUpdateNovel(novel, updatingInfo);
@@ -314,7 +320,6 @@ export class NovelfullService extends sourceService {
314320
);
315321
chapterBody = chapterBody.replace(/<script.*><\/script>/g, "");
316322
chapterBody = chapterBody.replace(/<ins.*<\/ins>/g, "");
317-
console.log(chapterBody);
318323

319324
const chapter = this.prepChapter(novel, downloadID, chapterTitle, chapterBody, downloadedChapters.length, totalLength);
320325
downloadedChapters.push(chapter);

src/app/services/sources/readlightnovel-service.service.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ export class ReadlightnovelService extends sourceService {
4747

4848
// LatestChapter
4949
try {
50-
novel.latestChapter = html.getElementsByClassName('wp-manga-chapter')[0].getElementsByTagName('a')[0].innerText.trim();
50+
const chapters_section = html.getElementsByClassName('tab-content')[0].getElementsByClassName("tab-pane")
51+
const latest_chapter_section = chapters_section[chapters_section.length - 2].getElementsByTagName('a') // latest element is always empty.
52+
const latest_chapter = latest_chapter_section[latest_chapter_section.length - 1]
53+
54+
novel.latestChapter = latest_chapter.innerText.trim();
5155
} catch (error) {
5256
novel.latestChapter = "N/A";
5357
console.log(error);
@@ -170,13 +174,23 @@ export class ReadlightnovelService extends sourceService {
170174
// Download each chapter at a time
171175
for (let i = 0; i < chapterLinks.length; i++) {
172176
if (this.database.isCanceled(downloadID)) {
173-
this.database.updateDownloading(novel.link, false);
174177
console.log('Download canceled!');
175178
canceled = true;
176179
break;
177180
}
178181

179-
const html = await this.getHtml(chapterLinks[i]);
182+
let html = null;
183+
try {
184+
html = await this.getHtml(chapterLinks[i]);
185+
} catch (error) {
186+
if (error.statusCode == 404) {
187+
novel.totalChapters -= 1
188+
this.database.updateTotalChapters(novel.link, novel.totalChapters);
189+
continue;
190+
}
191+
canceled = true;
192+
break;
193+
}
180194

181195
//////////////////////// YOUR CODE STARTS HERE ///////////////////////////////
182196

src/app/services/sources/sourceService.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,21 @@ export class sourceService {
103103

104104
async getHtml(link: string): Promise<HTMLHtmlElement> {
105105
const stringHtml: string = await cloudscraper(
106-
{ method: "GET", url: link },
106+
{ method: "GET", url: link, rejectUnauthorized: false },
107+
(error, response, novelHtmlString) => {
108+
return novelHtmlString;
109+
}
110+
);
111+
112+
const html = document.createElement("html");
113+
html.innerHTML = stringHtml;
114+
return html;
115+
}
116+
117+
118+
async postHtml(link: string): Promise<HTMLHtmlElement> {
119+
const stringHtml: string = await cloudscraper(
120+
{ method: "POST", url: link, rejectUnauthorized: false },
107121
(error, response, novelHtmlString) => {
108122
return novelHtmlString;
109123
}

0 commit comments

Comments
 (0)