forked from scara78/vidsrc-new
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
165 lines (132 loc) · 5.22 KB
/
index.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
import express from "express";
import { vidsrcBase } from "./src/common.js";
import { load } from "cheerio";
import { getVidsrcMovieSourcesId, getVidsrcShowSourcesId, getVidsrcSourceDetails, getVidsrcSources } from "./src/main.js";
import { encodeId, getFutoken } from "./src/utils.js";
import axios from "axios";
import randomUseragent from 'random-useragent';
const app = express()
const port = 3000
randomUseragent.getRandom();
//console.log(randomUseragent)
var ip = (Math.floor(Math.random() * 255) + 1)+"."+(Math.floor(Math.random() * 255))+"."+(Math.floor(Math.random() * 255))+"."+(Math.floor(Math.random() * 255));
//console.log(ip)
app.use(function (req, res, next) {
if (req.originalUrl && req.originalUrl.split("/").pop() === 'favicon.ico') {
return res.sendStatus(204);
}
next();
});
app.get('/', (req, res) => {
res.status(200).json({
intro: "Unofficial",
routes: {
movie: "/id",
show: "/id/s/e"
},
author: "swartie8"
})
})
app.get('/:movieTMDBid', async(req, res) => {
const movieId = req.params.movieTMDBid;
const sourcesId = await getVidsrcMovieSourcesId(movieId);
if(!sourcesId) res.status(404).send({
status: 404,
return: "Oops movie not available"
});
const sources = await getVidsrcSources(sourcesId);
const vidplay = sources.data.result.find((v) => v.title.toLowerCase() === 'vidplay');
if(!vidplay) res.status(404).json('vidplay stream not found for vidsrc');
const vidplayLink = await getVidsrcSourceDetails(vidplay.id);
const key = await encodeId(vidplayLink.split('/e/')[1].split('?')[0]);
const data = await getFutoken(key, vidplayLink);
let subtitles;
//if(vidplayLink.includes('sub.info='))
{
//const subtitleLink = vidplayLink.split('?sub.info=')[1].split('&')[0];
//const subtitlesFetch = await axios.get(decodeURIComponent(subtitleLink));
const data = await axios.get(`${vidsrcBase}/embed/movie/${movieId}`);
const doc = load(data.data);
const sourcesCode = doc('a[data-id]').attr('data-id');
const subtitlesFetch = await axios.get(`https://vidsrc.to/ajax/embed/episode/${sourcesCode}/subtitles`);
subtitles = await subtitlesFetch.data;
//console.log(sourcesCode)
}
const response = await axios.get(`https://vidplay.online/mediainfo/${data}?${vidplayLink.split('?')[1]}&autostart=true`, {
params: {
v: Date.now().toString(),
},
headers: {
"Origin": ip,
"Referer": vidplayLink,
"Host": "vidplay.online",
"User-Agent": randomUseragent
}
});
const result = response.data.result;
if (!result && typeof result !== 'object') {
throw new Error('an error occured');
}
const source = result.sources?.[0]?.file;
if(!source) res.status(404).send({
status: 404,
return: "Oops reached rate limit of this api"
})
res.status(200).json({
source,subtitles
})
})
app.get('/:showTMDBid/:seasonNum/:episodeNum', async(req, res) => {
const showTMDBid = req.params.showTMDBid;
const seasonNum = req.params.seasonNum;
const episodeNum = req.params.episodeNum;
//console.log(showTMDBid,seasonNum,episodeNum)
const sourcesId = await getVidsrcShowSourcesId(showTMDBid, seasonNum, episodeNum);
if(!sourcesId) res.status(404).send({
status: 404,
return: "Oops show not available"
});
const sources = await getVidsrcSources(sourcesId);
const vidplay = sources.data.result.find((v) => v.title.toLowerCase() === 'vidplay');
if(!vidplay) res.status(404).json('vidplay stream not found for vidsrc');
const vidplayLink = await getVidsrcSourceDetails(vidplay.id);
const key = await encodeId(vidplayLink.split('/e/')[1].split('?')[0]);
const data = await getFutoken(key, vidplayLink);
let subtitles;
//if(vidplayLink.includes('sub.info='))
{
//const subtitleLink = vidplayLink.split('?sub.info=')[1].split('&')[0];
//const subtitlesFetch = await axios.get(decodeURIComponent(subtitleLink));
const data = await axios.get(`${vidsrcBase}/embed/tv/${showTMDBid}/${seasonNum}/${episodeNum}`);
const doc = load(data.data);
const sourcesCode = doc('a[data-id]').attr('data-id');
const subtitlesFetch = await axios.get(`https://vidsrc.to/ajax/embed/episode/${sourcesCode}/subtitles`);
subtitles = await subtitlesFetch.data;
}
const response = await axios.get(`https://vidplay.online/mediainfo/${data}?${vidplayLink.split('?')[1]}&autostart=true`, {
params: {
v: Date.now().toString(),
},
headers: {
"Origin": ip,
"Referer": vidplayLink,
"Host": "vidplay.online",
"User-Agent": randomUseragent
}
});
const result = response.data.result;
if (!result && typeof result !== 'object') {
throw new Error('an error occured');
}
const source = result.sources?.[0]?.file;
if(!source) res.status(404).send({
status: 404,
return: "Oops reached rate limit of this api"
})
res.status(200).json({
source,subtitles
})
})
app.listen(port, () => {
console.log(`Example app listening on port http://localhost:${port}`)
})