Last active
December 17, 2020 20:07
-
-
Save rjesh-git/ee3e21cd966e8c7186bea6d9fd766b5c to your computer and use it in GitHub Desktop.
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
# 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 (Test-Path $FilePath -PathType Leaf) { | |
Write-Host "Skipping $FilePath already exists." -ForegroundColor Red | |
}else { | |
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 | |
if ($item.slideDeck) {Get-File -URI $item.slideDeck -FilePath "$DownloadPath/$($item.sessionCodeNormalized)-$name.pptx"} | |
if ($item.downloadVideoLink -and $IncludeVideos) {Get-File -URI $item.downloadVideoLink-FilePath "$DownloadPath/$($item.sessionCodeNormalized)-$name.mp4"} | |
} | |
$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
How can I do to download the PPT for Ignite 2020?