Skip to content

Instantly share code, notes, and snippets.

@arjancornelissen
Created January 3, 2016 20:55
Show Gist options
  • Save arjancornelissen/db5c6e007bedf65019d3 to your computer and use it in GitHub Desktop.
Save arjancornelissen/db5c6e007bedf65019d3 to your computer and use it in GitHub Desktop.
Blog
<#
.SYNOPSIS
This script can download slides, mp3, mp4 and high quality mp4 files from a Channel 9 RSS feed
Enter the feed like http://channel9.msdn.com/Events/SharePoint-Conference/2014.
This url can be found at the events homepage
.DESCRIPTION
The script itself will only print 'Hello World'. But that's cool. It's main objective is to show off the cool help thingy anyway.
.PARAMETER baseRSSfeedUrl
The URL of the events RSS feed like: http://channel9.msdn.com/Events/SharePoint-Conference/2014
.PARAMETER downloadLocation
The location on your local machine where the files should be downloaded. Keep this path as short as possible like: D:\SPC14
.PARAMETER filetypes
Select the filetypes you want to be downloaded. You can enter multiple filetypes
.EXAMPLE
This example will download all slides, mp3 files and high quality video for the sessions of SPC14
.\download-Channel9Content.ps1 -baseRSSfeedUrl "http://channel9.msdn.com/Events/SharePoint-Conference/2014" -downloadLocation "D:\SPC14" -filetypes mp3, slides, mp4high
.EXAMPLE
This example will download all slides for the sessions of SPC14
.\download-Channel9Content.ps1 -baseRSSfeedUrl "http://channel9.msdn.com/Events/SharePoint-Conference/2014" -downloadLocation "D:\SPC14" -filetypes slides
.NOTES
This script is based on a script that was distributed for the download of all content from SPC14.
That script was Originally published at https://gist.github.com/nzthiago/5736907
.LINK
http://www.arjancornelissen.nl
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True)]
[string]$baseRSSfeedUrl,
[Parameter(Mandatory=$True)]
[string]$downloadLocation,
[ValidateSet("slides","MP3","MP4","MP4High")]
[Parameter(Mandatory=$True)]
[string[]]$filetypes
)
[Environment]::CurrentDirectory=(Get-Location -PSProvider FileSystem).ProviderPath
$rss = (new-object net.webclient)
if (-not (Test-Path $downloadLocation)) {
Write-Host "Folder $fpath dosen't exist. Creating it..."
$dircreated = New-Item $downloadLocation -type directory
}
cd $downloadLocation
foreach ($filetype in $filetypes)
{
$downloadUrl = $baseRSSfeedUrl + "/RSS/" + $filetype
Write-Verbose $downloadUrl
$rssfeed = ([xml]$rss.downloadstring($downloadUrl))
Write-Host "Start downloading $filetype" -ForegroundColor Green
$rssfeed.rss.channel.item | foreach{
$code = $_.comments.split("/") | select -last 1
# Grab the URL for the MP4 file
$url = New-Object System.Uri($_.enclosure.url)
# Create the local file name for the MP4 download
$file = $code + "-" + $_.creator + "-" + $_.title.Replace(":", "-").Replace("?", "").Replace("/", "-").Replace("<", "").Replace("|", "").Replace('"',"").Replace("*","")
$file = $file.substring(0, [System.Math]::Min(120, $file.Length))
switch($filetype)
{
"slides" { $file = $file + ".pptx" }
"MP3" { $file = $file + ".mp3" }
"MP4" { $file = $file + ".mp4" }
"MP4High" { $file = $file + ".mp4" }
}
Write-Host "Downloading file: $file"
if ($code -ne "")
{
Write-Verbose "There is a session code so create a specific folder"
$folder = $code + " - " + $_.title.Replace(":", "-").Replace("?", "").Replace("/", "-").Replace("<", "").Replace("|", "").Replace('"',"").Replace("*","")
$folder = $folder.substring(0, [System.Math]::Min(100, $folder.Length))
}
else
{
Write-Verbose "There is no session code, place the files in the folder NoCodeSessions"
$folder = "NoCodeSessions"
}
if (-not (Test-Path $folder)) {
Write-Host "Folder ($folder) doesn't exist. Creating it..." -ForegroundColor Yellow
$foldercreated = New-Item $folder -type directory
}
# Make sure the MP4 file doesn't already exist
if (!(test-path $folder\$file))
{
Write-Verbose "File that's being downloaded: $file"
$dest = $folder+"\"+$file
Start-BitsTransfer -Source $url -Destination $dest -TransferType Download
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment