Created
April 29, 2021 15:23
-
-
Save KillyMXI/f36349424e3215e535d19fc9fe4b18ef to your computer and use it in GitHub Desktop.
Shuffle groups in an AIMP playlist ("*.aimppl4") while preserving the order inside groups.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Shuffle groups in an AIMP playlist ("*.aimppl4") | |
while preserving the order inside groups. | |
.PARAMETER inputPath | |
Input file to be shuffled ("*.aimppl4"). | |
#> | |
Param ( | |
[Parameter(Mandatory, HelpMessage="Input file to be shuffled.")] | |
[ValidateScript({($_ -Like "*.aimppl4") -And (Test-Path $_ -PathType Leaf)})] | |
[string]$inputPath | |
) | |
Set-StrictMode -Version Latest | |
$lines = Get-Content $inputPath | |
$contentMarkerLine = $lines | | |
Select-String -pattern "`#-----CONTENT-----`#" -SimpleMatch | | |
Select-Object -ExpandProperty LineNumber | |
$groupsList = [System.Collections.ArrayList]@() | |
$group = [System.Collections.ArrayList]@() | |
$lines | | |
Select-Object -Skip $contentMarkerLine | | |
ForEach-Object -Process { | |
If ($_.StartsWith("-") -And ($group.Count -gt 0)) { | |
[void]$groupsList.Add($group) | |
$group = [System.Collections.ArrayList]@() | |
} | |
[void]$group.Add($_) | |
} | |
[void]$groupsList.Add($group) | |
Write-Host "Found $($groupsList.Count) groups." | |
$shuffled = | |
($lines | Select-Object -First $contentMarkerLine) + | |
@($groupsList | Sort-Object { Get-Random } | ForEach-Object { $_ }) | |
$shuffled | Set-Content $inputPath -Encoding unicode | |
Write-Host "Shuffled." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment