Skip to content

A Rock Band song metadata file parser written in Javascript.

License

Notifications You must be signed in to change notification settings

ruggeryiury/rbdta-js

Repository files navigation

API

The main exports of this package consists on two classes (SongsDTA() and SongUpdatesDTA()) that represents the contents of a .dta file to be processed. All secondary methods used on these classes is also available to import from rbdta-js/core and rbdta-js/lib.

SongsDTA class

SongsDTA is a class that represents the contents of a songs.dta file. It is initalized passing a path as an argument, this argument can be:

  • A path to a songs.dta file (as string or an instantiated Path class).
  • The contents of a DTA file (as string).
  • A Buffer object of a DTA file.
  • A parsed DTAFile object, or an array of parsed DTAFile objects.
import { SongsDTA } from 'rbdta-js'

const dtaPath = 'path/to/songs.dta'
const songs = new SongsDTA(dtaPath)

console.log(songs.getSongByID('song_shortname')!.name) // <-- "Song title"

SongsDTA is more strict when parsing a song, expecting full information of a song and it will throw an Error if any song is found without all necessary values. By keeping full DTA information, the SongsDTA classes contains more methods to manipulate the songs rather than the SongUpdatesDTA class. With this class you can parse:

  • Any custom song DTA generated by MAGMA when compiling a custom song.
  • Any official RB3 and post-RB3 songs.

Class properties

  • songs DTAFile[] An array with object that represents the contents of a DTA song entry.

Static methods

fromURL()

Asynchronously fetches a songs.dta file from an URL.

  • Parameters:

    • url string The URL of the .dta file.
  • Returns: Promise<SongsDTA> A new instantiated SongsDTA class.

import { SongsDTA } from 'rbdta-js'

// This DTA file is found on "./assets/songs.dta"
const songsDTAURL = 'https://raw.githubusercontent.com/ruggeryiury/rbdta-js/refs/heads/main/assets/songs.dta'
const songs = await SongsDTA.fromURL(songsDTAURL)

console.log(songs.getSongByID('7748motherearth')!.name) // <-- "Mother Earth"

Class methods

getSongByID()

Returns a specific song contents based on its song ID (shortname). If no song if found, it will returns as undefined.

  • Parameters:

    • id string The unique shortname ID of the song you want to fetch.
  • Returns: DTAFile | undefined

import { SongsDTA } from 'rbdta-js'

const dtaPath = 'path/to/songs.dta'
const songs = new SongsDTA(dtaPath)

// The following code line might return a DTAFile object
// or undefined if no song with provided unique song ID
// (shortname) is found.
console.log(songs.getSongByID('song_shortname'))

patchSongIDs()

Patches non-numerical song IDs to numerical ones, using specific CRC32 hashing method.

See the original C# function on GitHub Gist, coded by Emma (InvoxiPlayGames).

import { SongsDTA } from 'rbdta-js'

const dtaPath = 'path/to/songs.dta'
const songs = new SongsDTA(dtaPath)

// All songs IDs will be patched to numerical IDs, if no
// numerical ID is found for the song.
songs.patchSongIDs()

patchEncodings()

Patches the encoding values of each song.

import { SongsDTA } from 'rbdta-js'

const dtaPath = 'path/to/songs.dta'
const songs = new SongsDTA(dtaPath)

// All songs string values will be checked if any non-ASCII characters
// is found on any string value of the song. If non-ASCII characters
// is found, the song encoding will be set to UTF-8, simulating the
// behavior of single song packs and fixing the song's values to be
// displayed correctly, specially on Rock Band 3 Deluxe.
songs.patchEncodings()

update()

Updates a song contents based on its song ID (shortname).

  • Parameters:

    • id string The unique shortname ID of the song you want to update.
    • update DTAUpdateOptionsForExtend An object with updates values to be applied on the DTAFile song entry.
import { SongsDTA } from 'rbdta-js'

const dtaPath = 'path/to/songs.dta'
const songs = new SongsDTA(dtaPath)
console.log(songs.getSongByID('7748motherearth')!.name) // <-- "Mother Earth"
songs.update('7748motherearth', {
  // Change the name of the custom which the unique string ID
  // (shortname) is "7748motherearth".
  name: 'New Name',
})
console.log(songs.getSongByID('7748motherearth')!.name) // <-- "New Name"

updateAll()

Updates all songs with provided update values.

  • Parameters:
    • update DTAUpdateOptionsForExtend update An object with updates values to be applied on each DTAFile song entry.

sort()

Sorts all songs entries using several sorting methods.

  • Parameters:
    • sortBy SongSortingTypes The sorting method type.
import { SongsDTA } from 'rbdta-js'

const dtaPath = 'path/to/songs.dta'
// The songs sorting will be inherit from the songs.dta file.
const songs = new SongsDTA(dtaPath)

// Now, the whole songs.dta will be sorted by song title.
songs.sort('Song Title')

stringify()

Stringifies all songs from this class to .dta file contents.

  • Parameters:

    • options ? SongStringifyOptions An object with values that changes the behavior of the stringify process.
  • Returns: string

import { SongsDTA } from 'rbdta-js'

const dtaPath = 'path/to/songs.dta'
const songs = new SongsDTA(dtaPath)
console.log(songs.stringify({ type: 'rb3_dlc', guitarCores: true }))

SongUpdatesDTA class

SongUpdatesDTA is a class that represents the contents of a songs_updates.dta file. It is initalized passing a path as an argument, this argument can be:

  • A path to a songs_updates.dta file (as string or an instantiated Path class).
  • The contents of a DTA update file (as string).
  • A Buffer object of a DTA update file.
  • A DTAUpdateOptions object, or an array of DTAUpdateOptions objects.

SongUpdatesDTA parses incomplete DTA information. With this class you can parse:

  • Pre-RB3 songs.
  • Any songs_updates.dta file type.

Class properties

  • updates PartialDTAFile[] An array with object that represents the contents of a DTA updates song entry.

Static methods

fromURL()

Asynchronously fetches a songs_updates.dta file from an URL.

  • Parameters:

    • url string The URL of the .dta file.
  • Returns: Promise<SongUpdatesDTA> A new instantiated SongUpdatesDTA class.

import { SongUpdatesDTA } from 'rbdta-js'

// This DTA file is found on RB3DX repo.
const songsDTAURL = 'https://raw.githubusercontent.com/hmxmilohax/rock-band-3-deluxe/refs/heads/main/_ark/dx/song_updates/vanilla.dta'
const songs = await SongUpdatesDTA.fromURL(songsDTAURL)

console.log(songs.getSongByID('gimmethreesteps')!.album_name) // <-- "(pronounced 'leh-'nérd 'skin-'nérd)"

getSongByID()

Fetches a specific song updates contents based on its song ID (shortname). If no song if found, it will returns as undefined.

  • Parameters:

    • id string The unique shortname ID of the song update you want to fetch.
  • Returns: PartialDTAFile | undefined

import { SongUpdatesDTA } from 'rbdta-js'

const dtaUpdPath = 'path/to/songs_updates.dta'
const updates = new SongUpdatesDTA(dtaUpdPath)

// The following code line might return a PartialDTAFile object
// or undefined if no song with provided unique song update ID
// (shortname) is found.
console.log(updates.getSongByID('song_shortname'))

update()

Updates a song updates contents based on its song ID (shortname).

  • Parameters:

    • id string The unique shortname ID of the song you want to update.
    • update DTAUpdateOptionsForExtend An object with updates values to be applied on the PartialDTAFile song updates entry.
import { SongUpdatesDTA } from 'rbdta-js'

const dtaUpdPath = 'path/to/songs_updates.dta'
const updates = new SongUpdatesDTA(dtaUpdPath)
console.log(updates.getSongByID('anysong')!.name) // <-- "Any Song Title"
updates.update('anysong', {
  // Change the name of the custom which the unique string ID
  // (shortname) is "anysong".
  name: 'New Name',
})
console.log(updates.getSongByID('anysong')!.name) // <-- "New Name"

sort()

Sorts all songs updates entries using several sorting methods.

  • Parameters:
    • sortBy SongSortingTypes The sorting method type.
import { SongUpdatesDTA } from 'rbdta-js'

const dtaUpdPath = 'path/to/songs_updates.dta'
// The updates sorting will be inherit from the songs.dta file.
const updates = new SongUpdatesDTA(dtaPath)

// Now, the whole songs.dta will be sorted by their unique string ID (shortname)
updates.sort('ID')

stringify()

Stringifies all songs updates from this class to .dta file contents.

  • Parameters:

    • options ? SongUpdatesStringifyOptions An object with values that changes the behavior of the stringify process.
  • Returns: string

import { SongUpdatesDTA } from 'rbdta-js'

const dtaUpdPath = 'path/to/songs_updates.dta'
const updates = new SongUpdatesDTA(dtaUpdPath)
console.log(updates.stringify({ allSongsInline: true }))

More Rock Band related projects

About

A Rock Band song metadata file parser written in Javascript.

Topics

Resources

License

Stars

Watchers

Forks