From f33cb61fa6e3399790828de10ac1a0747bca0453 Mon Sep 17 00:00:00 2001 From: amd64fox <62529699+amd64fox@users.noreply.github.com> Date: Sat, 5 Oct 2024 07:24:35 +0300 Subject: [PATCH] added version check in Spotify MS --- .github/workflows/ms-spotify.yml | 20 ++++ ms-spotify-check.ps1 | 185 +++++++++++++++++++++++++++++++ 2 files changed, 205 insertions(+) create mode 100644 .github/workflows/ms-spotify.yml create mode 100644 ms-spotify-check.ps1 diff --git a/.github/workflows/ms-spotify.yml b/.github/workflows/ms-spotify.yml new file mode 100644 index 0000000..2ba0ae9 --- /dev/null +++ b/.github/workflows/ms-spotify.yml @@ -0,0 +1,20 @@ +name: check Spotify MS + +on: + schedule: + - cron: '35 * * * *' + workflow_dispatch: + +jobs: + build: + runs-on: windows-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run PowerShell script + shell: pwsh + run: ./ms-spotify-check.ps1 + env: + TAG: ${{ secrets.TAG }} diff --git a/ms-spotify-check.ps1 b/ms-spotify-check.ps1 new file mode 100644 index 0000000..d9b9c89 --- /dev/null +++ b/ms-spotify-check.ps1 @@ -0,0 +1,185 @@ +# Suppress verbose output +$VerbosePreference = 'SilentlyContinue' + +function Write-Log { + param ( + [string]$Message + ) + Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') - $Message" +} + +function Get-LatestSpotifyVersion { + Write-Log "Getting data from rg-adguard..." + + # Setting up a session + $session = New-Object Microsoft.PowerShell.Commands.WebRequestSession + $session.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36" + + # Request parameters + $url = "https://store.rg-adguard.net/api/GetFiles" + $body = "type=url&url=https://apps.microsoft.com/detail/9ncbcszsjrsb&gl=US&ring=RP&lang=en" + $headers = @{ + "authority" = "store.rg-adguard.net" + "method" = "POST" + "path" = "/api/GetFiles" + "scheme" = "https" + "accept" = "*/*" + "accept-language" = "ru,ru-RU;q=0.9,en;q=0.8" + "dnt" = "1" + "origin" = "https://store.rg-adguard.net" + "priority" = "u=1, i" + "referer" = "https://store.rg-adguard.net/" + "sec-ch-ua" = '"Google Chrome";v="129", "Not=A?Brand";v="8", "Chromium";v="129"' + "sec-ch-ua-mobile" = "?0" + "sec-ch-ua-platform" = '"Windows"' + "sec-fetch-dest" = "empty" + "sec-fetch-mode" = "cors" + "sec-fetch-site" = "same-origin" + } + + $ProgressPreference = 'SilentlyContinue' + + try { + $response = Invoke-WebRequest -Uri $url -Method "POST" -Body $body -WebSession $session -Headers $headers -UseBasicParsing + $html = $response.Content + } + catch { + Write-Log "Error executing request: $_" + Write-Log "Error code: $($_.Exception.Response.StatusCode.value__)" + Write-Log "Error message: $($_.Exception.Message)" + return $null + } + + $trContents = [regex]::Matches($html, '(?s)(.*?)') | ForEach-Object { $_.Groups[1].Value } + $results = @() + foreach ($trContent in $trContents) { + if ($trContent -match ']*>([^<]+)') { + $url = $matches[1] + $fileName = $matches[2] + } + if ($trContent -match '>(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} GMT)<') { + $dateTime = [DateTime]::ParseExact($matches[1], "yyyy-MM-dd HH:mm:ss 'GMT'", $null) + } + if ($trContent -match '>(\d+(?:\.\d+)?)\s*MB<') { + $size = $matches[1] + " MB" + } + $results += [PSCustomObject]@{ + FileName = $fileName + DateTime = $dateTime + Size = $size + Url = $url + } + } + + $filteredResults = $results | Where-Object { $_.FileName -match 'SpotifyAB\.SpotifyMusic_.+x86.+\.appx' } + $latestFile = $filteredResults | Sort-Object -Property DateTime -Descending | Select-Object -First 1 + Write-Log "Found: $($latestFile.FileName)" + return $latestFile +} + +function Download-SpotifyAppx { + param ($downloadUrl, $filePath) + Write-Log "Downloading appx file..." + $ProgressPreference = 'SilentlyContinue' + Invoke-WebRequest -Uri $downloadUrl -OutFile $filePath +} + +function Extract-SpotifyAppx { + param ($filePath, $extractPath) + Write-Log "Extracting files from archive..." + Add-Type -AssemblyName "System.IO.Compression.FileSystem" + try { + $zip = [System.IO.Compression.ZipFile]::OpenRead($filePath) + $zip.Entries | Where-Object { $_.FullName -notlike '*/*' } | ForEach-Object { + $destPath = Join-Path $extractPath $_.Name + [System.IO.Compression.ZipFileExtensions]::ExtractToFile($_, $destPath, $true) + } + } + finally { + if ($zip -ne $null) { + $zip.Dispose() + } + } +} + +function Get-SpotifyExeVersion { + param ($spotifyExePath) + Write-Log "Getting version from file $([System.IO.Path]::GetFileName($spotifyExePath))..." + $exeContent = Get-Content -Path $spotifyExePath -Raw + $regex = '(?