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: firstname.lastname@example.org # 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, '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()
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)
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!
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.