-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathanime-vostfr.js
168 lines (147 loc) · 5.08 KB
/
anime-vostfr.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
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//Modules
const cloudscraper = require('cloudscraper');
const DomParser = require('dom-parser');
/**
* Retourne un anime en fonction de son nom (shortcut function)
* @param {Object} elem
* @param {String} name
* @returns {Boolean}
*/
function getAnimeByTitle(elem, name){
name = name.toLowerCase().trim();
let title = elem.title ? elem.title.toLowerCase().trim().includes(name) : false;
let title_english = elem.title_english ? elem.title_english.toLowerCase().trim().includes(name) : false;
let title_romanji = elem.title_romanji ? elem.title_romanji.toLowerCase().trim().includes(name) : false;
let others = elem.others ? elem.others.toLowerCase().trim().includes(name) : false;
return title || title_english || title_romanji || others;
}
/**
* Permet de load les animes à partir d'un fichier json
* @returns {Promise}
*/
exports.loadAnime = async () => {
const result = await cloudscraper("https://neko-sama.fr/animes-search-vostfr.json");
return JSON.parse(result);
}
/**
* Permet de load les animes en vf à partir d'un fichier json
* @returns {Promise}
*/
exports.loadAnimeVF = async () => {
const result = await cloudscraper("https://neko-sama.fr/animes-search-vf.json");
return JSON.parse(result);
}
/**
* Permet de récuperer le lien de la vidéo en embed
* @param {String} url
* @returns {Promise}
*/
exports.getEmbed = async (url) => {
const html = await cloudscraper("https://www.neko-sama.fr"+url);
let video = [];
let result = html.substring(html.indexOf('else'));
result = result.substring(4,result.indexOf('}')+1);
eval(result);
return video;
}
/**
* Permet de retourner la bannière, la synopsy, le trailer d'un anime et les episodes avec leurs informations
* @param {String} url
* @returns {Object}
*/
exports.getMoreInformation = async (url) => {
const html = await cloudscraper("https://www.neko-sama.fr"+url);
let parser = new DomParser();
let document = parser.parseFromString(html);
let synop = document.getElementsByClassName('synopsis')[0].getElementsByTagName('p')[0].innerHTML;
let ytb = document.getElementsByTagName('iframe')[0];
let banner = document.getElementById('head').getAttribute('style');
banner = banner.substring(banner.indexOf('url('));
banner = banner.substring(4,banner.indexOf(')'));
let result = html.substring(html.indexOf('episodes'));
result = result.substring(0,result.indexOf('$(document)'));
result = eval(result);
return{
synop: synop,
banner: banner,
trailer: ytb ? ytb.getAttribute('src') : false,
eps: result
};
}
/**
* Permettais dans les ancienne version de retourner les genres
* Plus d'utilité pour le moment
* @param {Array} result
* @returns {Array}
*/
exports.getGenres = (result) => {
//let keys = Object.keys(result); keys.splice(0, keys.indexOf('nb_eps')+1); return keys;
return result.genres;
}
/**
* Permet de chercher un anime par son nom (Film et animes)
* @param {Array} data
* @param {String} name
* @returns {Array}
*/
exports.searchAnime = (data, name) => {
if(!data || typeof data != "object") throw 'invalid data object (data,name)';
if(!name) throw '"name" should be declared (data,name)';
let result = data.filter(elem => getAnimeByTitle(elem, name));
return result;
}
/**
* Recherche un anime qui n'est pas un film en fonction de son nom
* @param {Array} data
* @param {String} name
* @returns {Array}
*/
exports.searchAnimeNotMovie = (data, name) => {
if(!data || typeof data != "object") throw 'invalid data object (data,name)';
if(!name) throw '"name" should be declared (data,name)';
name = name.toLowerCase().trim();
let result = data.filter(elem => getAnimeByTitle(elem, name) && elem.nb_eps != "Film");
return result;
}
/**
* Permet de rechercher un anime de type film
* @param {Array} data
* @param {String} name
* @returns {Array}
*/
exports.searchMovieAnime = (data, name) => {
if(!data || typeof data != "object") throw 'invalid data object (data,name)';
if(!name) throw '"name" should be declared (data,name)';
let result = data.filter(elem => getAnimeByTitle(elem, name) && elem.nb_eps == "Film");
return result;
}
/**
* Retourne la liste des animes populaire
* @param {Array} data
* @returns {Array}
*/
exports.popularAnime = (data) => {
if(!data || typeof data != "object") throw 'invalid data object (data)';
let result = data.filter(elem => Number(elem.popularity) > 10);
return result;
}
/**
* Permet de retourner tous les animes de type Film
* @param {Array} data
* @returns {Array}
*/
exports.movieAnime = (data) => {
if(!data || typeof data != "object") throw 'invalid data object (data)';
let result = data.filter(elem => elem.nb_eps == "Film");
return result;
}
/**
* Retourne la liste des animes avec la meilleur note (>4)
* @param {Array} data
* @returns {Array}
*/
exports.bestScoreAnime = (data) => {
if(!data || typeof data != "object") throw 'invalid data object (data)';
let result = data.filter(elem => Number(elem.score) > 4);
return result;
}