55 lines
1.2 KiB
JavaScript
55 lines
1.2 KiB
JavaScript
import http from "http";
|
|
|
|
const unicodeToChar = (text) => {
|
|
return text.replace(/\\u[\dA-F]{4}/gi, function (match) {
|
|
return String.fromCharCode(parseInt(match.replace(/\\u/g, ""), 16));
|
|
});
|
|
};
|
|
|
|
http
|
|
.createServer(async (request, response) => {
|
|
const responseBody = {
|
|
message: "ok",
|
|
data: {},
|
|
};
|
|
|
|
let statusCode = 200;
|
|
|
|
let html;
|
|
try {
|
|
const res = await fetch("https://live.kankanews.com/live/8029037XEw6");
|
|
html = await res.text();
|
|
} catch (error) {
|
|
response.message = "fetch failed";
|
|
statusCode = 500;
|
|
}
|
|
|
|
const pattern = /play_url:"(.*?)"/g;
|
|
let match = [];
|
|
let urls = [];
|
|
|
|
while ((match = pattern.exec(html)) !== null) {
|
|
if (match.length > 0) {
|
|
const playUrl = match[1];
|
|
const decodedUrl = unicodeToChar(playUrl);
|
|
|
|
urls.push(decodedUrl);
|
|
}
|
|
}
|
|
|
|
if (urls.length > 0) {
|
|
responseBody.data = {
|
|
urls,
|
|
};
|
|
} else {
|
|
responseBody.message = "no urls";
|
|
statusCode = 404;
|
|
}
|
|
|
|
response.writeHead(statusCode, { "Content-Type": "application/json" });
|
|
response.end(JSON.stringify(responseBody));
|
|
})
|
|
.listen(8888);
|
|
|
|
console.log("Server running at http://127.0.0.1:8888/");
|