Skip to content

Instantly share code, notes, and snippets.

@tdavisjr
Last active December 19, 2015 04:29
Show Gist options
  • Save tdavisjr/e5e78282052a10701954 to your computer and use it in GitHub Desktop.
Save tdavisjr/e5e78282052a10701954 to your computer and use it in GitHub Desktop.
Python script to download all the Build 2013 Web Developer Related sessions (only). If you like to include all sessions, just modify the url by removing all the querystring parameters. http://channel9.msdn.com/Events/Build/2013 Note: since python requires proper indending, make sure open this file to make sure all indents are tabs or all are spaces
#!/usr/bin/python
import os, urllib, feedparser, math, sys
def handleunicode(title):
return title.encode(encoding='ascii',errors='replace')
def tofile(title):
title = title.replace("?", "-").replace("$", "-").replace("/", "-").replace(":", "-").replace(",", "-").replace("<", "").replace(">","")
return title + ".mp4"
def getsessions():
'''
This requires feedparser to be loaded. E.g (pip install feedparser)
'''
try:
url = 'http://channel9.msdn.com/Events/Build/2013/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'
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")
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(fname)
urllib.urlretrieve(url, fname, reportprogress)
except:
print("Unable to download " + url)
if __name__ == '__main__':
download(getsessions())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment