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] VLC Media Player #75

Open AScott-WWF opened 2 days ago

AScott-WWF commented 2 days ago

As VLC often publish a new version before updating their release notes or status downloads (Which EverGreen relies on) it often results in out of date information being served by EverGreen (example issue), I think it would be more reliable to use NeverGreen to scrape the VLC Download Page where the latest versions appear to be published earliest.

The script:

# Get-VLCMediaPlayer

$AppName = "VLC Media Player"

$Platforms = @(
    @{Architecture = 'x86'; Type = 'exe'; VerPattern = '"latestVersion":"(\d+\.\d+\.\d+)"'; FilePattern = 'vlc-(\d+\.\d+\.\d+)-win32\.exe'}
    @{Architecture = 'x64'; Type = 'exe'; VerPattern = '"latestVersion":"(\d+\.\d+\.\d+)"'; FilePattern = 'vlc-(\d+\.\d+\.\d+)-win64\.exe'}
    # N.B. MSI not currently available for v3.0.21
    @{Architecture = 'x86'; Type = 'msi'; VerPattern = '"latestVersion":"(\d+\.\d+\.\d+)"'; FilePattern = 'vlc-(\d+\.\d+\.\d+)-win32\.msi'}
    @{Architecture = 'x64'; Type = 'msi'; VerPattern = '"latestVersion":"(\d+\.\d+\.\d+)"'; FilePattern = 'vlc-(\d+\.\d+\.\d+)-win64\.msi'}
    @{Architecture = 'x86'; Type = 'zip'; VerPattern = '"latestVersion":"(\d+\.\d+\.\d+)"'; FilePattern = 'vlc-(\d+\.\d+\.\d+)-win32\.zip'}
    @{Architecture = 'x64'; Type = 'zip'; VerPattern = '"latestVersion":"(\d+\.\d+\.\d+)"'; FilePattern = 'vlc-(\d+\.\d+\.\d+)-win64\.zip'}
    #@{Architecture = 'ARM64'; Type = 'zip'; VerPattern = '"latestVersion":"(\d+\.\d+\.\d+)"'; FilePattern = 'vlc\d+\.\d+\.\d+_win64\.zip'}
)

foreach ($Platform in $Platforms) {

    $ReleaseURL = 'https://www.videolan.org/vlc/'
    $SearchCount = 1
    [version]$Version = (Get-Version -Uri $ReleaseURL -Pattern $Platform.VerPattern)

    do {
        if (($Platform.Type -eq "msi") -or ($Platform.Type -eq "zip")){
            if ($Platform.Architecture -eq "x86"){
                $Arch = "32"
            } else {
                $Arch = "64"
            }

            $BaseDownloadURL = "https://download.videolan.org/pub/videolan/vlc"
            $DownloadURL = "$($BaseDownloadURL)/$($Version)"

            #Build the URL
            $URL = "$($DownloadURL)/win$($Arch)/vlc-$($Version)-win$($Arch).$($Platform.Type)"
            # Test the existence of download by sending a HEAD request to the URL
            try {
                $response = Invoke-WebRequest -Uri $url -Method Head -ErrorAction Stop

                # Check the status code of the response (If the file exists add to NevergreenApp list)
                if ($response.StatusCode -eq 200) {
                    New-NevergreenApp -Name $AppName -Version $Version -Uri $URL -Architecture $Platform.Architecture -Type $Platform.Type
                    break
                }
            } catch {
                Write-Verbose "File 'vlc-$($Version)-win$($Arch).$($Platform.Type)' does not exist at URL: $url"
            }

        } else {
            $URL = Get-Link -Uri $ReleaseURL -MatchProperty href -Pattern $Platform.FilePattern
            if ($URL) {
                $URL = "https:$($URL)" # Prepend "https:" infront of returned URL
                New-NevergreenApp -Name $AppName -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 $($AppName) $Version ($($Platform.Architecture)) $($Platform.Type) type"
    }

}