@@ -13,27 +13,73 @@ $AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
1313[System.Net.ServicePointManager ]::SecurityProtocol = $AllProtocols
1414[System.Net.ServicePointManager ]::CertificatePolicy = New-Object TrustAllCertsPolicy
1515
16+ $RepoRoot = $PSScriptRoot
17+
18+ function Get-HandBrakeNightlyGuiZipFileName {
19+ param (
20+ [Parameter (Mandatory )]
21+ [string ] $PageContent ,
22+ [Parameter (Mandatory )]
23+ [ValidateSet (' x86_64' , ' arm64' )]
24+ [string ] $Architecture
25+ )
26+ $suffix = " ${Architecture} -Win_GUI.zip"
27+ $pattern = ' HandBrake[^"<>]+' + [regex ]::Escape($suffix )
28+ if (-not ($PageContent -match $pattern )) {
29+ throw " Could not find $Architecture HandBrake nightly zip on the releases page."
30+ }
31+ return $matches [0 ]
32+ }
33+
34+ function Install-HbDllFromHandBrakeGuiZip {
35+ param (
36+ [Parameter (Mandatory )]
37+ [string ] $ZipUrl ,
38+ [Parameter (Mandatory )]
39+ [string ] $ZipDownloadPath ,
40+ [Parameter (Mandatory )]
41+ [string ] $ExtractDirectory ,
42+ [Parameter (Mandatory )]
43+ [string ] $DestinationHbDllPath
44+ )
45+ Invoke-WebRequest - Uri $ZipUrl - OutFile $ZipDownloadPath - UseBasicParsing
46+ [System.IO.Compression.ZipFile ]::ExtractToDirectory($ZipDownloadPath , $ExtractDirectory )
47+ $null = New-Item - ItemType Directory - Force - Path (Split-Path - Parent $DestinationHbDllPath )
48+ Copy-Item (Join-Path $ExtractDirectory ' HandBrake\hb.dll' ) $DestinationHbDllPath
49+ }
50+
1651# $wc = New-Object System.Net.WebClient
1752# $wc.Credentials = New-Object System.Net.NetworkCredential("username","password")
1853# $nightlyPageContent = $wc.DownloadString("https://handbrake.fr/nightly.php")
1954
20- $nightlyPageResponse = Invoke-WebRequest - Uri " https://github.com/HandBrake/handbrake-snapshots/releases/tag/win" - UseBasicParsing
21- $nightlyPageContent = $nightlyPageResponse.Content
55+ $nightlyPageContent = (
56+ Invoke-WebRequest - Uri " https://github.com/HandBrake/handbrake-snapshots/releases/tag/win" - UseBasicParsing
57+ ).Content
2258
23- $nightlyPageContent -match " HandBrake[^"" <>]+x86_64-Win_GUI.zip" | Out-Null
24- $remoteFile = $matches [0 ]
25- $url = " https://github.com/HandBrake/HandBrake-snapshots/releases/download/win/" + $remoteFile
59+ $downloadBaseUrl = " https://github.com/HandBrake/HandBrake-snapshots/releases/download/win/"
2660
27- if (Test-Path .\Import\Hb) {
28- Remove-Item .\Import\Hb\* - recurse
61+ $importHbRoot = Join-Path $RepoRoot " Import\Hb"
62+ if (Test-Path $importHbRoot ) {
63+ Remove-Item (Join-Path $importHbRoot ' *' ) - Recurse - Force
2964}
3065
31- New-Item - ItemType Directory - Force - Path " Import\Hb" | Out-Null
32-
33- Add-Type - assembly " system.io.compression.filesystem"
66+ Add-Type - AssemblyName " System.IO.Compression.FileSystem"
3467
35- Invoke-WebRequest - Uri $url - OutFile (" Import\hb.zip" ) - UseBasicParsing
68+ $platforms = @ (
69+ @ { HandBrakeArch = ' x86_64' ; ImportSubdir = ' x64' ; ZipFileName = ' hb-x64.zip' ; LibRelative = ' Lib\x64\hb.dll' }
70+ @ { HandBrakeArch = ' arm64' ; ImportSubdir = ' arm64' ; ZipFileName = ' hb-arm64.zip' ; LibRelative = ' Lib\arm64\hb.dll' }
71+ )
3672
37- [io.compression.zipfile ]::ExtractToDirectory(" Import\hb.zip" , " Import\Hb\" )
38-
39- Copy-Item " Import\Hb\HandBrake\hb.dll" " Lib\hb.dll"
73+ foreach ($p in $platforms ) {
74+ $zipName = Get-HandBrakeNightlyGuiZipFileName - PageContent $nightlyPageContent - Architecture $p.HandBrakeArch
75+ Write-Host " Downloading $zipName ..."
76+ $extractDir = Join-Path $importHbRoot $p.ImportSubdir
77+ $zipPath = Join-Path (Join-Path $RepoRoot " Import" ) $p.ZipFileName
78+ $libHbDll = Join-Path $RepoRoot $p.LibRelative
79+ $null = New-Item - ItemType Directory - Force - Path $extractDir
80+ Install-HbDllFromHandBrakeGuiZip `
81+ - ZipUrl ($downloadBaseUrl + $zipName ) `
82+ - ZipDownloadPath $zipPath `
83+ - ExtractDirectory $extractDir `
84+ - DestinationHbDllPath $libHbDll
85+ }
0 commit comments