#download latest version off url

5 messages · Page 1 of 1 (latest)

lime copper
#
$apiUrl = "https://store.rg-adguard.net/api/GetFiles"

$p = "Microsoft.Paint"
$productUrl = "https://apps.microsoft.com/detail/9pcfs5b6t72h"

$downloadFolder = ".\dl\"
if(!(Test-Path $downloadFolder -PathType Container)) {
    New-Item $downloadFolder -ItemType Directory -Force
}

$body = @{
    type = 'url'
    url  = $productUrl
    ring = 'RP'
    lang = 'en-US'
}

$raw = Invoke-RestMethod -Method Post -Uri $apiUrl -ContentType 'application/x-www-form-urlencoded' -Body $body

$test = $raw | Select-String '<tr style.*<a href=\"(?<url>.*)"\s.*>(?<text>.*)<\/a>' -AllMatches|
 % { $_.Matches } |
 % { 
    $url = $_.Groups[1].Value
    $text = $_.Groups[2].Value
    Write-Host $text

    $pattern = $p + "(\.|_)(.+)_(x64|neutral).*appx(|bundle)$"
    if($text -match $pattern) {
        $downloadFile = Join-Path $downloadFolder $text
        if(!(Test-Path $downloadFile)) {
            #Invoke-WebRequest -Uri $url -OutFile $downloadFile
        }
    }
}

$test
#

i want it to download only the latest version, i think i need to sort filenames and match the highest version somehow

tropic moth
#

there could be some corner cases, but smth to get you started:

$apiUrl = "https://store.rg-adguard.net/api/GetFiles"

$p = "Microsoft.Paint"
$productUrl = "https://apps.microsoft.com/detail/9pcfs5b6t72h"

$downloadFolder = ".\dl\"
if(!(Test-Path $downloadFolder -PathType Container)) {
    New-Item $downloadFolder -ItemType Directory -Force
}

$body = @{
    type = 'url'
    url  = $productUrl
    ring = 'RP'
    lang = 'en-US'
}

$raw = Invoke-RestMethod -Method Post -Uri $apiUrl -ContentType 'application/x-www-form-urlencoded' -Body $body

$pattern = [regex]::Escape($p) + "(\.|_)(.+)_(x64|neutral)_.*\.(appx|msixbundle|msix)$"

$raw | Select-String '<tr style.*<a href=\"(?<url>.*)"\s.*>(?<text>.*)<\/a>' -AllMatches | ForEach-Object Matches | ForEach-Object { 
    [PSCustomObject]@{
        url = $_.Groups[1].Value
        filename = $_.Groups[2].Value
    }
} | Where-Object filename -Match $pattern | Sort-Object { 
    if($_.filename -match '_(\d+\.\d+\.\d+\.\d+)_'){[version]$Matches[1]}
} -Bottom 1 | ForEach-Object {
    $filepath = Join-Path $downloadFolder $_.filename
    if(!(Test-Path $filepath)) {
        Write-Host $filepath
        #Invoke-WebRequest -Uri $url -OutFile $filepath 
    }
}
lime copper
#

works ty

upbeat wadi