-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathnovelupdates.js
More file actions
100 lines (79 loc) · 3.08 KB
/
novelupdates.js
File metadata and controls
100 lines (79 loc) · 3.08 KB
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
import { addContributor, cleanText, collectObject, getCoverData, getFormattedText, normalizeReadingFormat } from "../shared/utils.js";
import { Extractor } from "./AbstractExtractor.js"
class novelUpdatesScraper extends Extractor {
get _name() { return "Novel Updates Extractor"; }
needsReload = false;
_sitePatterns = [
/https:\/\/www\.novelupdates\.com\/series\/(.*)\//
];
async getDetails() {
return collectObject([
getCover(),
getTitle(),
getDescription(),
getMetadata(),
getAltTitles(),
]);
}
}
async function getCover() {
const el = document.querySelector(`.seriesimg img, .serieseditimg img`);
if (!el) return {};
return getCoverData(el.src);
}
function getTitle() {
const title = document.querySelector(`.seriestitlenu`)?.textContent;
if (!title) return {};
return { "Title": cleanText(title) }
}
function getDescription() {
const description = document.querySelector(`#editdescription`);
if (!description) return {};
return { "Description": getFormattedText(description) }
}
function getAltTitles() {
const el = document.querySelector(`#editassociated`);
if (!el) return {};
const titles = getFormattedText(el).split("\n").map(cleanText);
return { "Alt Titles": titles }
}
function getMetadata() {
const infoBar = document.querySelector(`.one-third`);
if (!infoBar) return {};
const details = {};
let val = document.querySelector(`#showtype a`)?.textContent;
if (val) {
details["Edition Format"] = cleanText(val);
details["Reading Format"] = normalizeReadingFormat(details["Edition Format"]);
}
// val = [...document.querySelectorAll(`#seriesgenre a`)].map(i => cleanText(i.textContent));
// if (val && val.length > 0) details["Genres"] = val;
//
// val = [...document.querySelectorAll(`#showtags a`)].map(i => cleanText(i.textContent));
// if (val && val.length > 0) details["Tags"] = val;
val = document.querySelector(`#showlang`)?.textContent;
if (val) details["Language"] = cleanText(val);
val = [...document.querySelectorAll(`#showauthors a`)].map(i => cleanText(i.textContent));
if (val && val.length > 0) {
const contributors = [];
for (const author of val) addContributor(contributors, author, "Author");
details["Contributors"] = contributors;
}
val = [...document.querySelectorAll(`#showartists a`)].map(i => cleanText(i.textContent));
if (val && val.length > 0) {
const contributors = details["Contributors"] ?? [];
for (const artist of val) addContributor(contributors, artist, "Artist");
details["Contributors"] = contributors;
}
val = document.querySelector(`#edityear`)?.textContent;
if (val) details["Publication date"] = cleanText(val);
val = [...document.querySelectorAll(`#showopublisher a`)].map(i => cleanText(i.textContent));
if (val && val.length > 0) {
details["Original Publisher"] = val;
details["Publisher"] = val[0];
}
val = [...document.querySelectorAll(`#showepublisher a`)].map(i => cleanText(i.textContent));
if (val && val.length > 0) details["English Publisher"] = val;
return details;
}
export { novelUpdatesScraper };