Replays
Import .osr files into Realm or export stored scores as replay files.
import-osr
Imports an .osr replay and prints the metadata parsed from it.
sh
cd examples/import-osr
npm install
npm startImporting parses the replay, finds its beatmap by MD5, and writes the score to Realm. The returned object contains the replay metadata and decoded frames.
js
View sourceconst result = initialized.osr.import(replayPath)
console.log(` Player: ${result.playerName}`)
console.log(` Score: ${result.totalScore.toLocaleString()}`)
console.log(` Combo: ${result.maxCombo}x`)
console.log(` Date: ${result.timestamp.toISOString()}`)
console.log(` Mods: ${result.mods.valueOf()} (0x${result.mods.valueOf().toString(16)})`)
console.log(` MD5: ${result.replayMD5}`)
console.log(` Frames: ${result.replayFrames.length}`)
console.log(` Online ID: ${result.onlineScoreID}`)
API used: init · OsuFilesAPI#osr
export-osr
Lists the ten most recent scores and exports the one you choose as an .osr file.
sh
cd examples/export-osr
npm install
npm startSort scores by date and limit the query before printing them. These are detached snapshots, and exporting one does not change Realm.
js
View sourceconst recent = initialized.scores.get.sortedBy('Date').limit(10)
if (recent.length === 0) {
console.log('No scores found.')
return
}
Look up the chosen score by its Realm ID. The exporter accepts that same ID when it writes the .osr file.
js
View sourceconst choice = (await rl.question('Enter the Score ID to export: ')).trim()
const score = initialized.scores.get.byId(choice).first()
if (!score) {
console.log(`Score '${choice}' not found.`)
return
}
js
View sourceinitialized.osr.export(choice, outputPath)
API used: init · OsuFilesAPI#scores · OsuFilesAPI#osr