Skip to content

Instantly share code, notes, and snippets.

@tswicegood
Created January 18, 2010 05:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tswicegood/279804 to your computer and use it in GitHub Desktop.
Save tswicegood/279804 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os
import feedparser
import pprint
import subprocess
TED_FEED = "http://feeds.feedburner.com/tedtalks_video"
def need_to_download(entries):
for entry in entries:
file_path = os.path.join(os.getcwd(), itunes_like_filename(entry))
if os.path.exists(file_path):
continue
yield entry
def run(command):
command = subprocess.Popen(command, shell = True)
return command.wait()
def get_hd_url(entry):
return entry['guid'].replace('.mp4', '_480.mp4')
def do_download(entry):
hd_url = get_hd_url(entry)
run('wget %s' % hd_url)
do_rename(entry)
def do_rename(entry):
hd_url = get_hd_url(entry)
file_name = os.path.basename(hd_url)
run("mv '%s' '%s'" % (file_name, itunes_like_filename(entry)))
def itunes_like_filename(entry):
return entry['title'].replace(':', '_') + '.mp4'
feed = feedparser.parse(TED_FEED)
[do_download(e) for e in [entry for entry in need_to_download(feed['entries'])]]
#for entry in need_to_rename(feeds['entries']):
#print entry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment