Skip to content

Instantly share code, notes, and snippets.

@DerAlbertCom
Created February 21, 2011 20:35
Show Gist options
  • Save DerAlbertCom/837672 to your computer and use it in GitHub Desktop.
Save DerAlbertCom/837672 to your computer and use it in GitHub Desktop.
PowerShell Scripts for Downloading Channel 9 Videos
# --- settings ---
$feedUrl = $Args[0]
$url = New-Object System.Uri($feedUrl)
$overwrite = $false
$destinationDirectory = join-path "C:\Channel9\" $url.Segments[-2]
# 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
$pagepercent = 0
$entries = $feed.rss.channel.item.Length
$invalidChars = [System.IO.Path]::GetInvalidFileNameChars()
$feed.rss.channel.item | foreach {
$url = New-Object System.Uri(($_.group.content | where {$_.url -match $downloadFilter}).url)
$name = $_.title
$extension = [System.IO.Path]::GetExtension($url.Segments[-1])
$fileName = $name + $extension
$invalidchars | foreach { $filename = $filename.Replace($_, ' ') }
$saveFileName = join-path $destinationDirectory $fileName
$tempFilename = $saveFilename + ".tmp"
$filename
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, $tempFilename)
rename-item $tempFilename $saveFileName
}
$pagepercent = [Math]::floor((++$progress)/$entries*100)
}
}
# --- do the actual work ---
# if dest dir doesn't exist, create it
if (!(Test-Path -path $destinationDirectory)) { New-Item $destinationDirectory -type directory }
DownloadEntries $feedUrl
@DerAlbertCom
Copy link
Author

Channel9Downloader.ps1 Channel9FeedUrl

Make sure you changed the basepath of the $destingationDirectory to your needs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment