I would like to be able to screen scrape the Tiktok Effects House downloads page to obtain the URL for the latest version download
I have managed to read the latest version number (from the Release Notes page), but have so far been unable to find the installer URL from the downloads page - this is what I have acheived so far with the following Powershell:
[cmdletbinding()]
Param()
Clear-Host
Write-Verbose "Setting Arguments" -Verbose
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$DetectionMethod = "Webscrape"
$AppName = "TikTokEffectHouse"
$Application = "TikTok Effect House"
#$Arch = "x64"
$AppType = "EXE"
$AppInstaller = "Effect_House_Setup.exe"
$InstallPath = "$($env:LOCALAPPDATA)\Effect House\Effect House.exe"
$DownloadsURL = "https://effecthouse.tiktok.com/download"
$ReleaseNotes = "https://effecthouse.tiktok.com/latest/release-notes-latest/"
# $PSScriptRoot should always be something like C:\Users\FSmith\gitrepos\Intune\Admin\Scripts.
# Our Base folder should be 'Intune', or 2 levels up.
$BaseFolder = "$PSScriptRoot\..\.."
$AllAppsFolder = ".\Apps"
$PrepToolExe = ".\Microsoft-Win32-Content-Prep-Tool-1.8.4\IntuneWinAppUtil.exe"
$StartTime = Get-Date
Write-Verbose "Finding installed version" -Verbose
# Check if App is installed and if it is get version
if (Test-Path -Path $InstallPath) {
[version]$InstalledVersion = (Get-ItemProperty $InstallPath).VersionInfo.FileVersion
Write-Host "Installed version of $($Application) is: $($InstalledVersion)"
} else {
Write-Host "WARNING :: $($Application) is not installed" -ForegroundColor Red
}
Write-Verbose "Using $($DetectionMethod) to check for latest version from: $($ReleaseNotes)..." -Verbose
try {
# $Web = Invoke-WebRequest -UseBasicParsing -Uri $DownloadsUrl -ErrorAction SilentlyContinue
$Web = Invoke-WebRequest -UseBasicParsing -Uri $ReleaseNotes -ErrorAction SilentlyContinue
}
catch {
Throw "Failed to connect to URL: $ReleaseNotes with error $_."
Break
}
finally {
# Luckily, although this web page covers a major release it only seems to have active links to the very latest update.
# So we can determine the latest version by searching for specific text in the page...
$PageContent = ($Web.Content)
$SearchString = "</style><h2 class=`"css-ov5iey e15xsn0a4`">v"
$CaptureStart = $PageContent.IndexOf($SearchString) + $SearchString.Length
$EndIndex = $PageContent.IndexOf(" (", $CaptureStart) - $CaptureStart
$Version = ($PageContent.Substring($CaptureStart, $EndIndex).Trim()) -replace "\.","-"
[version]$LatestVersion = ($PageContent.Substring($CaptureStart, $EndIndex).Trim()) -replace "-","."
}
Write-Output "Latest version of $($Application) is: $($LatestVersion)"
Write-Verbose "Using $($DetectionMethod) to find latest version download from: $($DownloadsURL)..." -Verbose
try {
# $Web = Invoke-WebRequest -UseBasicParsing -Uri $DownloadsUrl -ErrorAction SilentlyContinue
$Download = Invoke-WebRequest -UseBasicParsing -Uri $DownloadsURL -ErrorAction SilentlyContinue
}
catch {
Throw "Failed to connect to URL: $DownloadsURL with error $_."
Break
}
finally {
# This web page only seems to have an active link to the very latest update - obscured by CSS.
# So we need to determine the latest version download by searching within the links on the page...
$DownloadContent = (($Download.Links | Where-Object {$_.href -eq "/download"}).outerHTML)
<#
$SourceUrl = "" # To be read from page ?
#>
# Current Download URL for v3.3.2.87 has been obtained in a browser:
$SourceUrl = "https://sf16-va.tiktokcdn.com/obj/eden-va2/olaa_ajlmml_zlp/ljhwZthlaukjlkulzlp/V332_External_Release_0927/Effect_House_v3.3.2.87_101_Setup.exe"
}
<#
Other code...
N.B. Includes setting path to $Outfile
#>
# New Version available, so open Release Notes
$ReleaseNotesURL = "https://effecthouse.tiktok.com/effect-platform/latest/release-notes-latest/v$($version)/?enter_method=category_card"
Write-Output ""
Write-Host "New version $($LatestVersion) has been released, Opening release notes in default browser..." -ForegroundColor DarkGreen
Start-Process $ReleaseNotesURL
Write-Output ""
# Download the latest Installer
Write-Output ""
Write-Output "Downloading $($Application) $($LatestVersion) from $($SourceUrl)..."
$ProgressPreference = 'SilentlyContinue'
Invoke-WebRequest -Uri $SourceUrl -OutFile $Outfile