Package org.deepsymmetry.cratedigger
Class Database
- java.lang.Object
-
- org.deepsymmetry.cratedigger.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Database.PlaylistFolderEntry
Playlist folders can either contain playlists or other folders.
-
Field Summary
Fields Modifier and Type Field Description SortedMap<Long,SortedSet<Long>>
albumArtistIndex
A sorted map from artist ID to the set of album IDs associated with that artist.Map<Long,RekordboxPdb.AlbumRow>
albumIndex
A map from album ID to the actual album object.SortedMap<String,SortedSet<Long>>
albumNameIndex
A sorted map from album name to the set of album IDs with that name.Map<Long,RekordboxPdb.ArtistRow>
artistIndex
A map from artist ID to the actual artist object.SortedMap<String,SortedSet<Long>>
artistNameIndex
A sorted map from artist name to the set of artist IDs with that name.Map<Long,RekordboxPdb.ArtworkRow>
artworkIndex
A map from artwork ID to the artwork row containing its file path.Map<Long,RekordboxPdb.ColorRow>
colorIndex
A map from color ID to the actual color object.SortedMap<String,SortedSet<Long>>
colorNameIndex
A sorted map from color name to the set of color IDs with that name.Map<Long,RekordboxPdb.GenreRow>
genreIndex
A map from genre ID to the actual genre object.SortedMap<String,SortedSet<Long>>
genreNameIndex
A sorted map from genre name to the set of genre IDs with that name.Map<Long,List<Long>>
historyPlaylistIndex
A map from playlist ID to the list of tracks IDs making up a history playlist.SortedMap<String,Long>
historyPlaylistNameIndex
A sorted map from history playlist name to the ID by which its entries can be found.Map<Long,RekordboxPdb.LabelRow>
labelIndex
A map from label ID to the actual label object.SortedMap<String,SortedSet<Long>>
labelNameIndex
A sorted map from label name to the set of label IDs with that name.Map<Long,RekordboxPdb.KeyRow>
musicalKeyIndex
A map from (musical) key ID to the actual key object.SortedMap<String,SortedSet<Long>>
musicalKeyNameIndex
A sorted map from musical key name to the set of musical key IDs with that name.Map<Long,List<Database.PlaylistFolderEntry>>
playlistFolderIndex
Map<Long,List<Long>>
playlistIndex
A map from playlist ID to the list of tracks IDs making up a playlist.File
sourceFile
Holds a reference to the file this database was constructed from.SortedMap<Long,SortedSet<Long>>
trackAlbumIndex
A sorted map from album ID to the set of track IDs associated with that album.SortedMap<Long,SortedSet<Long>>
trackArtistIndex
A sorted map from artist ID to the set of track IDs associated with that artist.SortedMap<Long,SortedSet<Long>>
trackGenreIndex
A sorted map from genre ID to the set of track IDs associated with that genre.Map<Long,RekordboxPdb.TrackRow>
trackIndex
A map from track ID to the actual track object.SortedMap<String,SortedSet<Long>>
trackTitleIndex
A sorted map from track title to the set of track IDs with that title.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the file underlying the parsed database.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.
-
-
-
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.
-
artistIndex
public final Map<Long,RekordboxPdb.ArtistRow> artistIndex
A map from artist ID to the actual artist object.
-
artistNameIndex
public final SortedMap<String,SortedSet<Long>> artistNameIndex
A sorted map from artist name to the set of artist IDs with that name.
-
colorIndex
public final Map<Long,RekordboxPdb.ColorRow> colorIndex
A map from color ID to the actual color object.
-
colorNameIndex
public final SortedMap<String,SortedSet<Long>> colorNameIndex
A sorted map from color name to the set of color IDs with that name.
-
albumIndex
public final Map<Long,RekordboxPdb.AlbumRow> albumIndex
A map from album ID to the actual album object.
-
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.
-
labelIndex
public final Map<Long,RekordboxPdb.LabelRow> labelIndex
A map from label ID to the actual label object.
-
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.
-
genreIndex
public final Map<Long,RekordboxPdb.GenreRow> genreIndex
A map from genre ID to the actual genre object.
-
genreNameIndex
public final SortedMap<String,SortedSet<Long>> genreNameIndex
A sorted map from genre name to the set of genre IDs with that name.
-
artworkIndex
public final Map<Long,RekordboxPdb.ArtworkRow> artworkIndex
A map from artwork ID to the artwork row containing its file path.
-
playlistIndex
public final Map<Long,List<Long>> playlistIndex
A map from playlist ID to the list of tracks IDs making up a playlist.
-
playlistFolderIndex
public final Map<Long,List<Database.PlaylistFolderEntry>> playlistFolderIndex
-
-
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 usingFileFetcher.fetch(InetAddress, String, String, File)
. Be sure to callclose()
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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- 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
-
-