Skip to content

Instantly share code, notes, and snippets.

@OfficialEsco
Last active August 27, 2021 19:21
Show Gist options
  • Save OfficialEsco/599257140346fa4a79b36dc63bb20d61 to your computer and use it in GitHub Desktop.
Save OfficialEsco/599257140346fa4a79b36dc63bb20d61 to your computer and use it in GitHub Desktop.
Get winget-pkgs urls
Param (
[Parameter(Position = 0, HelpMessage = "Options: GitHub, SourceForge", Mandatory=$true)]
[String] $Domain
)
Switch ($Domain) {
'GitHub' { $LookFor = "*github.com/*" }
'SourceForge' { $LookFor = "*sourceforge.net/*" }
Default { Write-Error 'Invalid Domain' -ErrorAction 'Stop' }
}
$Manifests = Get-ChildItem -path "$env:USERPROFILE\GitHub\winget-pkgs\manifests\" -Recurse -Filter "*.yaml" | Select-Object -Property FullName
foreach ($_ in $Manifests) {
$_ = Get-Content -Path $_.FullName -ErrorAction SilentlyContinue | Select-String -Pattern "InstallerUrl:" | Select-Object -Unique | ConvertFrom-String -Delimiter "InstallerUrl:"
if ($_.P2 -like $LookFor) {
$u = $_.P2.Trim() -replace "`"" -replace "`'" -split "/"
$Url = $u[0..5] -join "/"
$Urls += @($Url)
}
}
Write-Host -ForegroundColor 'Green' -Object "Found", ($Urls -ne '' | Select-Object -Unique).Count, "unique $Domain urls"
$RSSUrls += @(
'<?xml version="1.0" encoding="UTF-8"?>'
'<opml version="1.0">'
' <head>'
' <title>Winget Repo Installer Url Export</title>'
' </head>'
' <body>'
)
ForEach ($_ in ($Urls | Select-Object -Unique | Sort-Object) -ne '') {
$Url = $_.Split("/").Trim()
Switch ( $Domain ) {
'GitHub' {
$Name = ($Url[3..4] -join "/")
$FullUrl = ($Url[0..5] -join "/")
$RSSUrls += @(" <outline text=`"$Name`" title=`"$Name`" type=`"rss`" xmlUrl=`"$FullUrl.atom`" />")
}
'SourceForge' {
$Name = ($Url[4] -join "/")
$FullUrl = ($Url[0..4] -join "/")
$RSSUrls += @(" <outline text=`"$Name`" title=`"$Name`" type=`"rss`" xmlUrl=`"$FullUrl/rss?path=/`" />")
}
}
}
$RSSUrls += @(
' </body>'
' </opml>'
)
Set-Content -Value $RSSUrls -Path "$env:USERPROFILE\Downloads\$($Domain)_UniqueUrlsRSS.opml" -Encoding UTF8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment