Class Database

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class Database
    extends Object
    implements Closeable

    Parses rekordbox database export files, providing access to the information they contain.

    • Field Detail

      • sourceFile

        public final File sourceFile
        Holds a reference to the file this database was constructed from.
      • trackIndex

        public final Map<Long,​RekordboxPdb.TrackRow> trackIndex
        A map from track ID to the actual track object. If this ends up taking too much space, it would be possible to reorganize the Kaitai Struct mapping specification so that rows are parse instances of the file itself, with parameters for the page and row numbers as well as the page type, allowing them to be loaded directly, and this index would only need to store their addresses. Or we could figure out how to find and use the index tables that must exist in the file somewhere, and avoid building this at all.
      • trackTitleIndex

        public final SortedMap<String,​SortedSet<Long>> trackTitleIndex
        A sorted map from track title to the set of track IDs with that title.
      • trackArtistIndex

        public final SortedMap<Long,​SortedSet<Long>> trackArtistIndex
        A sorted map from artist ID to the set of track IDs associated with that artist.
      • trackAlbumIndex

        public final SortedMap<Long,​SortedSet<Long>> trackAlbumIndex
        A sorted map from album ID to the set of track IDs associated with that album.
      • trackGenreIndex

        public final SortedMap<Long,​SortedSet<Long>> trackGenreIndex
        A sorted map from genre ID to the set of track IDs associated with that genre.
      • historyPlaylistNameIndex

        public final SortedMap<String,​Long> historyPlaylistNameIndex
        A sorted map from history playlist name to the ID by which its entries can be found.
      • historyPlaylistIndex

        public final Map<Long,​List<Long>> historyPlaylistIndex
        A map from playlist ID to the list of tracks IDs making up a history playlist.
      • artistNameIndex

        public final SortedMap<String,​SortedSet<Long>> artistNameIndex
        A sorted map from artist name to the set of artist IDs with that name.
      • colorNameIndex

        public final SortedMap<String,​SortedSet<Long>> colorNameIndex
        A sorted map from color name to the set of color IDs with that name.
      • albumNameIndex

        public final SortedMap<String,​SortedSet<Long>> albumNameIndex
        A sorted map from album name to the set of album IDs with that name.
      • albumArtistIndex

        public final SortedMap<Long,​SortedSet<Long>> albumArtistIndex
        A sorted map from artist ID to the set of album IDs associated with that artist.
      • labelNameIndex

        public final SortedMap<String,​SortedSet<Long>> labelNameIndex
        A sorted map from label name to the set of label IDs with that name.
      • musicalKeyIndex

        public final Map<Long,​RekordboxPdb.KeyRow> musicalKeyIndex
        A map from (musical) key ID to the actual key object.
      • musicalKeyNameIndex

        public final SortedMap<String,​SortedSet<Long>> musicalKeyNameIndex
        A sorted map from musical key name to the set of musical key IDs with that name.
      • genreNameIndex

        public final SortedMap<String,​SortedSet<Long>> genreNameIndex
        A sorted map from genre name to the set of genre IDs with that name.
      • playlistIndex

        public final Map<Long,​List<Long>> playlistIndex
        A map from playlist ID to the list of tracks IDs making up a playlist.
    • Constructor Detail

      • Database

        public Database​(File sourceFile)
                 throws IOException
        Construct a database access instance from the specified recordbox export file. The file can obtained either from the SD or USB media, or directly from a player using FileFetcher.fetch(InetAddress, String, String, File). Be sure to call close() when you are done using the parsed database to close the underlying file or users will be unable to unmount the drive holding it until they quit your program.
        Parameters:
        sourceFile - an export.pdb file
        Throws:
        IOException - if there is a problem reading the file
    • Method Detail

      • close

        public void close()
                   throws IOException
        Close the file underlying the parsed database. This needs to be called if you want to be able to unmount the media on which that file resides, but once it is done, you can no longer access lazy elements within the database which have not already been parsed.
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        Throws:
        IOException - if there is a problem closing the file
      • getText

        public static String getText​(RekordboxPdb.DeviceSqlString string)
        Helper function to extract the text value from one of the strings found in the database, which have a variety of obscure representations.
        Parameters:
        string - the string-encoding structure
        Returns:
        the text it contains, which may have zero length, but will never be null