# PDC09Downloader.rb
#
# By Matt Sherman (matt@mattandjulie.org)
#
# Based on Mike Swanson's downloader and renamer found at:
# http://microsoftpdc.com/Videos

$sessions =
{
    'KYN01-PGM' => 'Day 1 Keynote',
    'KYN02-PGM' => 'Day 2 Keynote',
    'CL09' => 'How Microsoft Visual Studio 2010 Was Built with Windows Presentation Foundation 4',
    'CL18' => 'Windows Ribbon Technical Deep Dive',
    'FT02' => 'Data Programming and Modeling for the Microsoft .NET Developer',
    'FT06' => 'Accelerated Windows Application Development with Microsoft Visual C++ 2010',
    'FT11' => 'Future Directions for C# and Visual Basic',
    'PR05' => 'Microsoft Unified Communications Developer Platform Futures',
    'SVC01' => 'Lap Around the Windows Azure Platform',
    'SVC10' => 'Software + Services Identity Roadmap Update',
    'SVC20' => 'Bridging the Gap from On-Premises to the Cloud',
    'SVR03' => 'Data Tier Applications in Visual Studio 2010',
    'CL30' => 'Microsoft Expression Blend 3 for Developers Tips, Tricks and Best Practices',
    'CL33' => 'Windows Error Reporting',
    'FT30' => 'Using Dynamic Languages to Build Scriptable Applications',
    'FT31' => 'Dynamic Binding in C# 4',
    'PR31' => 'Managing the Solution Lifecycle for xRM Applications',
    'SVC30' => 'Lessons Learned Migrating Applications to the Windows Azure Platform',
    'SVC37' => 'Introduction to Building Applications with Windows Azure',
    'SVR33' => 'Building Location Aware Applications with the SQL Server Spatial Library',
    'VTL30' => 'Managing Development to Inspire Innovation and Create Great User Experiences',
    'VTL32' => 'Concurrency Fuzzing & Data Races',
    'CL04' => 'Windows 7 and Windows Server 2008 R2 Kernel Changes',
    'CL14' => 'Advanced Graphics Functionality Using DirectX',
    'CL25' => 'Become a Web Debugging Virtuoso with Fiddler',
    'FT18' => 'Microsoft ASP.NET Futures',
    'FT19' => 'C++ Forever Interactive Applications in the Age of Manycore',
    'FT25' => 'Microsoft Application Server Technologies Present and Future',
    'PR02' => 'Overview of SharePoint 2010 Programmability',
    'SVC13' => 'Windows Azure Present and Future',
    'SVR01' => 'Accelerating Applications Using Windows HPC Server 2008',
    'SVR14' => 'Building Live Media Viewing Experiences Using Internet Information Services (IIS) Smooth Streaming and the Smooth Streaming Player SDK',
    'CL13' => 'Windows Touch Deep Dive',
    'CL29' => 'Windows 7 and Windows Server 2008 R2 Kernel Changes (Continued from 130 Session)',
    'FT10' => 'Evolving ADO.NET Entity Framework in Microsoft .NET Framework 4 and Beyond',
    'FT28' => 'Microsoft .NET Micro Framework and Intelligent Devices',
    'FT57' => 'Microsoft ASP.NET 4 Core Runtime for Web Developers',
    'PR11' => 'Leveraging and Extending Microsoft SharePoint Server 2010 Identity Features',
    'SVC52' => 'SQL Azure Database Present and Future',
    'SVR15' => 'Microsoft BizTalk Server Futures and Roadmap',
    'SVR17' => 'Data-Intensive Computing on Windows HPC Server with the DryadLINQ Framework',
    'CL11' => 'Advanced Windows Presentation Foundation Application Performance Tuning and Analysis',
    'CL17' => 'Building Sensor- and Location-Aware Applications with Windows 7 and .NET Framework 4',
    'CL23' => 'SketchFlow Prototyping to the Rescue',
    'FT03' => 'Manycore and the Microsoft .NET Framework 4 A Match Made in Microsoft Visual Studio 2010',
    'FT08' => 'Code Visualization, UML, and DSLs',
    'PR10' => 'SharePoint Is Not Just On-Premise Developing and Deploying Solutions to Microsoft SharePoint Online',
    'SVR16' => 'Connecting Applications with the Microsoft BizTalk Enterprise Service Bus Toolkit',
    'VTL01' => 'Code Contracts and Pex Power Charge Your Assertions and Unit Tests',
    'CL01' => 'Microsoft Silverlight Roadmap and Futures',
    'FT50' => 'Building Data-Driven Applications Using Microsoft Project Code Name Quadrant and Microsoft Project Code Name M',
    'FT52' => 'Microsoft Perspectives on the Future of Programming',
    'FT55' => 'Developing REST Applications with the .NET Framework',
    'FT59' => 'ASP.NET MVC 2 Ninjas Still on Fire Black Belt Tips',
    'PR13' => 'Integrating and Extending the Microsoft Office Communicator Experience with Windows Presentation Foundation and Microsoft Silverlight',
    'SVC02' => 'Windows Identity Foundation Overview',
    'SVC03' => 'Development Best Practices and Patterns for Using Microsoft SQL Azure Databases',
    'SVC15' => 'Windows Azure Monitoring, Logging, and Management APIs',
    'CL31' => 'Mastering WPF Graphics and Beyond',
    'CL34' => 'Media Foundation Supporting Hardware Codecs and Cameras',
    'FT32' => 'Code Like the Wind with Microsoft Visual Basic 2010',
    'FT34' => 'Microsoft Project Code Name M The Data and Modeling Language',
    'FT36' => 'Future of Garbage Collection',
    'SVC31' => 'Lessons Learned Building On-Premises and Cloud Applications with the Service Bus and Windows Azure',
    'SVC32' => 'Lessons Learned Building Scalable Applications with the Windows Azure Platform',
    'SVR31' => 'Making Microsoft SQL Server 2008 Fly',
    'VTL31' => 'Coming Together in the Cloud',
    'CL15' => 'Modern 3D Graphics Using Windows 7 and Direct3D 11 Hardware',
    'FT12' => 'ADO.NET Data Services What\'s New with the RESTful Data Services Framework',
    'FT17' => 'Spice Up Your Applications with Windows Workflow Foundation 4',
    'FT58' => 'What\'s New in Microsoft ASP.NET 4 Web Forms and Dynamic Data',
    'SVC16' => 'Developing Advanced Applications with Windows Azure',
    'SVC28' => 'The \'M\'-Based System.Identity Model for Accessing Directory Services',
    'SVC53' => 'Tips and Tricks for Using Visual Studio 2010 to Build Applications that Run on Windows Azure',
    'SVR11' => 'Improving Application Compatibility and Quality for Windows Server 2008 R2',
    'VTL05' => 'A New Approach to Exploring Information on the Web',
    'CL06' => 'Networking and Web Services in Microsoft Silverlight',
    'FT04' => 'Windows Workflow Foundation 4 from the Inside Out',
    'FT07' => 'The State of Parallel Programming',
    'FT29' => 'Microsoft AJAX Library, jQuery, and Microsoft Visual Studio 2010',
    'PR06' => 'Developing Solutions with Business Connectivity Services in Microsoft SharePoint Server 2010',
    'SVC09' => 'Windows Azure Tables and Queues Deep Dive',
    'SVC17' => 'Enabling Single Sign-On to Windows Azure Applications',
    'SVR13' => 'Windows PowerShell An Automation Toolbox for Building Solutions That Span Small Businesses, Enterprises, and Cloud Services',
    'VTL04' => 'Rx Reactive Extensions for .NET',
    'CL12' => 'Developing with the Windows API Code Pack for Microsoft .NET Framework',
    'CL22' => 'Advanced Topics for Building Large-Scale Applications with Microsoft Silverlight',
    'FT22' => 'Microsoft ASP.NET MVC 2 The New Stuff',
    'FT23' => 'Extending the Microsoft Visual Studio 2010 Code Editor to Visualize Runtime Intelligence',
    'FT26' => 'Scaling Your Data Tier with Microsoft Project Code Name Velocity',
    'SVC04' => 'Petabytes for Peanuts! Making Sense out of Ambient Data',
    'SVC14' => 'Storing and Manipulating Blobs and Files with Windows Azure Storage',
    'SVC19' => 'REST Services Security Using the Access Control Service',
    'SVC54' => 'The Business of Windows Azure  What you should know about Windows Azure Platform pricing and SLAs',
    'SVR12' => 'Building Your Administration GUI over Windows PowerShell',
    'CL02' => 'Microsoft Silverlight 3 Advanced Performance and Profiling Techniques',
    'CL05' => 'Embodiment The Third Great Wave of Computing Applications',
    'CL16' => 'Optimizing for Performance with the Windows Performance Toolkit',
    'FT21' => 'PLINQ LINQ, but Faster!',
    'FT56' => 'Web Deployment Painkillers Microsoft Visual Studio 2010 & MS Deploy',
    'PR03' => 'Developer Patterns to Integrate Microsoft Silverlight 3.0 with Microsoft SharePoint 2010',
    'SVC08' => 'Patterns for Building Scalable and Reliable Applications with Windows Azure',
    'SVC18' => 'Building Hybrid Cloud Applications with Windows Azure and the Service Bus',
    'SVR10' => 'Lighting up Windows Server 2008 R2 Using the ConcRT on UMS',
    'VTL03' => 'Infer.NET Building Software with Intelligence',
    'CL10' => 'Windows Presentation Foundation 4 Plumbing and Internals',
    'FT13' => 'What\'s New for Windows Communication Foundation 4',
    'FT53' => 'Microsoft Visual Studio Lab Management to the Build Setup Rescue',
    'FT60' => 'A Lap Around Microsoft Visual Studio and Team Foundation Server 2010',
    'PR07' => 'Developing Solutions for Microsoft SharePoint Server 2010 Using the Client Object Model',
    'SVC06' => 'Scaling out Web Applications with Microsoft SQL Azure Databases',
    'SVC25' => 'Automating the Application Lifecycle with Windows Azure',
    'SVR07' => 'Introduction to Microsoft SQL Server 2008 R2 StreamInsight',
    'SVR18' => 'Developing Applications for Scale-Up Servers Running Windows Server 2008 R2',
    'VTL02' => 'Axum A .NET Language for Safe and Scalable Concurrency',
    'CL03' => 'DirectX11 DirectCompute',
    'CL21' => 'Building Amazing Business Applications with Microsoft Silverlight and Microsoft .NET RIA Services',
    'CL27' => 'Multi-Touch on Microsoft Surface and Windows 7 for .NET Developers',
    'FT14' => 'Workflow Services and Dublin',
    'FT20' => 'F# for Parallel and Asynchronous Programming',
    'FT24' => 'Building Extensible Rich Internet Applications with the Managed Extensibility Framework',
    'PR09' => 'Document Assembly and Manipulation on Microsoft SharePoint Server 2010 Using Word Automation Services and Open XML',
    'SVC12' => 'Microsoft SQL Azure Database Under the Hood',
    'SVR09' => 'Developing Rich Reporting Solutions with Microsoft SQL Server 2008 R2',
    'SVR19' => 'Microsoft Project Code Name Repository Using Metadata to Drive Application Design, Development, and Management',
    'CL32' => 'Developing Testable Silverlight Applications',
    'CL35' => 'Custom Behaviors for Advanced Microsoft Silverlight UI Effects',
    'CL36' => 'Deep Dive on Bing Maps Silverlight Control',
    'FT33' => 'Microsoft Visual Basic IDE Tips and Tricks',
    'FT35' => 'Microsoft Visual C# IDE Tips and Tricks',
    'PR30' => 'The Exchange 2010 Developer Story Building Rich Exchange-enabled Applications for the Enterprise and the Cloud',
    'PR33' => 'Build a .NET Business Application in 60 Minutes with xRM and SharePoint',
    'SVC33' => 'Lessons Learned Building Multi-Tenant Applications with the Windows Azure Platform',
    'SVC36' => 'Microsoft adPlatform Opportunities for Developers',
    'SVR32' => 'Microsoft Semantic Engine',
    'CL07' => 'Mastering Microsoft .NET RIA Services',
    'CL24' => 'XAML Futures in Microsoft .NET Framework, Microsoft Silverlight and Tools',
    'CL28' => 'New Developer Tools in Windows Embedded Standard 2011',
    'FT09' => 'Scrum in the Enterprise and Process Customization with Microsoft Visual Studio 2010',
    'FT16' => 'Advanced Diagnostics, IntelliTrace™ and Test Automation',
    'FT27' => 'Application Server Extensibility with Microsoft Project Code Name Dublin and Microsoft .NET Framework 4',
    'PR12' => 'It\'s All about the Services Developing Custom Applications for Microsoft SharePoint Server 2010 Using Microsoft ASP.NET, WCF, and REST',
    'SVC27' => 'The Future of Database Development with SQL Azure',
    'SVR02' => 'Using Classification for Data Security and Data Management',
    'SVR06' => 'Extending Internet Information Services (IIS) 7.x',
    'CL26' => 'The Audience API Live Framework Present and Future',
    'FT05' => 'Automating Done Done in  the Team Workflows with Microsoft Visual Studio Ultimate and Team Foundation Server 2010',
    'FT54' => 'Power Tools for Debugging',
    'PR01' => 'Developing xRM Solutions Using Windows Azure',
    'PR14' => 'Unleashing the Power of Excel on the Web',
    'SVC23' => 'Using the Microsoft Sync Framework to Connect Apps to the Cloud',
    'SVC26' => 'How Microsoft SharePoint 2010 was Built with the Windows Identity Foundation',
    'SVR08' => 'Advanced Microsoft SQL Server 2008 R2 StreamInsight'
}

$extensions = 
{
    'wmvhigh' => 'wmv',
    'wmv' => 'wmv',
    'mp4' => 'mp4',
    'pptx' => 'pptx'
}

$folders = 
{
    'wmvhigh' => 'wmvhigh',
    'wmv' => 'wmv',
    'mp4' => 'mp4',
    'pptx' => 'ppt'
}

$baseUrl = 'http://ecn.channel9.msdn.com/o9/pdc09/'

def createCurlCommand(url, fileName, proxy)
    curlCommand = "curl"

    if proxy != nil
        curlCommand += " -x " + proxy
    end

    curlCommand += " " + url + " -o \"" + fileName + "\""

    return curlCommand
end

def downloadFile(sessionId, fileType, proxy)
    url = $baseUrl + $folders[fileType] + '/' + sessionId + '.' + $extensions[fileType]
    fileName = sessionId + ' - ' + $sessions[sessionId] + '.' + $extensions[fileType]
    curlCommand = createCurlCommand(url, fileName, proxy)

    puts fileName + ":\n"
    
    system curlCommand

    puts "\n"
end

if ARGV.size == 0
    puts "PDCDownloader.rb <filetype> [proxyhost:proxyport])\n\nPass the type of file you\'d like to download (WMVHIGH, WMV, MP4 or PPTX). For example:\n\nPDC09Downloader.rb MP4\n\nOptionally, also pass a proxy host name and port:\n\nPDCDownloader.rb MP4 proxy.example.com:8080"
else
    fileType = ARGV[0].downcase
    proxy = ARGV[1]

    if $extensions[fileType] == nil
        puts "Unsupported type of file."
    else
        puts "Downloading " + fileType + " files...\n\n"

        $sessions.each_key do |sessionId|
           downloadFile(sessionId, fileType, proxy)
        end
    end
end

