Updated version: Download MMS 2013 Videos from Channel 9

Updated version: Download MMS 2013 Videos from Channel 9

  • Comments 10
  • Likes

Sitting at the McCarran International Airport waiting for my flight to Amsterdam (the Netherlands) I had some time to kill so I wrote a simpel PowerShell script which helps to easily download the MMS 2013 sessions from the Channel 9 RSS feed.

Using the Out-GridView Cmdlet you can easily select the sessions you are interested in. Click on Ok when finished selecting the sessions you are interested in downloading.

 

image

After creating my initial version I got some feedback that sometimes the script did not work and with the help of Jamie Moyer (also a Senior PFE like me) we made the script more robust and added extra features like a HTML Report overview.

You can even use the –verbose switch and other parameters to tweak the download folder. We hope you like the improvements.

#######################################################################################################################                        
# Description:   Download MMS 2013 Channel 9 videos
# PowerShell version: 3                   
# Author(s):     Stefan Stranger (Microsoft)
#                Jamie Moyer (Microsoft          
# Example usage: Run Get-MMS2013Channel9Videos.ps1 -path c:\temp -verbose
#                Select using the Out-Gridview the videos you want to download and they are stored in your myvideos folder.
#                You can multiple select videos, holding the ctrl key.
# Disclamer:     This program source code is provided "AS IS" without warranty representation or condition of any kind
#                either express or implied, including but not limited to conditions or other terms of merchantability and/or
#                fitness for a particular purpose. The user assumes the entire risk as to the accuracy and the use of this
#                program code.
# Date:          04-13-2012                        
# Name:          Get-MMS2013Channel9Videos.ps1            
# Version:       v1.001 - 04-14-2012 - Stefan Stranger - initial release
# Version:       v1.005 - 04-29-2013 - Jamie Moyer, Stefan Stranger - added more robustness and HTML Report
########################################################################################################################
#requires -version 3.0

[CmdletBinding()]
Param
(
        # Path where to store video's locally
        [Parameter(Mandatory=$false,
                   Position=0)]
        $Path = [environment]::getfolderpath("myvideos") + "\MMS2013",
        [Parameter(Mandatory=$false,
                   Position=1)]
        $rssfeed = "http://channel9.msdn.com/Events/MMS/2013/RSS"
    )

function Get-NewFileName($name)
{
    Write-Verbose "Calling Get-NewFileName Function"
    $r=$Path+"\"+(($name -replace "[^\w\s\-]*") -replace "\s+") + ".wmv";$r
}

Write-Verbose "Remove last slash if added using the downloaddirectory Parameter"
if ($path.EndsWith("\")){$path = $path.Substring(0,$path.Length-1)}
write-verbose "Path is: $path"

Write-Verbose "Checking if Download directory $Path exists"
if(!(test-path $Path -PathType Container))
{
    Write-Verbose "Creating $Path"
    New-Item -ItemType Directory $Path | Out-Null
}

Write-Verbose "Downloading RSS Feed Items from $rssfeed"
$feeditems = Invoke-RestMethod $rssfeed
[array]$feeditemsWithDetails = $feeditems | 
    select Title, Summary, Duration, Enclosure,creator | 
        Add-Member -MemberType ScriptProperty -Name AlreadyDownloaded -Value {(test-path("$Path\$($this.enclosure.url.split('/')[6])"))} -PassThru -Force |
        Add-Member -MemberType ScriptProperty -Name Destination -Value {("$Path\$($this.enclosure.url.split('/')[6])")} -PassThru -Force |
        Add-Member -MemberType ScriptProperty -Name Source -Value {$this.enclosure.url} -PassThru -Force |
            select AlreadyDownloaded,Title, Summary, Duration, Enclosure,Source,Destination,creator | sort Title

Write-Verbose "Add all already downloaded items back to the list"
$duplicateVideoNames = $feeditemsWithDetails |sort name| group destination | where-object {$_.Name -ne "" -and $_.Count -gt 1} | 
    ForEach-Object {$_.Group}

Write-Verbose "Remove the posts with duplicate file names from the feeditemsSelected array"
$feeditemsSelected = @($feeditemsSelected | Where-Object {$duplicateVideoNames -notcontains $_})

Write-Verbose "Change video names to filenames, check to see if they are downloaded already and added them back to the array with updated details"
$duplicateVideoNames | foreach-object {
                                        $newDestination = Get-NewFileName $_.Title
                                        $_.Destination = $newDestination
                                        $_.AlreadyDownloaded = (Test-Path $newDestination)
                                        $feeditemsWithDetails += $_
                                      }

Write-Verbose "Open Out-GridView to select vidoes to download"
[array]$feeditemsSelected = $feeditemsWithDetails| Out-GridView -PassThru | 
    select AlreadyDownloaded,Title, Summary, Duration, Enclosure,Source,Destination

Write-Verbose "Downloading videos"
$feeditemsSelected |Where-Object{!(Test-Path $_.Destination)} | 
    select Source,Destination | 
        Start-BitsTransfer -Priority Normal | Out-Null

Write-Verbose "Add all already downloaded items back to the list"
$feeditemsWithDetails | where-object {$_.AlreadyDownloaded} | 
                            foreach-object {
                                                if(-not [bool]($feeditemsSelected | Select-String $_.Title -Quiet))
                                                {
                                                    $feeditemsSelected += $_
                                                }
                                           }

Write-Verbose "Create HTML Report"
$feeditemsSelected | sort Name | Out-Null
$html = $feeditemsSelected |?{Test-Path "$($_.Destination)"} | % {@"
     <H4><a href="$($_.Destination)">$($_.Title)</a></H4> 
     <H5>Speaker(s): $($_.creator)</H5>
     <H5>$($_.Summary)</H5>
"@}

Write-Verbose "Open HTML Report"
ConvertTo-Html -Head "<h1>My Downloaded MMS Videos - $($feeditemsSelected.Count) Downloaded</h1>" -Body $html | 
    Out-File $Path\MyMMSContent.html;start "$Path\MyMMSContent.html"

image

Have fun!

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Hi

    Running your script get error:

    Invoke-RestMethod : The remote server returned an error: (407) Proxy Authentica

    tion Required.

    At line:18 char:14

    + $feeditems = Invoke-RestMethod $rssfeed

    +              ~~~~~~~~~~~~~~~~~~~~~~~~~~

       + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:Htt

      pWebRequest) [Invoke-RestMethod], WebException

       + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShe

      ll.Commands.InvokeRestMethodCommand

    When I run in web browser channel9.msdn.com/.../RSS the Outlook is starting and it is trying to create a new directery under Mailbox\RSS Feed

    I will that script open only the GridView only window

    Regards

    "Stisse"

  • Cool, works superb. Thx!

  • Hi Stisse,

    I just tested the script and it it seems to work for me ok. I think you have a proxy authentication issue. My guess is that you need a proxy to connect to external websites.

    Try from a connection that does not need a proxy.

    Stefan

  • Where do the files get downloaded into? What format is selected for download?

  • Hi Stephan,

    I'm getting the following error. Any ideas?

    Start-BitsTransfer : HTTP status 400: The server cannot process the request because the syntax is not valid.

    At C:\Users\Administrator\Documents\Untitled1.ps1:23 char:17

  • Hi Patrick,

    The files get downloaded to your temp folder specified in the environment variable. Run $env:temp from PowerShell to check.

    The format is *.wmv

    First save the script to Get-MMS2013Channel9Videos.ps1 and run .\Get-MMS2013Channel9Videos.ps1 Still getting the error?

    Could be that one of the links on the Channel9 is incorrect. I just tested the script again and it just seems to work.

    Are you using PowerShell version 3?

    Which session are you trying to download? Maybe it's only one session that is failing?

    /Stefan    

  • Hi Stephan,

    I made the changes you suggested, and about half of the videos download. There seem to be some connection issues. I will attempt it a second time.

    Cheers,

    Patrick

  • "Those who forget to script are doomed to repeat their work." (cit)

  • very useful. I was wondering if there is a way to also download the PPTX files?

  • Hi ShipInTheNight,

    No sorry, these are not published on the Channel 9 website.

    /Stefan