forked from yoannchb-pro/getanime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetanime.js
More file actions
71 lines (55 loc) · 2.38 KB
/
getanime.js
File metadata and controls
71 lines (55 loc) · 2.38 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
//Config
const config = {
nb_anime: 1,
}
//Imports
const api = require("anime-vostfr");
const fs = require('fs');
const cloudscrapper = require("cloudscraper");
const displayInfo = function(param){console.log("[INFO] "+param);}
const displayError = function(param){console.log("[ERROR] "+param);}
//Verification
if(!process.argv[2] || process.argv[2].trim() == "") {
console.log("\nUSAGE:");
console.log("--------------------------------------------------------------------------------------------------------------");
console.log('node getanime.js "hunter x hunter" - to get the anime json file in structured mode');
console.log('node getanime.js "hunter x hunter" false - to get the anime json file in not structured mode (minimified file)');
console.log("--------------------------------------------------------------------------------------------------------------");
return;
}
//starting
displayInfo("Connexion en cours...");
api.loadAnime().then(async function(data){
let anime = api.searchAnime(data, process.argv[2]);
if(!anime || anime.length == 0) {
displayError("Anime not found !");
return;
}
anime = anime[0];
displayInfo(`Lancement pour l'anime intitulé : \x1b[32m ${anime.title} \x1b[37m`);
displayInfo("Getting informations...");
const infos = await api.getMoreInformation(anime.url).catch((error) => displayError(error));
anime = Object.assign(anime, infos);
displayInfo("OK.");
delete anime.url;
displayInfo("Getting videos...");
let index = 0;
if(anime['eps'].length <= 200) for(const episode of anime['eps']){
index++;
displayInfo(`Episodes \x1b[31m ${index} \x1b[37m [${anime.title}]`);
const embed = await api.getEmbed(episode.url).catch((error) => displayError(error));
delete episode.url;
episode.embed = embed ? embed : [];
};
displayInfo("OK.");
const fileName = anime.title.replace(/[:,;\/\\!\%\?\.\<\>\~\&\=\+]/gi, "");
const content = process.argv[3] ? JSON.stringify(anime) : JSON.stringify(anime, undefined, 4);
fs.writeFile(`./data/${fileName}.json`, content, function(err) {
if(err) {
return displayError(err);
}
displayInfo("SAVED in data directory");
});
}).catch(function(error){
displayError(error);
});