-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
79 lines (68 loc) · 2.13 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
const express = require('express');
const path = require('path');
const cheerio = require('cheerio');
const favicon = require('serve-favicon');
const axios = require('axios');
const app = express();
const http = require('http').Server(app);
const PORT = process.env.PORT || 3000;
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));
app.use(favicon(path.join(__dirname, 'public', 'favicon.png')));
// routes
app.get('/', (req, res) => {
res.render('index.html');
})
app.post('/api/get-link', async (req, res) => {
let page = req.body.linkNCT;
try {
let done = await getLink(page);
res.send(done);
} catch (error) {
res.send();
}
});
// Handle 404
app.use(function (req, res) {
res.status(404).send('Page not found.');
});
// Handle 500
app.use(function (error, req, res, next) {
res.status(500).send('Internal Server Error');
});
async function getLink(page) {
let result = {
title: '',
coverImage: '',
link: '',
message: ''
};
let body = await axios.get(page);
let $ = cheerio.load(body.data);
const flashPlayer = $('#box_playing_id').html();
const flashxml = 'https://www.nhaccuatui.com/flash/xml?html5=true&key1=';
result.title = $('title').text();
// result.flashPlayer = flashPlayer;
// Copyright in your country
if ($('.txt-alert-universal').text().length > 0) {
result.message = $('.txt-alert-universal').text();
return result;
};
if (flashPlayer.indexOf(flashxml) !== -1) {
const text = flashPlayer.substring(flashPlayer.indexOf(flashxml));
const location = text.substring(0, text.indexOf('"'));
body = await axios.get(location);
$ = cheerio.load(body.data);
const cdata = $('location').html();
const coverImage = $('coverimage').html();
result.link = cdata.substring(cdata.indexOf('https'), cdata.indexOf(']'));
if (coverImage.indexOf('https') !== -1) {
result.coverImage = coverImage.substring(coverImage.indexOf('https'), coverImage.indexOf(']'));
}
}
return result;
}
const server = http.listen(PORT, () => {
console.log(`Server listening on port:${PORT}`);
})