Skip to content

Instantly share code, notes, and snippets.

@jack3898
Created November 26, 2023 16:06
Show Gist options
  • Save jack3898/35ccf748886ba41ff7ef304b8e4dc905 to your computer and use it in GitHub Desktop.
Save jack3898/35ccf748886ba41ff7ef304b8e4dc905 to your computer and use it in GitHub Desktop.
Run Danser CLI on new replay generated
###
# ABOUT: Watches for new replays and renders them with danser-cli
#
# HOW TO:
# 1. Download Danser from https://github.com/Wieku/danser-go and extract it
# 2. Download this script and place it in the same folder as danser-cli.exe
# 3. Open PowerShell and run the script with `.\watch-replays.ps1`
# 4. When new replays are created, they will be rendered with danser-cli
#
# NOTES:
# - This script will only watch for replays in the default osu! directory. If you have osu! installed in a different location, you will need to update the $OsuDir variable.
# - This script relies on a Danser settings preset which can be made easily in the Danser GUI. The preset name is set in the $DanserSettingsName variable.
###
# Update these variables to match your environment if necessary
$OsuDir = "$env:LOCALAPPDATA/osu!"
$ReplayDir = "$OsuDir/Replays"
# Internal variables
$WatcherName = "FileCreated"
# Unregister the event if it already exists
Unregister-Event -SourceIdentifier $WatcherName
# Watch for new replays
$Watcher = New-Object System.IO.FileSystemWatcher $ReplayDir, '*.osr' -Property @{
IncludeSubdirectories = $false
NotifyFilter = [System.IO.NotifyFilters]'FileName, LastWrite'
EnableRaisingEvents = $true
}
# Process a new replay
Register-ObjectEvent $Watcher Created -SourceIdentifier $WatcherName -Action {
try {
$DanserSettingsName = "4k"
$ProcessOptions = @{
FilePath = "danser-cli.exe"
ArgumentList = "-settings=`"$DanserSettingsName`" -out=`"$($eventArgs.Name)`" -replay=`"$($eventArgs.FullPath)`""
Wait = $true
WindowStyle = "Hidden"
}
# Execute danser-cli with the replay
Start-Process @ProcessOptions
[System.Media.SystemSounds]::Asterisk.Play()
} catch {
# Log the error to a text file
$Error | Out-File -FilePath "render-replay-error.txt"
[System.Media.SystemSounds]::Hand.Play()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment