Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# Author Rajesh Sitaraman
# @rjesh | rjesh.com
<#
.SYNOPSIS
Download Ignite 2019 session presentation slides and videos.
.EXAMPLE
PS C:\> .\Get-IgniteContent.ps1 -DownloadPath /Users/rajeshsitaraman/src/public/share/IG-2019 -Keyword "AI"
.EXAMPLE
PS C:\> .\Get-IgniteContent.ps1 -DownloadPath /Users/rajeshsitaraman/src/public/share/IG-2019 -Keyword "Teams" -IncludeVideos
.EXAMPLE
Downloads all sessions -- Might take very long time
PS C:\> .\Get-IgniteContent.ps1 -DownloadPath /Users/rajeshsitaraman/src/public/share/IG-2019
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true, Position = 1)]
[String]$DownloadPath,
[Parameter(Mandatory = $false, Position = 2)]
[String]$Keyword,
[Parameter(Mandatory = $false, Position = 3)]
[Switch]$IncludeVideos
)
$itemsPerPage = 100
$page = 1
$response = $null
If (-Not (Test-Path -Path $DownloadPath -PathType Container)) {
New-Item -Path $DownloadPath -ItemType directory | Out-Null
}
function Get-File {
param([Parameter(Mandatory=$true)][string] $FilePath, [Parameter(Mandatory=$true)][string] $URI)
If ($PSVersionTable.PSEdition -eq "Core") {
Invoke-WebRequest -Uri $URI -OutFile $FilePath
}
Else {
Start-BitsTransfer -Source $URI -Destination $FilePath
}
}
if (!$Keyword) { $searchText = "" } else { $searchText = $Keyword}
do {
$body = @{
"itemsPerPage" = $itemsPerPage
"searchText" = $searchText
"searchPage" = $page
"sortOption" = "None"
"mustHaveOnDemandVideo" = $true
}
$params = @{
Headers = @{"Content-type"="application/json"}
Body = $body | convertto-json
Method = "Post"
URI = "https://api-myignite.techcommunity.microsoft.com/api/session/search"
}
$response = Invoke-RestMethod @params
foreach ($item in $response.data) {
$name = $item.Title -replace '[\W]', ' '
$name = $name.Substring(0,[System.Math]::Min(50, $name.Length))
Write-Host "Downloading -- $($item.sessionCodeNormalized)" -ForegroundColor Green
# check to see if MP4 already exists if so skip re-downloading it
$outmp4 = "$DownloadPath/$($item.sessionCodeNormalized)-$name.mp4"
if (Test-Path $outmp4 -PathType Leaf) {
Write-Host "MP4 Already Exists"
}else {
Write-Host "Downloading MP4"
if ($item.downloadVideoLink -and $IncludeVideos) {Get-File -URI $item.downloadVideoLink-FilePath $outmp4}
}
# check to see if pptx already exists if so skip re-downloading it
$outpptx = "$DownloadPath/$($item.sessionCodeNormalized)-$name.pptx"
if (Test-Path $outpptx -PathType Leaf) {
Write-Host "PPTX Already Exists"
}else {
Write-Host "Downloading PPTX"
if ($item.slideDeck) {Get-File -URI $item.slideDeck -FilePath $outpptx}
}
}
$page +=1
} until ($page -gt ($($response.total)/$itemsPerPage))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment