My blog has moved!

You will be automatically redirected to the new address. If that does not occur, visit
http://www.kdmcgregor.wordpress.com
and update your bookmarks.

Friday, February 19, 2010

My script for downloading PDC09 presentations

So Microsoft PDC for 2009 was sometime ago. On the site are videos of presentations which are available for download. Having short-listed the presentations that interested me (and it turned out to be all of them), I decided to download the videos and view them at a later date. I had two choices:
1. For each link, right click and chose “Save Target As”
or
2. Find some script to download all videos.

My decision was to find some script to download all the videos. Microsoft does provide a script via a batch file. You need to install cRUL; however my personal decision is to move away from batch files. I could not find any other script online so I decided to create one my self.
Leverage my python skills I created the following script.


import os
import getopt

class DownloadFiles:
def init(self):

self.dic_downloaded_files = {}
self.fname = ""

def download_files(self):
for line in open(self.fname):

linesplit = line.split()
wgetCommand = "wget" + " " + "--output-document=" + linesplit[0]+ ".wmv" + " " + linesplit[1]
os.system(wgetCommand)

def run(self,argv):
self.init()
if "-f" in argv:
self.fname = argv[1]
print "file name : " + self.fname
else:
print "No file in command line"
sys.exit(2)


self.download_files()


if __name__ == "__main__":
DownloadFiles().run(sys.argv[1:])


This script uses the GNU wget.This script parses a text file containing
1. The name of the file when it has been downloaded to disk(linespilt[0]). On the pdc website the name of videos have the name like “CL11”. I want a descriptive name so I can know what this video will be presenting.
2. the url of the video I want to download (linesplit[1]) and the name of the file

The following is a sample a line in the text file
AdvanceWPFApplicationPerformanceTuningandAnalysis http//ecn.channel9.msdn.com/o9/pdc09/wmvhigh/CL11.wmv

This was a script I wrote in about 30 minutes, and I am sure there are some errors somewhere;however I was able to run the script and get all the files. Also I realized I needed extra space on my hard drive.