-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjson_and_string.js
More file actions
91 lines (63 loc) · 2.3 KB
/
json_and_string.js
File metadata and controls
91 lines (63 loc) · 2.3 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
var express = require('express');
var request = require('request');
var cheerio = require('cheerio');
var xmlToJSON = require('xmlToJSON');
var app = express();
var title;
var url="https://www.youtube.com/watch?v=JZjAg6fK-BQ";
console.log("Enter the youtube link");
url = url.replace("https://www.youtube.com/watch?v=","http://video.google.com/timedtext?lang=en&v=");
console.log(url);
request({
uri: url,
}, function(error, response, body) {
if(!error){
// var rom = cheerio.load(body);
// console.log(body);
var parseString = require('xml2js').parseString;
var xml = body;
parseString(xml, function (err, result) {
// console.dir(result);
var fs = require('fs');
fs.writeFile('output.json', JSON.stringify(result, null, 4), function(err){
// console.log('File successfully written! - Check your project directory for the output.json file');
console.log("\n");
var lyric="";
var i=1;
while(result.transcript.text[i].$){
if(result.transcript.text[i]._){
//console.log(result.transcript.text[i]._);
lyric = lyric + result.transcript.text[i]._;
// console.log(result.transcript.text[i]._);
}
console.log(Number(result.transcript.text[i].$.start) + " - " + (Number(result.transcript.text[i].$.start) + Number(result.transcript.text[i].$.dur)));
i++;
if(result.transcript.text[i].$ ){continue;}
}
console.log(lyric);
});
});
// var testString = '<xml><a>It Works!</a></xml>'; // get some xml (string or document/node)
// var result = xmlToJSON.parseString(xml);
// console.log(result);
}
});
//
//
// var myJson = {
// key: "myvalue"
// };
//
// fs.writeFile( "youtube_json.json", JSON.stringify( myJson ), "utf8", yourCallback );
/*
var xml2js = require('xml2js');
var parser = new xml2js.Parser();
var check;
fs.readFile(body.toString(),function(err,data){
parser.parseString(data,function (err,result) {
console.log(result);
check = result;
});
});
*/
// console.log(check);