Skip to content

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.

Full source

sh
cd examples/import-osr
npm install
npm start

Importing 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
const 
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
}`)
View source

API used: init · OsuFilesAPI#osr

export-osr ​

Lists the ten most recent scores and exports the one you choose as an .osr file.

Full source

sh
cd examples/export-osr
npm install
npm start

Sort scores by date and limit the query before printing them. These are detached snapshots, and exporting one does not change Realm.

js
const 
recent
=
initialized
.
scores
.
get
.
sortedBy
('Date').
limit
(10)
if (
recent
.
length
=== 0) {
console
.
log
('No scores found.')
return }
View source

Look up the chosen score by its Realm ID. The exporter accepts that same ID when it writes the .osr file.

js
const 
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 }
View source
js
initialized
.
osr
.
export
(
choice
,
outputPath
)
View source

API used: init · OsuFilesAPI#scores · OsuFilesAPI#osr

Released under the MIT License.