Code for retrieving the JSON address of the Firebug subtitle file

Source: Internet
Author: User

Previously, I watched the TED video about how school education kills creativity.
The video is good, and there are also Chinese subtitles. Download the HD version is also available below.
Unfortunately, subtitles cannot be downloaded. (Or I cannot find it)

As the saying goes, do it yourself. Use Firebug to find the subtitle file address, download it, and see that it is in JSON format. Then, you can directly use JS output strings to convert it to srt Subtitles.
The Code is as follows. The code is very simple and practical. Without efficiency, security, and boundary problems, you can solve your problem as quickly as possible ~

I have to say that it makes sense to learn a programming language. Whatever it is, it can easily solve some practical problems. This is a pleasure.
JS is a very powerful language. It is very convenient to process JSON and XML, and most of the time it is enough. However, there will always be many defects, especially for system operations. However, if it is Microsoft's JScript, you can do it too. I used to want to learn Python, and now I feel calm. I just like what I use. Maybe, this is related to I no longer engage in IT-related industries. Enough ~
Copy codeThe Code is as follows:
// Read the chi_hans File
$. GetJSON ("chi_hans", function (json ){
Var c = json. captions, o = [];
For (var I = 0, l = c. length; I <l; I ++ ){
O. push (I + 1 );
// Here 18500 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;
}
// Output to a textarea
$ ("# Output"). text (o. join ("\ r "));
});
// Obtain the time in the srt subtitle 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 the leading zero
Function leadZero (s ){
If (s <10 ){
Return "0" + s;
} Else {
Return s;
}
}
// This is also the leading zero, 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 Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.