Thứ Hai, 18 tháng 2, 2019

VTV Video Direct Link Generator

Deploying Node.js Apps on Heroku

Tools nho nhỏ viết bằng Nodej và Express bao gồm các modules:

body-parser

cheerio

string

  • 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
41
42
43
44
45
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('');
        res.write('');
        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>

Không có nhận xét nào:

Đăng nhận xét