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.
cd examples/export-collection
npm install
npm startOpen Realm in read-only mode.
const initialized = init(osuLazerRealmPath, { readOnly: true })
The collection module returns detached snapshots. Reading .get here loads every collection.
const all = initialized.collections.get
Enter all to export every collection, or type an exact name to export one. Name lookup returns the first matching snapshot.
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)`)
}
exportLegacy returns a buffer in osu!stable's collections.db format. Write that buffer directly to the requested path.
writeFileSync(outputPath, data)
API used: init · OsuFilesAPI#collections
Import a collection database
Merges a legacy collections.db file into the collections already stored in Realm.
cd examples/import-collection
npm install
npm startImport the legacy database in one call. Collections with new names are created; matching names receive any beatmap hashes they do not already contain.
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`)
API used: init · OsuFilesAPI#collections
Manage a collection
Adds beatmaps to a collection by online ID and removes them by list index.
cd examples/manage-collection
npm install
npm startCollection queries return detached snapshots. Changes go through the collection module rather than mutating col.
const col = osu.collections.get.byName(name).first()
if (!col) { console.log(`'${name}' not found.`); continue }
Collections store beatmap MD5 hashes, not online IDs. Look up the beatmap first, then add its MD5 hash to the selected collection.
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)
Removal uses the same MD5 hash. The local array is updated as well so the next prompt reflects the change without another query.
osu.collections.removeBeatmap(String(col.ID), md5)
hashes.splice(idx, 1)
API used: init · OsuFilesAPI#collections · OsuFilesAPI#beatmaps