Home > Web Front-end > JS Tutorial > Firebug subtitle file JSON address acquisition code_javascript skills

Firebug subtitle file JSON address acquisition code_javascript skills

WBOY
Release: 2016-05-16 18:43:07
Original
1426 people have browsed it

I watched a TED video earlier, about school education killing creativity.
The video is very good and has Chinese subtitles. A high-definition version is also available for download below, which I am very happy about.
Unfortunately, subtitles are not available for download. (Or I didn’t find it)

As the saying goes, you can have enough food and clothing by yourself. I directly used Firebug to find the address of the subtitle file. After downloading it, I saw that it was in JSON format. I then thought that I could convert it to srt subtitles by directly using JS to output the string.
The code is as follows, a very simple code, as long as it is practical. I don’t care about efficiency, security and boundary issues, I just want to solve my problem as quickly as possible~

I have to say that learning a programming language is very helpful The meaning, no matter what it is, can easily solve some practical problems. It's great fun.
JS is a very powerful language. It is very convenient to process JSON and XML. It is enough for most of the time. However, there will also be times when you are unable to do what you want, especially when it comes to the operation of the system, there are always many flaws. But if you include Microsoft's JScript, it's pretty good. I used to want to learn Python, but now I feel free to use it as long as I like it. Perhaps this is related to the fact that I am no longer engaged in IT-related industries. It’s enough~

Copy code The code is as follows:

//Read chi_hans file
$.getJSON("chi_hans",function(json) {
var c=json.captions,o=[];
for (var i=0,l=c.length; io.push(i 1);
//18500 here is the time offset
o.push(timeline(c[i].startTime 18500) " --> "
timeline(c[i].startTime c[i].duration 18500));
o.push(c[i].content);
o.push("");
/ /if (i==5) break;
}
//Here I output to a textarea
$("#output").text(o.join("r"));
});
//This is to get the time in srt subtitles based on the time in JSON
function timeline(time) {
t=new Date(time);
return [
leadZero (t.getUTCHours()),
leadZero(t.getUTCMinutes()),
leadZero(t.getUTCSeconds())
].join(":") "," leadZero3(t.getUTCMilliseconds ());
}
//Add leading zero
function leadZero(s) {
if (s<10) {
return "0" s;
}else {
return s;
}
}
//This is also a leading zero, a three-digit
function leadZero3(s) {
var ret;
if (s< 10) {
ret="00" s;
}else if (s<100) {
ret= "0" s;
}else {
ret=s;
}
return ret;
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template