-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
136 lines (130 loc) · 3.78 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
const express = require("express");
const app = express();
const port = process.env.PORT || 8080;
const fetch = require("node-fetch");
var path = require('path')
var rawData = [];
app.listen(port, () => {
console.log(`App is running on port ${port}`);
});
app.get("/", function (req, res) {
res.sendFile(path.join(__dirname + '/index.html'));
});
app.get("/detail", function (req, res) {
DoWork(req, res);
});
async function DoWork(req, res) {
var type = req.query.type;
var url = req.query.url;
if (type == null || url == null)
res.json({ status: "Error", code: "Please provide type and url params" });
else {
try {
var firstUrl = await getPathName(url);
var contentData = await getIdandDetail(
'https://seo.mxplay.com/v1/api/seo/get-url-details' + "?url=" + firstUrl
);
var streamdata = await getAllData(
'https://api.mxplay.com/v1/web/detail/video' + `?type=${type}&id=${contentData.data.id}`
);
if (type.includes("episode"))
await SendSeriesData(contentData, streamdata, res);
else await SendMovieData(contentData, streamdata, res);
} catch (e) {
console.log(e)
res.json({
status: "Error",
code: "Wrong url or type. Please check this again...",
error:e
});
}
}
}
async function getIdandDetail(url) {
rawData = await fetch(url);
rawData = await rawData.json();
return rawData;
}
async function getAllData(url) {
rawData = [];
rawData = await fetch(url);
rawData = await rawData.json();
return rawData;
}
async function getPathName(url) {
return new URL(url).pathname;
}
async function SendSeriesData(contentData, streamdata, res) {
var actors = await ProcessActors(streamdata.contributors);
var img = await ProcessImages(streamdata.imageInfo);
var mediaUrl =
streamdata.stream.hls.high ||
streamdata.stream.hls.base ||
streamdata.stream.hls.min;
var response = {
id: contentData.data.id,
type: "series",
seriesTitle: contentData.data.display_title,
description: contentData.data.description,
releaseDate: streamdata.releaseDate,
season_no: contentData.data.dependencies.season.season_no,
episode_no: contentData.data.source.episode_no,
duration: contentData.data.source.duration,
actors: actors,
images: img,
streamingUrl: "https://llvod.mxplay.com/" + mediaUrl,
};
if (mediaUrl != null) res.send(response);
else
res.json({
status: "error",
code: "Unable to process this url. Please check url and its type.",
});
}
async function SendMovieData(contentData, streamdata, res) {
var actors = await ProcessActors(streamdata.contributors);
var img = await ProcessImages(streamdata.imageInfo);
var mediaUrl =
streamdata.stream.hls.high ||
streamdata.stream.hls.base ||
streamdata.stream.hls.min;
var response = {
id: contentData.data.id,
type: "movies",
title: contentData.data.title,
description: contentData.data.description,
releaseDate: streamdata.releaseDate,
duration: contentData.data.source.duration + " seconds",
actors: actors,
images: img,
streamingUrl: "https://llvod.mxplay.com/" + mediaUrl,
};
if (mediaUrl != null) res.send(response);
else
res.json({
status: "error",
code: "Unable to process this url. Please check url and its type.",
});
}
async function ProcessActors(actors) {
var wholeData = [];
await actors.forEach((element) => {
var data = {
name: element.name,
type: element.type,
};
wholeData.push(data);
});
return wholeData;
}
async function ProcessImages(images) {
var wholeData = [];
await images.forEach((element) => {
var data = {
type: element.type,
url: "https://isa-1.mxplay.com/" + element.url,
};
wholeData.push(data);
});
return wholeData;
}