Created
April 8, 2014 04:50
-
-
Save tdavisjr/10092157 to your computer and use it in GitHub Desktop.
Updated for Build 2014; but made year an input parameter. This is a Python3 script. Require one third-part package (pip install feedparser). To run, just type >> python download_build_talks.py
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/python | |
import os | |
import urllib.request | |
import feedparser | |
import math | |
import sys | |
def tofile(title): | |
title = title.replace("?", "").replace("", "").replace("/", "-").replace(":", "-").replace(",", "-").replace("<", "").replace(">","").replace("'","") | |
return title + ".mp4" | |
def handleunicode(title): | |
return title.encode(encoding='ascii',errors='replace').decode(encoding='ascii') | |
def getsessions(year): | |
''' | |
This requires feedparser to be loaded. E.g (pip install feedparser) | |
''' | |
try: | |
url = 'http://channel9.msdn.com/Events/Build/{0}/RSS/mp4high?sort=sequential&direction=desc&term=&t=.net&t=asp.net&t=csharp&t=html5&t=javascript&t=jquery&t=mobile-services&t=node.js&t=rest&t=typescript&t=web&t=web-api&t=web-sites&t=winjs&t=android&t=ios&t=html5&t=visual-studio'.format(year) | |
rss = feedparser.parse(url) | |
return [(tofile(handleunicode(e.title)), e.enclosures[0].href) for e in rss.entries] | |
except: | |
print("Error reading Session RSS feed") | |
print("Url: " + url) | |
return [] | |
def reportprogress(blocksRead, blockSize, totalSize): | |
downloaded = blocksRead * blockSize | |
complete = math.ceil((downloaded / (totalSize * 1.0)) * 100) | |
sys.stdout.write("{0:.0f}%".format(complete)) | |
sys.stdout.write("\r") | |
sys.stdout.write("") | |
sys.stdout.flush() | |
def download(sessions): | |
sessions.sort() | |
for s in sessions: | |
fname = s[0] | |
url = s[1] | |
if not os.path.exists(fname): | |
try: | |
print("Downloading - " + fname) | |
urllib.request.urlretrieve(url, fname, reportprogress) | |
print(fname) | |
except: | |
print("Unable to download " + fname) | |
else: | |
print("Skiping - " + fname) | |
if __name__ == '__main__': | |
year = input('Which year would you like? ') | |
download(getsessions(year)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment