Channel 9 PowerShell Download Script for Build 2014 Videos

Crazy long title, but you get the idea.

Here is a PowerShell script that will download all of the mp4 high quality videos from Channel 9 for Build 2014.

Change the $baseLocation to a folder of your choosing, and let it go.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
$baseLocation = "V:/Coding/Channel 9/Build 2014/"
 
$rssFeed = New-Object -TypeName XML
$rss = (New-Object System.Net.WebClient).DownloadString("http://s.ch9.ms/Events/Build/2014/RSS/mp4high")
 
$rssFeed.LoadXml($rss)
 
$itemCount = $rssFeed.rss.channel.item.Count
 
for($i = 0; $i -lt $itemCount; $i++)
{
     $fileCount = $i + 1
     Write-Progress -Activity "Downloading Recordings..." -Status "Processing file $fileCount of $itemCount" -PercentComplete (($i/$itemCount)*100)
 
     $item = $rssFeed.rss.channel.item[$i]
 
     $fileExtension = $item.enclosure.url.Substring($item.enclosure.url.lastIndexOf('.'), $item.enclosure.url.length - $item.enclosure.url.lastIndexOf('.'))
 
     $cleanFileName = [RegEx]::Replace($item.title, "[{0}]" -f ([RegEx]::Escape([String][System.IO.Path]::GetInvalidFileNameChars())), '') 
 
     $downloadTo = $baseLocation+$cleanFileName+$fileExtension
 
     If(!(Test-Path $downloadTo)) 
     {
          (New-Object System.Net.WebClient).DownloadFile($item.enclosure.url, $downloadTo)
     }
}

Comments

  1. says

    Thanks for the code! I made a slight change to deal with some strange characters that were coming through and to prefix the titles with the filename.

    #http://calvinallen.net/2014/04/06/channel-9-powershell-download-script-for-build-2014-videos/
    $baseLocation = “C:/Users/Paul/Videos/Build.2014/”

    $rssFeed = New-Object -TypeName XML
    $rss = (New-Object System.Net.WebClient).DownloadString(“http://s.ch9.ms/Events/Build/2014/RSS/mp4high”)
    $rssFeed.LoadXml($rss)
    $itemCount = $rssFeed.rss.channel.item.Count

    Clear-Host
    for($i = 0; $i -lt $itemCount; $i++)
    {
    $fileCount = $i + 1
    Write-Progress -Activity “Downloading Recordings…” -Status “Processing file $fileCount of $itemCount” -PercentComplete (($i/$itemCount)*100)

    $item = $rssFeed.rss.channel.item[$i]

    $fileName = $item.enclosure.url.Substring($item.enclosure.url.lastIndexOf(‘/’) + 1, $item.enclosure.url.length – $item.enclosure.url.lastIndexOf(‘/’) – 1)
    $fileName = $fileName.Substring(0, $fileName.lastIndexOf(‘.’)) + ” ”
    $fileExtension = $item.enclosure.url.Substring($item.enclosure.url.lastIndexOf(‘.’), $item.enclosure.url.length – $item.enclosure.url.lastIndexOf(‘.’))
    $cleanFileName = $item.title.Replace(“’”, “‘”).Replace(“—+[char]8220, “-”).Replace(““”, “‘”).Replace(“””,”‘”)
    $cleanFileName = [RegEx]::Replace($cleanFileName, “[{0}]” -f ([RegEx]::Escape([String][System.IO.Path]::GetInvalidFileNameChars())), ‘ ‘)
    $downloadTo = $baseLocation + $fileName + $cleanFileName + $fileExtension

    If(!(Test-Path $downloadTo))
    {
    (New-Object System.Net.WebClient).DownloadFile($item.enclosure.url, $downloadTo)
    #echo $downloadTo
    }
    }

Leave a Reply