-
-
Save roder/279805 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/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