Last active
December 23, 2015 02:59
-
-
Save dmi3/6570252 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# Decription | |
# =========== | |
# Script to run get all TED talks links from the page, then download it in HD | |
# Requirements | |
# ============ | |
# In Linux shell run: | |
# sudo apt-get install python3 python3-setuptools | |
# sudo easy_install3 sh | |
from sh import wget,mkdir | |
from logging import info, error, root, DEBUG | |
import re,os,traceback | |
src = "http://www.reddit.com/r/AskReddit/comments/kfl17/what_are_the_best_ted_talks/?sort=top" | |
output_dir = "~/videos/ted/" | |
root.setLevel(DEBUG) | |
raw = str(wget(src,"-q","-O","-")) | |
talks = re.findall(r'<a.*?href="(http://www\.ted\.com/talks/.*?\.html)">',raw) | |
mkdir("-p", os.path.expanduser(output_dir)) | |
i = 0 | |
for talk in talks: | |
try: | |
talk_raw = str(wget("-q","-O","-",talk)) | |
download = re.findall(r'<a.*?href="(http://download\.ted\.com/talks/.*?apikey=TEDDOWNLOAD)">',talk_raw) | |
if len(download)>0: | |
i+=1 | |
url = download[0].replace(".mp4","-480p.mp4") | |
info("%d. Downloading %s" % (i,download[0])) | |
wget(url, "--content-disposition", "-P", os.path.expanduser(output_dir)) | |
except: | |
error("Error while trying to download %s: %s" % (talk, traceback.print_exc())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment