-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
48 lines (42 loc) · 1.2 KB
/
app.js
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
const {
urlType,
getLinks,
anLinks,
getDownLink,
anScraper,
} = require("./utils");
const axios = require("axios");
const fs = require("fs");
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const URL = process.argv[2] || null;
const QUALITY = process.argv[3] || "720";
if (!URL) {
console.log("Please Provide A link");
}
async function main() {
const html = await axios.get(URL);
const dom = new JSDOM(html.data);
const animeTitle = dom.window.document.querySelector(
".anime-details-title"
).textContent;
console.log(animeTitle);
if (urlType(URL) === "anime") {
console.log("it an anime");
const allEps = await anScraper(dom, QUALITY);
fs.writeFile(`./${animeTitle}.txt`, allEps.join("\n"), function (err) {
if (err) throw err;
console.log("Saved!");
});
}
if (urlType(URL) === "episode") {
const epLink = getLinks(dom, QUALITY);
const epDownLink = await getDownLink(epLink);
const episodeTitle =
dom.window.document.querySelector(".container h3").textContent;
fs.writeFileSync(`./${episodeTitle}.txt`, epDownLink);
}
if (urlType(URL) !== "episode" && urlType(URL) !== "anime")
return "provide a valide link";
}
main();