Skip to content

Collections ​

Import, export, and edit the beatmap collections stored in Realm.

export-collection ​

Writes one collection, or all of them, to the legacy collections.db format.

Full source

sh
cd examples/export-collection
npm install
npm start

Open Realm in read-only mode.

js
const 
initialized
=
init
(
osuLazerRealmPath
, {
readOnly
: true })
View source

The collection module returns detached snapshots. Reading .get here loads every collection.

js
const 
all
=
initialized
.
collections
.
get
View source

Enter all to export every collection, or type an exact name to export one. Name lookup returns the first matching snapshot.

js
let 
data
if (
choice
.
toLowerCase
() === 'all') {
data
=
initialized
.
collections
.
exportLegacy
(
all
)
console
.
log
(` Exporting all ${
all
.
length
} collections`)
} else { const
found
=
initialized
.
collections
.
get
.
byName
(
choice
).
first
()
if (!
found
) {
console
.
log
(`Collection '${
choice
}' not found.`)
return }
data
=
initialized
.
collections
.
exportLegacy
(
found
)
console
.
log
(` Exporting collection '${
found
.
Name
}' (${
found
.
BeatmapMD5Hashes
.
filter
(
h
=>
h
).
length
} beatmaps)`)
}
View source

exportLegacy returns a buffer in osu!stable's collections.db format. Write that buffer directly to the requested path.

js
writeFileSync
(
outputPath
,
data
)
View source

API used: init · OsuFilesAPI#collections

Import a collection database ​

Merges a legacy collections.db file into the collections already stored in Realm.

Full source

sh
cd examples/import-collection
npm install
npm start

Import the legacy database in one call. Collections with new names are created; matching names receive any beatmap hashes they do not already contain.

js
console
.
log
(`\nImporting ${
legacyDbPath
}...`)
const {
imported
,
merged
} =
initialized
.
collections
.
importLegacy
(
legacyDbPath
)
const
total
=
initialized
.
collections
.
get
.
count
()
console
.
log
(` Created: ${
imported
} new collections`)
console
.
log
(` Merged: ${
merged
} existing collections`)
console
.
log
(` Total: ${
total
} collections in database`)
View source

API used: init · OsuFilesAPI#collections

Manage a collection ​

Adds beatmaps to a collection by online ID and removes them by list index.

Full source

sh
cd examples/manage-collection
npm install
npm start

Collection queries return detached snapshots. Changes go through the collection module rather than mutating col.

js
const 
col
=
osu
.
collections
.
get
.
byName
(
name
).
first
()
if (!
col
) {
console
.
log
(`'${
name
}' not found.`); continue }
View source

Collections store beatmap MD5 hashes, not online IDs. Look up the beatmap first, then add its MD5 hash to the selected collection.

js
const 
beatmap
=
osu
.
beatmaps
.
get
.
byOnlineId
(
onlineId
).
first
()
if (!
beatmap
) {
console
.
log
(`Beatmap ${
onlineId
} not found.`); continue }
if (!
beatmap
.
MD5Hash
) {
console
.
log
(`Beatmap ${
onlineId
} has no MD5Hash.`); continue }
osu
.
collections
.
addBeatmap
(
String
(
col
.
ID
),
beatmap
.
MD5Hash
)
View source

Removal uses the same MD5 hash. The local array is updated as well so the next prompt reflects the change without another query.

js
osu
.
collections
.
removeBeatmap
(
String
(
col
.
ID
),
md5
)
hashes
.
splice
(
idx
, 1)
View source

API used: init · OsuFilesAPI#collections · OsuFilesAPI#beatmaps

Released under the MIT License.