Script to Download TED Videos in Bulk

I recently became addicted to TED Videos. This inspired me to create a simple python script which helps one download TED Talks in bulk. Here is the main part of the script. Scroll down for download link and usage instructions.

#! /usr/bin/python
 
# Name: TED Video Downloader
# Version: 0.4
# Summary: A bulk TED Talks download tool
# License: BSD
# Author: Pranav Ashok
# Author-email: iam@pranavashok.com
# Author-homepage: http://pranavashok.com/blog
# Support: http://pranavashok.com/blog/2009/12/script-to-download-ted-videos-in-bulk/
# Support: Twitter (@pranavashok)
 
from BeautifulSoup import BeautifulSoup
from urllib2 import urlopen
import re
import os
import sys
 
f = open(sys.argv[1], 'r')
for link in f:
	web = urlopen(link)
	soup = BeautifulSoup(web.read())
	wholeTag = soup.find(href=re.compile("download.ted.com/talks/.+"))
 
	name = os.path.basename(link)
	fileName, fileExt = os.path.splitext(name)
	outputFile = fileName+".mp4"
 
	# wholeTag['href'] gives the value of the href attribute
	downloadUrl = wholeTag['href']
 
	w = open('downloader.sh', 'a')
	w.write('wget -c -O \"%s\" \"%s\"\n' % (outputFile, downloadUrl))
	w.close()
exit()


Dependencies
This script has used python library called BeautifulSoup for parsing HTML. If you are a developer, I’d recommend you to try BeautifulSoup. It’s got a nice documentation and it’s easy to use.
(Note: You don’t need to download this, I’ve included it along with my script)

Instructions
1. Download the TED Video Downloader
2. Extract the files to the directory where you want the videos to be downloaded.
3. Edit the toDownload.txt file and add the links of each TED Video in a new line (example links are already present).
4. Open a terminal and change to the directory where you extracted the files.
5. Execute ‘sh run-first.sh

$ sh run-first.sh

6. The python script will be executed automatically and download will start soon (depending on the length of your list)
7. If you want to stop the downloads, press Ctrl+C.
8. To resume a stopped/interrupted download, execute the following command in terminal – ‘sh downloader.sh

$ sh downloader.sh

9. Enjoy the videos!

Limitations
I haven’t implemented any sort of error handling. If the TED.com decides to change the format of their video page, this script might stop working. In that case, please drop a comment here and I’ll fix it as soon as possible.

Hope you liked this script. Suggestions on optimization of the script are welcome.

Update (Dec 7, 2011): Changed downloader.py due to changes in TED website structure.

13 thoughts on “Script to Download TED Videos in Bulk

  1. Pingback: Tweets that mention Script to Download TED Videos in Bulk | i R pranav -- Topsy.com

  2. Pingback: uberVU - social comments

  3. Majmun12

    Hello,
    I hope you can help me getting the script to work as I’m always getting this:

    Is-MacBook:Desktop V$ cd TED-Downloader-1Is-MacBook:TED-Downloader-1 V$ sh run-first.shdownloader.sh: line 1: wget: command not found
    Cheers.

  4. Jose

    Hello Pranav,
    After to download theTED-Downloader.tar.bz2 I’m used
    tar -jxvf TED-Downloader.tar.bz2
    run-first.sh
    toDownload.txt
    BeautifulSoup.py
    downloader.py
    README

    Then:

    sh run-first.sh
    Traceback (most recent call last):
    File “downloader.py”, line 30, in
    downloadUrl = “http://www.ted.com”+wholeTag['href']
    TypeError: ‘NoneType’ object is unsubscriptable
    sh: downloader.sh: File or directory not found

    Where are the script downloader.sh ?

    Thanks,
    Jose

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>