DanGough / Nevergreen

This module is an alternative to Evergreen, and allows you to find the latest version and download URL for various Windows apps. Evergreen uses API queries to obtain its data whereas this module is more focussed on web scraping. This is more prone to breaking when websites are changed, hence the name.
The Unlicense
71 stars 16 forks source link

[New App Request] FileZilla #64

Open AScott-WWF opened 1 month ago

AScott-WWF commented 1 month ago

After a long running conversation with Aaron Parker on the Evergreen Issues page regarding FileZilla no longer working via Evergreen (https://github.com/aaronparker/evergreen/issues/581) and with your input it has lead me to investigate using NeverGreen to solve this problem

I now understand why Nevergreen is exactly the right way to solve this 'web scrape problem' 😁

Using your Get-AdobeAcrobatReader.ps1 script as a template, I have created a new Get-FileZilla.ps1 script, which works exactly as required for my purposes. N.B. I have removed the Language attribute (as FileZilla is not language specific) I have added a Headers splat to include the Headers that the FileZilla site requires / expects before it will serve content I guess the Platforms that Filezilla supports 'could' be expanded in the future for other OS distributions, but for now I'm assuming this module is only likely to be used for Windows.

Here's my script, feel free to check and include in any future release(s) of NeverGreen:

# Get-Filezilla.ps1
$Platforms = @(
    @{Architecture = 'x86'; Type = 'exe'; Pattern = 'FileZilla_\d+\.\d+\.\d+_win32-setup\.exe'}
    @{Architecture = 'x64'; Type = 'exe'; Pattern = 'FileZilla_\d+\.\d+\.\d+_win64-setup\.exe'}
    @{Architecture = 'x86'; Type = 'zip'; Pattern = 'FileZilla_\d+\.\d+\.\d+_win32\.zip'}
    @{Architecture = 'x64'; Type = 'zip'; Pattern = 'FileZilla_\d+\.\d+\.\d+_win64\.zip'}
)

foreach ($Platform in $Platforms) {

    $ReleaseURL = 'https://filezilla-project.org/download.php?show_all=1'
    $SearchCount = 3

    $Headers = @{
    "Accept"="*/*"
    "Accept-Language"="en-GB,en;q=0.9,en-US;q=0.8"
    "User-Agent" = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:125.0) Gecko/20100101 Firefox/125.0"
        "Host" = "filezilla-project.org"
    }

    do {
        $URL = Get-Link -Uri $ReleaseURL -Headers $Headers -MatchProperty href -Pattern $Platform.Pattern
        if ($URL) {
            $Version = ($URL | Get-Version -Pattern 'FileZilla_(\d+\.\d+\.\d+)_.+(exe|zip)')
            New-NevergreenApp -Name 'FileZilla' -Version $Version -Uri $URL -Architecture $Platform.Architecture -Type $Platform.Type
            break
        }

        $SearchCount--
    } until ($SearchCount -eq 0)

    if ($SearchCount -eq 0) {
        Write-Warning "Could not find release for FileZilla $($Platform.Architecture) $($Platform.Language)"
    }

}
DanGough commented 4 weeks ago

Thanks for the contribution, will review asap!