-
Notifications
You must be signed in to change notification settings - Fork 3
/
source.js
41 lines (33 loc) · 1.19 KB
/
source.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
const sources = require('./lib/sources')
async function stream(type, id) {
try {
console.log("stream", type, id)
const promises=[];
if (id.match(/tt\d+(:\d+)?(:\d+)?/i)){
const [tmdb_id,season,episode] = id.split(":");
for (const key in sources.movies) {
promises.push(sources.movies[key](type,tmdb_id, episode, season).catch(e => { console.error(e) }));
}
}
else if(id.match(/kitsu:\d+(:\d+)?/i)){
const [kitsu_id,episode] = id.match(/\d+/ig);
console.log(kitsu_id,episode)
for (const key in sources.anime) {
promises.push(sources.anime[key](kitsu_id,episode).catch(e => { console.error(e) }));
}
}
let streams = await Promise.allSettled(promises).then(promises=>{
let streams = []
promises.forEach(({status,value})=>{
if(status == "fulfilled"){
streams = streams.concat(value)
}
})
return streams.filter(Boolean);
});
return streams
} catch (e) {
console.error(e)
}
}
module.exports = stream;