Skip to content

Instantly share code, notes, and snippets.

@MasayukiOzawa MasayukiOzawa/Ignite2019Session.ps1 Secret
Last active Nov 9, 2019

Embed
What would you like to do?
$captionUrl = "https://medius.studios.ms/video/asset/CAPTION/IG19-TK01"
$ret = Invoke-WebRequest -Uri $captionUrl -UseBasicParsing
$sb = New-Object System.Text.StringBuilder
if ($ret.Content.GetType() -eq [System.Byte[]]) {
$captionString = ([System.Text.Encoding]::UTF8.GetString($ret.Content)) -split "`n"
}
else {
$captionString = $ret.Content -split "`n"
}
foreach ($line in $captionString) {
if ($line.trim() -ne "WEBVTT" -and -not([System.String]::IsNullOrEmpty($line.Trim()))) {
if (-not [System.Int32]::TryParse($line, [ref]$null)) {
if (-not ($line.Trim() -match ".*[0-9][0-9]$")) {
$line = $line -replace "`r", "" -replace "`n", ""
[void]$sb.Append($line)
}
}
}
}
$sb.ToString() -replace "\.", ".`r`n" | clip.exe
param(
$DownloadPath = "D:\Ignite2019",
$DownloadSlide = $true,
$DownloadVideo = $true,
$DownloadCaption = $true,
$BitsDownload = $false,
$retryCount=5,
$searchText = """SQL"""
)
$ErrorActionPreference = "Stop"
if (-not (Test-Path $DownloadPath)) {
New-Item -ItemType Directory $DownloadPath
}
$uri = "https://api-myignite.techcommunity.microsoft.com/api/session/search"
$link_base = "https://myignite.techcommunity.microsoft.com/sessions/"
$list = New-Object "System.Collections.Generic.List[PSCustomObject]"
for ($page = 1; $page -le 200; $page++) {
$body = @{
searchPage = $page
sortOption = "ASC"
searchText = $searchText
}
$ret = Invoke-WebRequest -Uri $uri -Method Post -Body $body
$data = $ret.Content | ConvertFrom-Json
if (($data.data | Measure-Object).count -ne 0) {
foreach ($item in $data.data) {
Write-Host ("{0} : {1} {2}" -f (Get-Date -Format "G"), $item.sessionCode, $item.title)
$list.Add([PSCustomObject]@{
sessionCode = $item.sessionCode
title = $item.title
level = $($item.level -match "^*\((?<level>.*?)\)$" | Out-Null; $Matches.level)
speaker = $item.speakerNames -join "|"
sessionType = $item.sessionType
startDateTime = $item.startDateTime
lastUpdate = $item.lastUpdate
link = $($link_base + $item.sessionId)
onDemand = $item.onDemand
captionFileLink = $item.captionFileLink
slideDeck = $item.slideDeck
downloadVideoLink = $item.downloadVideoLink
})
$fileNameBase = ("{0} {1}" -f $item.sessionCode, ($item.title -replace ":", " " -replace "/", " " -replace "<", " " -replace ">" , " " -replace "\?", " " -replace "\[", " " -replace "\]", " "))
# Slide Download
if ( $item.slideDeck -ne "" -and $DownloadSlide -eq $true) {
if (-not (Test-Path (Join-Path $DownloadPath ($fileNameBase + ".pptx")))) {
Write-Host ("{0} : Slide Downloading...." -f (Get-Date -Format "G"))
for ($i = 1; $i -le $retryCount; $i++) {
try {
If($BitsDownload){
Start-BitsTransfer -Source $item.slideDeck -Destination (Join-Path $DownloadPath ($fileNameBase + ".pptx"))
}else{
Invoke-WebRequest -Uri $item.slideDeck -OutFile (Join-Path $DownloadPath ( $fileNameBase + ".pptx"))
}
break
}
catch {
Write-Host "Slide Download Failed..." -ForegroundColor Red
if (Test-Path (Join-Path $DownloadPath ( $fileNameBase + ".pptx"))) {
Remove-Item -Path (Join-Path $DownloadPath ( $fileNameBase + ".pptx"))
}
if($i -eq $retryCount){
Write-Host ("{0} : Download Error [{1}]" -f (Get-Date -Format "G"), $item.sessionCode) -ForegroundColor Red
}else{
Write-Host ("{0} : Download Retry... {1}/{2}" -f (Get-Date -Format "G"), ($i+1), $retryCount) -ForegroundColor Red
}
}
}
}
}
# Video Download
if ( $item.downloadVideoLink -ne "" -and $DownloadVideo -eq $true) {
if (-not (Test-Path (Join-Path $DownloadPath ($fileNameBase + ".mp4")))) {
Write-Host ("{0} : Video Downloading...." -f (Get-Date -Format "G"))
for ($i = 1; $i -le $retryCount ; $i++) {
try {
If($BitsDownload){
Start-BitsTransfer -Source $item.downloadVideoLink -Destination (Join-Path $DownloadPath ($fileNameBase + ".mp4"))
}else{
Invoke-WebRequest -Uri $item.downloadVideoLink -OutFile (Join-Path $DownloadPath ($fileNameBase + ".mp4"))
}
break
}
catch {
Write-Host "Video Download Failed..." -ForegroundColor Red
Write-Host $Error[0].Exception -ForegroundColor Red
if (Test-Path (Join-Path $DownloadPath ( $fileNameBase + ".mp4"))) {
Remove-Item -Path (Join-Path $DownloadPath ( $fileNameBase + ".mp4"))
}
if($i -eq $retryCount){
Write-Host ("{0} : Download Error [{1}]" -f (Get-Date -Format "G"), $item.sessionCode) -ForegroundColor Red
}else{
Write-Host ("{0} : Download Retry... {1}/{2}" -f (Get-Date -Format "G"), ($i+1), $retryCount) -ForegroundColor Red
}
}
}
}
}
# Caption Download
if ( $item.captionFileLink -ne "" -and $DownloadCaption -eq $true) {
if (-not (Test-Path (Join-Path $DownloadPath ($fileNameBase + ".vtt")))) {
Write-Host ("{0} : Caption Downloading...." -f (Get-Date -Format "G"))
for ($i = 1; $i -le $retryCount ; $i++) {
try {
If($BitsDownload){
Start-BitsTransfer -Source $item.captionFileLink -Destination (Join-Path $DownloadPath ($fileNameBase + ".vtt"))
}else{
Invoke-WebRequest -Uri $item.captionFileLink -OutFile (Join-Path $DownloadPath ($fileNameBase + ".vtt"))
}
break
}
catch {
Write-Host "Video Download Failed..." -ForegroundColor Red
Write-Host $Error[0].Exception -ForegroundColor Red
if (Test-Path (Join-Path $DownloadPath ( $fileNameBase + ".vtt"))) {
Remove-Item -Path (Join-Path $DownloadPath ( $fileNameBase + ".vtt"))
}
if($i -eq $retryCount){
Write-Host ("{0} : Download Error [{1}]" -f (Get-Date -Format "G"), $item.sessionCode) -ForegroundColor Red
}else{
Write-Host ("{0} : Download Retry... {1}/{2}" -f (Get-Date -Format "G"), ($i+1), $retryCount) -ForegroundColor Red
}
}
}
}
}
}
}
else {
break
}
}
Write-Output ("{0} Session" -f $list.Count)
Write-Output $list | Sort-Object startDateTime | Select-Object * | ConvertTo-Csv -Delimiter `t | clip.exe
Write-Output $list | Sort-Object startDateTime | Select-Object * | Format-Table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.