VTV Video Direct Link Generator

Từ ý tưởng này: https://kipalog.com/posts/Lay-link-tai-cac-chuong-trinh-yeu-thich-tren-VTV
Mình viết 1 cái app đơn giản để get link ra luôn, code có vẻ hơi củ chuối ^^
Mình sử dụng các module: body-parser; cheerio; string; express
Demo: http://vtv-link.herokuapp.com/

File app.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
var express = require('express');
var bodyParser = require('body-parser')
var cheerio = require('cheerio');
var request = require('request');
var s = require('string')

var port = Number(process.env.PORT || 5000);
var app = express();

function get_link(url) {
var link = url;
var text1 = s(link).chompLeft('http://vcplayer.vcmedia.vn/1.1/?_site=vtv&vid=').s;
var text2 = s(text1).splitLeft('&');
var text3 = 'http://vhosting.vcmedia.vn/' + text2[0];
return text3;
}

app.use(bodyParser.urlencoded({extended:false}));

app.get('/', function (req, res) {
res.sendFile('index.html', { root: __dirname });
});


app.post('/', function (req, res) {
var url = req.body.vtv;

request(url,function(err, resp, body){
var vtv_source = cheerio.load(body);
var link = vtv_source('.VCSortableInPreviewMode').attr('data-src');
res.writeHead(200, { 'Content-Type': 'text/html' });
res.write('<center> <br> <br> <br> <a href="' + get_link(link) + '">' + get_link(link) + '</a> </center>');
res.end();
});

});

var server = app.listen(port, function () {
console.log('Node server is running..');
});

File index.html

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
<!DOCTYPE html>
<html>
<head>
<title>VTV Video Direct Link Generator</title>
</head>
<style>
input {
width: 30%;
padding: 12px 20px;
margin: 8px 0;
font-size: 100%;
}
input[type=button], input[type=submit] {
background-color: #4CAF50;
border: none;
color: white;
padding: 16px 16px;
text-decoration: none;
margin: 4px 2px;
cursor: pointer;
width: 15%;
}
}
</style>

<body>
<br>
<br>
<br>
<center>
<h1>Paste your VTV Video url here</h1>
<form method = "post">
<input type="text" name="vtv" placeholder="http://vtv.vn/video/cong-nghe-doi-song-sinh-vat-ngoai-lai-204180.htm">
<input type="submit">
</form>
</center>
</body>