-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
45 lines (38 loc) · 1.35 KB
/
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 http = require('http');
var express = require('express');
var app = express();
app.use("/css", express.static(__dirname + '/css'));
var bodyParser = require('body-parser');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
var request = require('request');
app.get('/', function(req , res) {
res.sendFile(__dirname + "/" + "index.html");
});
app.post('/process_get' , function(req , res){
var key = 'AIzaSyAll4ST1vhpn83iZKWe32nxxLcmTP7rxWU';
searchKey = req.body.bandName;
var url = 'https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&q='+searchKey+'&key='+key;
request({
url: url,
json: true
}, function (error, response, body) {
if (!error && response.statusCode === 200) {
var JSONString = JSON.stringify(body);
var JSONParser = JSON.parse(JSONString);
var finalJSONObject = {playlistObj:[]};
for(var i=0 ; i<5 ; i++)
{
finalJSONObject.playlistObj.push({
"videoId": JSONParser.items[i].id.videoId,
"title" : JSONParser.items[i].snippet.title
});
}
res.send(JSON.stringify(finalJSONObject));
}
});
});
var server = app.listen(8080,function(){
var port = server.address().port;
console.log("Server is running at http://localhost:%s", port);
});