Download mvcConf session videos with a PowerShell script (should work with other Channel 9 feeds, too)

I tweaked my NuGet downloader PowerShell script to handle the Channel 9 media feeds, so you can grab a local copy of all session videos in the format of your choice:

  • WMV (high and low quality)
  • MV4 (high and low quality)
  • MP3
  • WMA

There are a few ultra-premium professional features in this script, like a download progress bar, logic to skip download if you’ve already grabbed some of the files, and pre-written filter strings to let you select the media type. Despite these advanced features, I pledge to think about keeping this script free for community use.

Just kidding, it’s Public Domain, like all the code on my blog.

Works with other Channel 9 feeds

The first setting is the feed url, which is different for each series or show. You can browse to a show / series, grab the RSS feed link, and update the script.

Why a script to download from an RSS feed?

This is a great question. The deal is that the Channel 9 RSS feed includes the low quality video file as the default enclosure. That makes sense in most cases, but not when you need to read code. I already had a script which did most of the work, so I just added some logic to grab the media URL based on some (admittedly a bit ugly) string matching.

I wouldn’t be surprised if there’s a smarter way, like adding a parameter to the RSS feed or something. Until I hear differently, I assert that this is a great script because it works on my machine.

Note: Now that I’ve got a local copy, I’ll be uploading a torrent via ClearBits, which is a bit more efficient than having everyone pull them from Channel 9.

How To Use

(same instructions as the NuGet downloader script – see that post for a little more detail and screenshots)

The easiest way to use the following script (included at the end of this post) is to open it in the PowerShell ISE (Integrated Scripting Environment). If you're running Windows 7 , just tap the Windows key and type "powershell" - you should see "Windows PowerShell ISE" show up in your Programs list. Paste in the code, save it if you'd like, and hit F5 to run it.

mvcConf Downloader

You can also paste the whole script into the NuGet Package Manager Console, but you lose the beautiful progress bar and maybe some other features.

There are a few settings you may want to tweak:

  • feedUrl indicates the feed you’re downloading. It’s already set for mvcConf, but you can change it to download other series.
  • overwrite indicates whether you want to force downloading even if you already have a file. It defaults to false, meaning that files you’ve already got will be skipped.
  • destinationDirectory defaults to a new folder called mvcConfVideo in your Documents folder. You can change that to any path you’d like.
  • downloadFilter determines which media type will be downloaded. Default is HD WMV. To change the media type, just copy the download filter string from the list shown below.

The Script

# --- settings ---
$feedUrl = "http://channel9.msdn.com/Series/mvcConf/RSS"
$overwrite = $false
$destinationDirectory = join-path ([Environment]::GetFolderPath("MyDocuments")) "mvcConfVideo"

# Download filter options
# "_high_ch9\.mp4"               - High quality mp4
# "_low_ch9\.mp4"                - Low quality mp4
# "_2MB_ch9\.wmv"                - High quality wmv (default)
# "^((?>(?!_2MB).)*)_ch9\.wmv"   - Low quality wmv (excluding high quality wmv)
# "_ch9\.wma"                    - WMA (audio)
# "_ch9\.mp3"                    - MP3
$downloadFilter = "_2MB_ch9\.wmv"

# --- locals ---
$webClient = New-Object System.Net.WebClient

# --- functions ---
function DownloadEntries {
 param ([string]$feedUrl) 
 $feed = [xml]$webClient.DownloadString($feedUrl)
 $progress = 0
 $entries = $feed.rss.channel.item.Length
 $feed.rss.channel.item | foreach {
    $url = New-Object System.Uri(($_.group.content | where {$_.url -match $downloadFilter}).url)
    $fileName = $url.Segments[-1]
    $saveFileName = join-path $destinationDirectory $fileName
    $pagepercent = [Math]::floor((++$progress)/$entries*100)
    if ((-not $overwrite) -and (Test-Path -path $saveFileName)) 
    {
        write-progress -activity "$fileName already downloaded" -status "$pagepercent% of current page complete" -percentcomplete $pagepercent
    }
    else 
    {
        write-progress -activity "Downloading $fileName" -status "$pagepercent% of current page complete" -percentcomplete $pagepercent
        $webClient.DownloadFile($url, $saveFileName)
    }
  }
}  

# --- do the actual work ---

# if dest dir doesn't exist, create it
if (!(Test-Path -path $destinationDirectory)) { New-Item $destinationDirectory -type directory }

DownloadEntries $feedUrl

1 Comment

  • firstly, Thanks for the code. well I am now downloading the files but I have run into some problems;

    first of all, I couldn't run the script beacuse of some restriction policy. set a new excecution policy with below script code inside power shell;

    Set-ExecutionPolicy RemoteSigned

    but I couldn't run it either and I figured it might be that I didn't run ps with admin role. I started ps with admin role and set the Set-ExecutionPolicy RemoteSigned and I am all good to go now. I will take a while I guess to download aIl the files.

Comments have been disabled for this content.