Skip to content

Instantly share code, notes, and snippets.

@ribbanya
Last active May 11, 2021 10:07
Show Gist options
  • Save ribbanya/d60bfac56c312850992ef2cdf7c58aeb to your computer and use it in GitHub Desktop.
Save ribbanya/d60bfac56c312850992ef2cdf7c58aeb to your computer and use it in GitHub Desktop.
Batch move osu! stable songs into groups for segmented import to lazer

Instructions

  1. Run Split-Songs.ps1. It will move all of your songs into a directory called SongsBatch, with each batch having its own folder.
  2. Once the initial move completes, a function called Move-OsuBatch will be defined globally. You can call this repeatedly to:
    1. Delete all files in the Songs directory
    2. Move all songs from the first batch to the Songs directory
  3. Launch osu!lazer and import your songs from stable
  4. Repeat steps 2 and 3 until finished
$batchSize = 1000
function global:Move-OsuBatch
{
Push-Location "$Env:LOCALAPPDATA/osu!"
try
{
Remove-Item Songs\* -Confirm -Verbose -Recurse | Tee-Object -Append -FilePath 'Split-Songs.log'
$dir = Get-ChildItem -Directory SongsBatch | Sort-Object {[int]$_.Name} | Select-Object -First 1
$children = Get-ChildItem $dir
foreach ($child in $children)
{
Move-Item -Force -Verbose -LiteralPath $child Songs *>&1 | Tee-Object -Append -FilePath 'Split-Songs.log'
}
Remove-Item -Verbose $dir *>&1 | Tee-Object -Append -FilePath 'Split-Songs.log'
}
finally
{
Pop-Location
}
}
Push-Location "$Env:LOCALAPPDATA/osu!"
try
{
$songs = Get-ChildItem Songs
$counter = [pscustomobject] @{ Value = 0 }
# https://stackoverflow.com/a/26850233/5880994
$groups = $songs | Group-Object -Property { [math]::Floor($counter.Value++ / $batchSize) }
foreach ($group in $groups)
{
$dir = New-Item "SongsBatch/$($group.Name)" -ItemType Directory -Force
foreach ($item in $group.Group)
{
Move-Item -Verbose -LiteralPath $item $dir *>&1 | Tee-Object -Append -FilePath 'Split-Songs.log'
}
}
}
finally
{
Pop-Location
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment