Skip to content

Commit

Permalink
Update Clementine update script to fetch releases from GitHub API and…
Browse files Browse the repository at this point in the history
… handle pre-release versions
  • Loading branch information
robmoss2k committed Dec 17, 2024
1 parent d5d5b88 commit ad80646
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions automatic/clementine/update.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Import-Module Chocolatey-AU

$releases = 'https://www.clementine-player.org/downloads'
$releases = 'https://api.github.com/repos/clementine-player/Clementine/releases'
$publicReleases = 'https://www.clementine-player.org/downloads'

function global:au_BeforeUpdate {
Get-RemoteFiles -Purge
Expand All @@ -14,7 +15,7 @@ function global:au_BeforeUpdate {
function global:au_SearchReplace {
@{
".\legal\VERIFICATION.txt" = @{
"(?i)(^\s*location on\:?\s*)\<.*\>" = "`${1}<$releases>"
"(?i)(^\s*location on\:?\s*)\<.*\>" = "`${1}<$publicReleases>"
"(?i)(\s*1\..+)\<.*\>" = "`${1}<$($Latest.URL32)>"
"(?i)(^\s*checksum\s*type\:).*" = "`${1} $($Latest.ChecksumType32)"
"(?i)(^\s*checksum(32)?\:).*" = "`${1} $($Latest.Checksum32)"
Expand All @@ -25,15 +26,34 @@ function global:au_SearchReplace {
}
}
function global:au_GetLatest {
$download_page = Invoke-WebRequest -Uri $releases -UseBasicParsing

$re = '\.exe$'
$url = $download_page.links | ? href -match $re | select -First 1 -expand href
$version = Split-Path (Split-Path $url) -Leaf
@{
URL32 = $url
Version = $version
$download_page = Invoke-RestMethod -Uri $releases
$streams = @{}
$download_page | ForEach-Object {
if ($_.prerelease -eq $True) {
$key = "pre"
$version = $_.tag_name -replace '-[^-]+$' -replace '([0-9]+)\.([0-9]+)\.([0-9]+)(rc[0-9]+)-([0-9]+)', '$1.$2.$3.$5-$4'
}
else {
$key = "stable"
$version = $_.tag_name -replace '-[^-]+$' -replace '-', '.'
}
$url = $_.assets | Where-Object { $_.name -match '\.exe$' } | Select-Object -First 1 -ExpandProperty browser_download_url
if ($url -and !$streams.ContainsKey($key)) {
$streams.Add($key, @{
Version = $version
URL32 = $url
})
}
}
return @{ Streams = $streams }

# $re = '\.exe$'
# $url = $download_page.links | ? href -match $re | select -First 1 -expand href
# $version = Split-Path (Split-Path $url) -Leaf
# @{
# URL32 = $url
# Version = $version
# }
}

update -ChecksumFor none

0 comments on commit ad80646

Please sign in to comment.