How to Download Video from ted.com in Javascript?


This post shows you how to download the video from the ted.com using the Javascript:

The video URLs of ted.com have been stored explicitly in HTML source code, as follows:

ted-video-html How to Download Video from ted.com in Javascript? chrome extension javascript video download tutorial

ted-video-html

It can be parsed via regular expressions despite that the URIs are expressed over Javascript code snippets instead of actual HTML tags. The video URIs were stored using meta tag video:src, which is easier to parse.

We can use regular expression to parse these URIs, which store the real ted video URLs for different resolution. The following Javascript code has been added to the ted video downloader.

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
if (domain.includes("ted.com")) {
    if (!ValidURL(video_url)) {
        var re = /{"uri":"([^"\']+)"/gi;
        var found = re.exec(html);                        
        var video_url_arr = [];
        while (found != null) {
            var tmp_url = CheckURL(found[1]);
            if (ValidURL(tmp_url)) {
                video_url_arr.push(tmp_url);    
            }                            
            found = re.exec(html);
        }
        if (valid_domain) {                
            if (video_url_arr.length > 0) {
                chrome.runtime.sendMessage({
                    action: "getSource",
                    source: JSON.stringify(video_url_arr)
                });                          
            } else {
                chrome.runtime.sendMessage({
                    action: "getSource",
                    source: JSON.stringify(CheckURL(video_url))
                });                              
            }
        }
    }
}   
if (domain.includes("ted.com")) {
    if (!ValidURL(video_url)) {
        var re = /{"uri":"([^"\']+)"/gi;
        var found = re.exec(html);                        
        var video_url_arr = [];
        while (found != null) {
            var tmp_url = CheckURL(found[1]);
            if (ValidURL(tmp_url)) {
                video_url_arr.push(tmp_url);    
            }                            
            found = re.exec(html);
        }
        if (valid_domain) {                
            if (video_url_arr.length > 0) {
                chrome.runtime.sendMessage({
                    action: "getSource",
                    source: JSON.stringify(video_url_arr)
                });                          
            } else {
                chrome.runtime.sendMessage({
                    action: "getSource",
                    source: JSON.stringify(CheckURL(video_url))
                });                              
            }
        }
    }
}   

This has been added to the Chrome Extension Video Download Helper and also available in Online Universal Video Downloader and TED Video Downloader.

This is how it looks like when the Video Download Helper is able to parse the multiple Video URIs.

download-video-from-ted-using-chrome-extension How to Download Video from ted.com in Javascript? chrome extension javascript video download tutorial

download-video-from-ted-using-chrome-extension

Relevant Video Download Posts

Here are some posts that relate to download videos (parser):

You may also like: 怎么样下载 TED 视频?

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
426 words
Last Post: Does CloudFlare Cache 403 and 503 By Default?
Next Post: Coding Review - How would you convert this 'goto' ?

The Permanent URL is: How to Download Video from ted.com in Javascript?

One Response

  1. Ferdinand Samsa

Leave a Reply