Last active
August 26, 2024 20:39
-
-
Save craeckor/b1fc55034c3d1633f48ec9ae9fb1c7ee to your computer and use it in GitHub Desktop.
Supports all parameters of https://store.rg-adguard.net/, only one parameter is allowed ($Ring doesn't count)
This file contains 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
function Get-AppxPackage-DownloadLinks { | |
param( | |
[Parameter(Position=0)] | |
[string]$URL, | |
[Parameter(Position=1)] | |
[string]$ProductID, | |
[Parameter(Position=2)] | |
[string]$PackageFamilyName, | |
[Parameter(Position=3)] | |
[string]$CategoryID, | |
[Parameter(Position=4)] | |
[ValidateSet("WIF","WIS","RP","Retail")] | |
[string]$Ring = "RP" | |
) | |
$counter = 0 | |
if ($URL) { | |
$counter++ | |
$data = $URL | |
$type = "url" | |
} | |
if ($ProductID) { | |
$counter++ | |
$data = $ProductID | |
$type = "ProductId" | |
} | |
if ($PackageFamilyName) { | |
$counter++ | |
$data = $PackageFamilyName | |
$type = "PackageFamilyName" | |
} | |
if ($CategoryID) { | |
$counter++ | |
$data = $CategoryID | |
$type = "CategoryId" | |
} | |
if ($counter -gt 1) { | |
Write-Host "Please provide only one value" | |
return | |
} elseif ($counter -eq 0) { | |
Write-Host "You must provide a single value" | |
return | |
} | |
$data = $data -replace "\?.*", "" | |
$urldata = "type=$type&url=$data&ring=$Ring&lang=en-US" | |
$patternUrlAndText = '<tr style.*<a href=\"(?<url>.*)"\s.*>(?<text>.*\.(app|msi)x.*)<\/a>' | |
$download = curl.exe -k -s -L --connect-timeout 45 --retry 5 --retry-max-time 120 --retry-connrefused -X POST https://store.rg-adguard.net/api/GetFiles -d "$urldata" | |
$unformateddata = $download | Select-String $patternUrlAndText -AllMatches | |
$formateddata = $unformateddata | ConvertFrom-String -Delimiter '"' | |
$unformatednames = $formateddata | Select-Object -ExpandProperty P7 | ConvertFrom-String -Delimiter "</a>" | Select-Object -ExpandProperty P1 | |
$names = $unformatednames -replace '>', '' | |
$links = $formateddata | Select-Object -ExpandProperty P4 | |
$count = $names.Count | |
$number = $count-1 | |
$numberlist = 0..$number | |
class Item { | |
[string]$PackageName | |
[string]$DownloadLink | |
} | |
$items = @() | |
for ($i = 0; $i -lt $numberlist.Count; $i++) { | |
$items += [Item]@{ | |
PackageName = $names[$i] | |
DownloadLink = $links[$i] | |
} | |
} | |
$table = @{} | |
$items | ForEach-Object { | |
$table[$_.PackageName] = $_.DownloadLink | |
} | |
return $items | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
Step 1: Import the function with
Import-Module .\Get-AppxPackage-Downloadlinks-Function.ps1
Step 2: Run it with either
Get-AppxPackage-DownloadLinks
{-URL
,-ProductID
,-PackageFamilyName
or-CategoryID
} "Value
" {-Ring
} (WIF
,WIS
,RP
,Retail
, default isRP
) or justGet-AppxPackage-DownloadLinks
"URL
"