Last active
October 3, 2017 05:22
-
-
Save keithga/cb124fa3d2f96ac58470831c52d359a7 to your computer and use it in GitHub Desktop.
Download Ignite content
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
Script to assist finding content to download from MS Ignite 2017 | |
Will use the script Get-IngiteSession.ps1 from: https://gallery.technet.microsoft.com/Ignite-2016-Slidedeck-and-296df316 | |
#> | |
[cmdletbinding()] | |
param( | |
[string] $URI = 'https://gallery.technet.microsoft.com/Ignite-2016-Slidedeck-and-296df316/file/180223/1/Get-IgniteSession.ps1', | |
[string]$DownloadFolder = "$ENV:SystemDrive\Ignite", | |
[string[]] $IgniteProperties = @( 'sessionCode', 'title', 'abstract', 'dayOfTheWeek', 'topics', 'format', 'audience', 'levels', 'personas', 'durationInMinutes', 'products', 'tags', 'speakerNames', 'speakerIds', 'slideDeck', 'onDemand', 'downloadVideoLink' ) | |
) | |
Function Remove-InvalidFileNameChars { | |
param( | |
[Parameter(Mandatory=$true, | |
Position=0, | |
ValueFromPipeline=$true, | |
ValueFromPipelineByPropertyName=$true)] | |
[String]$Name | |
) | |
$invalidChars = [IO.Path]::GetInvalidFileNameChars() -join '' | |
$re = "[{0}]" -f [RegEx]::Escape($invalidChars) | |
return ($Name -replace $re) | |
} | |
if ( -not ( test-path $DownloadFolder ) ) { | |
new-item -ItemType directory -Path $DownloadFolder -ErrorAction SilentlyContinue -force | out-null | |
} | |
#region Download and Cache session list | |
############################## | |
$IgniteCache = join-path $DownloadFolder 'IgniteSessionCache.xml' | |
if ( -not ( test-path $IgniteCache ) ) { | |
Write-verbose "Get meta-data on sessions" | |
$LocalSCript = Join-Path $DownloadFolder (split-path $URI -leaf) | |
if ( -not ( test-path $LocalScript ) ) { | |
write-verbose "download Script $URI" | |
Invoke-WebRequest -UseBasicParsing -Uri $URI -OutFile $LocalScript | |
} | |
$IgniteList = & $LocalScript -InfoOnly | |
remove-item -Path $LocalScript -ErrorAction SilentlyContinue | out-null | |
$IgniteList | Export-Clixml -Path $IgniteCache | |
} | |
else { | |
$IgniteList = Import-Clixml -path $IgniteCache | |
} | |
#endregion | |
#region Parse the list and display in out-gridview | |
############################## | |
$MyList = $igniteList | | |
# We are only intrested in presentations with content. | |
where { $_.SlideDeck -or $_.DownloadVideoLink -or $_.OnDemand } | | |
# Don't display any repeat sessions | |
where { ! $_.SessionCode.EndsWith('R') } | | |
select -Property $IgniteProperties | | |
Out-GridView -Title 'Select Items to download (use ctrl to select more than one)' -OutputMode Multiple | |
$count = $MyList | measure-object | % Count | |
write-host "Selected $count Items" | |
if ( $Count -eq 0 ) { exit } | |
#endregion | |
#region Display OnDemand content | |
############################## | |
if ( [System.Windows.MessageBox]::Show("Found $Count Items`r`n`r`nOK to generate ONDemand link?",'Ignite Download','YesNo','Info') -eq 'yes' ) { | |
write-host "List of OnDemand Content: " | |
$MyList | ? { $_.OnDemand } | ft -Property Title,onDemand | out-string -Width 200 | write-host | |
$MyList | ? { ! $_.OnDemand -and $_.slideDeck } | ft -Property Title,slideDeck | out-string -Width 200 | write-host | |
"<html><head><title>OnDemand Ignite Session List</title></head><body>" > $DownloadFolder\OnDemandList.html | |
$MyList | ? { $_.OnDemand } | % { "<a href=""$($_.onDemand)"">$($_.SessionCode) - $($_.Title)</a></br>" } >> $DownloadFolder\OnDemandList.html | |
"</br></br>" >> $env:temp\OnDemandList.html | |
$MyList | ? { ! $_.OnDemand -and $_.slideDeck } | % { "<a href=""https:$($_.slideDeck)"">$($_.SessionCode) - $($_.Title)</a></br>" } >> $DownloadFolder\OnDemandList.html | |
"</body></html>" >> $DownloadFolder\OnDemandList.html | |
start $DownloadFolder\OnDemandList.html | |
} | |
#endregion | |
#region Download content | |
############################## | |
if ( [System.Windows.MessageBox]::Show("Found $Count Items`r`n`r`nOK to Download to: $DownloadFolder",'Ignite Download','YesNo','Info') -eq 'yes' ) { | |
$MyList | | |
foreach-object { | |
if ( $_.DownloadVideoLink ) { | |
[PSCustomObject] @{ Source = $_.DownloadVideoLink; Destination = join-path $DownloadFolder ( Remove-InvalidFileNameChars "$($_.SessionCode) - $($_.Title).mp4" ) } | |
} | |
elseif ( $_.SlideDeck ) { | |
[PSCustomObject] @{ Source = [System.Web.HttpUtility]::UrlDecode( $_.Slidedeck.replace('//view.officeapps.live.com/op/embed.aspx?src=','') ) ; | |
Destination = join-path $DownloadFolder ( Remove-InvalidFileNameChars "$($_.SessionCode) - $($_.Title).pptx" ) } | |
} | |
} | | |
where-object { -not ( test-path $_.Destination ) } | | |
start-BitsTransfer | |
} | |
#endregion | |
#cleanup | |
#remove-item -Path $IgniteCache -ErrorAction SilentlyContinue | out-null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment