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] Scooter Software Beyond Compare #68

Open AScott-WWF opened 3 weeks ago

AScott-WWF commented 3 weeks ago

I have written a new NeverGreen script to return the latest versions of Scooter Softwares Beyond Compare for Windows, this is obtained using a webscrape against https://www.scootersoftware.com/download

N.B. The Platform Uris have been obtained from both the Downloads page (for .exe's) and the Alternate Installers page (for .msi & .zip files) As I introduced the new ReleaseDate attribute in the [Enhancement] Microsoft SSMS New issue, I have made use of it in here too.

Here is my script:

# Get-ScooterBeyondCompare.ps1

$AppName = "Scooter Beyond Compare"
$ReleaseURL = 'https://www.scootersoftware.com/download'
$Version = ((Get-Link -Uri $ReleaseURL -MatchProperty href -Pattern '\.exe$') | Get-Version -Pattern '(\d+\.\d+(\.\d+){0,2})')

#Obtain Release Date and convert to "yyyy-MM-dd" format
try {
    $Content = (Invoke-WebRequest -Uri $ReleaseURL).RawContent
    $SearchString = ", released "
    $CaptureStart = $Content.IndexOf($SearchString) + $SearchString.Length
    $EndIndex = $Content.IndexOf("</span>", $CaptureStart) - $CaptureStart
    $ReleasedOn = $Content.Substring($CaptureStart, $EndIndex).Trim()
}
catch {
    Throw "Failed to connect to ($($ReleaseUrl)) with error $_."
    Break
}
finally {
    # Define a regular expression pattern to match a date in the format "Month. Day, Year"
    $pattern = "\b(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec|January|February|March|April|May|June|July|August|September|October|November|December)\.\s\d{1,2},\s\d{4}\b"

    # Use Select-String to find the date in the text
    $matchesfound = $ReleasedOn | Select-String -Pattern $pattern

    # Extract the matched date
    if ($matchesfound) {
        # Parse the date and reformat it to "YYYY-MM-DD"
        $parsedDate = Get-Date $ReleasedOn
        #Create $LatestVersion variable to create folder structure
        $ReleaseDate = $parsedDate.ToString("yyyy-MM-dd")
        #Write-Verbose "Found Date: $ReleaseDate"
    } else {
        Write-Verbose "Date not found in the text."
    $ReleaseDate = ""
    }
    # Success
}

$Platforms = @(
    @{Architecture = 'x64'; Type = 'Msi'; Platform = 'Windows'; Language = 'English'; Uri = "https://www.scootersoftware.com/files/BCompare-$($Version)_x64.msi"}
    @{Architecture = 'x86'; Type = 'Msi'; Platform = 'Windows'; Language = 'English'; Uri = "https://www.scootersoftware.com/files/BCompare-$($Version)_x86.msi"}
    @{Architecture = 'x64'; Type = 'Zip'; Platform = 'Windows'; Language = 'English'; Uri = "https://www.scootersoftware.com/files/BCompareSetup-$($Version).zip"}
    @{Architecture = 'x64'; Type = 'Exe'; Platform = 'Windows'; Language = 'English'; Uri = "https://www.scootersoftware.com/files/BCompareSetup-$($Version).exe"}
    @{Architecture = 'x64'; Type = 'Exe'; Platform = 'Windows'; Language = 'German'; Uri = "https://www.scootersoftware.com/files/BCompareSetup-de-$($Version).exe"}
    @{Architecture = 'x64'; Type = 'Exe'; Platform = 'Windows'; Language = 'French'; Uri = "https://www.scootersoftware.com/files/BCompareSetup-fr-$($Version).exe"}
    @{Architecture = 'x64'; Type = 'Exe'; Platform = 'Windows'; Language = 'Japanese'; Uri = "https://www.scootersoftware.com/files/BCompareSetup-jp-$($Version).exe"}
    @{Architecture = 'x64'; Type = 'Exe'; Platform = 'Windows'; Language = 'Chinese (Simplified)'; Uri = "https://www.scootersoftware.com/files/BCompareSetup-zh-$($Version).exe"}
)

foreach ($Platform in $Platforms) {

    $SearchCount = 1

    do {
    New-NevergreenApp -Name $($AppName) -Version $($Version) -ReleaseDate $($ReleaseDate) -Language $($Platform.Language) -Uri $($Platform.Uri) -Platform $($Platform.Platform) -Architecture $($Platform.Architecture) -Type $($Platform.Type)
        break

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

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