pyrekordbox.db6.database#

exception pyrekordbox.db6.database.SessionNotInitializedError[source]#

Bases: Exception

class pyrekordbox.db6.database.Rekordbox6Database(path=None, db_dir='', key='', unlock=True)[source]#

Bases: object

Rekordbox v6 master.db database handler.

Parameters:
pathstr or Path, optional

The path of the Rekordbox v6 database file. By default, pyrekordbox automatically finds the Rekordbox v6 master.db database file. This parameter is only required for opening other databases or if the configuration fails.

db_dir: str, optional

The path of the Rekordbox v6 database directory. By default, pyrekordbox automatically finds the Rekordbox v6 database directory. Usually this is also the root directory of the analysis files. This parameter is only required for finding the analysis root directory if you are opening a database, that is stored somewhere else.

keystr, optional

The database key. By default, pyrekordbox automatically reads the database key from the Rekordbox v6 configuration file. This parameter is only required if the key extraction fails.

unlock: bool, optional

Flag if the database needs to be decrypted. Set to False if you are opening an unencrypted test database.

See also

pyrekordbox.db6.tables

Rekordbox v6 database table definitions

create_rekordbox_engine

Creates the SQLAlchemy engine for the Rekordbox v6 database

Examples

Pyrekordbox automatically finds the Rekordbox v6 master.db database file and opens it when initializing the object:

>>> db = Rekordbox6Database()

Use the included getters for querying the database:

>>> db.get_content()[0]
<DjmdContent(40110712   Title=NOISE)>
Attributes:
enginesqlalchemy.engine.Engine

The SQLAlchemy engine instance for the Rekordbox v6 database.

sessionsqlalchemy.orm.Session

The SQLAlchemy session instance bound to the engine.

property no_autoflush#

Creates a no-autoflush context.

property db_directory#

!! processed by numpydoc !!

property share_directory#

!! processed by numpydoc !!

open()[source]#

Open the database by instantiating a new session using the SQLAchemy engine.

A new session instance is only created if the session was closed previously.

Examples

>>> db = Rekordbox6Database()
>>> db.close()
>>> db.open()
close()[source]#

Close the currently active session.

register_event(identifier, fn)[source]#

Registers a session event callback.

Parameters:
identifierstr

The identifier of the event, for example ‘before_flush’, ‘after_commit’, … See the SQLAlchemy documentation for a list of valid event identifiers.

fncallable

The event callback method.

unregister_event(identifier)[source]#

Removes an existing session event callback.

Parameters:
identifierstr

The identifier of the event

query(*entities, **kwargs)[source]#

Creates a new SQL query for the given entities.

Parameters:
*entitiesBase

The table objects for which the query is created.

**kwargs

Arbitrary keyword arguments used for creating the query.

Returns:
querysqlalchemy.orm.query.Query

The SQLAlchemy Query object.

Examples

Query the DjmdContent table

>>> db = Rekordbox6Database()
>>> query = db.query(DjmdContent)

Query the Title attribute of the DjmdContent table

>>> db = Rekordbox6Database()
>>> query = db.query(DjmdContent.Title)
add(instance)[source]#

Add an element to the Rekordbox database.

Parameters:
instancetables.Base

The table entry to add.

delete(instance)[source]#

Delete an element from the Rekordbox database.

Parameters:
instancetables.Base

The table entry to delte.

get_local_usn()[source]#

Returns the local sequence number (update count) of Rekordbox.

Any changes made to the Djmd… tables increments the local update count of Rekordbox. The usn entry of the changed row is set to the corresponding update count.

Returns:
usnint

The value of the local update count.

set_local_usn(usn)[source]#

Sets the local sequence number (update count) of Rekordbox.

Parameters:
usnint or str

The new update sequence number.

increment_local_usn(num=1)[source]#

Increments the local update sequence number (update count) of Rekordbox.

Parameters:
numint, optional

The number of times to increment the update counter. By default, the counter is incremented by 1.

Returns:
usnint

The value of the incremented local update count.

Examples

>>> db = Rekordbox6Database()
>>> db.get_local_usn()
70500
>>> db.increment_local_usn()
70501
>>> db.get_local_usn()
70501
autoincrement_usn(set_row_usn=True)[source]#

Auto-increments the local USN for all uncommited changes.

Parameters:
set_row_usnbool, optional

If True, set the rb_local_usn value of updated or added rows according to the uncommited update sequence.

Returns:
new_usnint

The new local update sequence number after applying all updates.

Examples

>>> db = Rekordbox6Database()
>>> db.get_local_usn()
70500
>>> content = db.get_content().first()
>>> playlist = db.get_playlist().first()
>>> content.Title = "New Title"
>>> playlist.Name = "New Name"
>>> db.autoincrement_usn(set_row_usn=True)
>>> db.get_local_usn()
70502
flush()[source]#

Flushes the buffer of the SQLAlchemy session instance.

commit(autoinc=True)[source]#

Commit the changes made to the database.

Parameters:
autoincbool, optional

If True, auto-increment the local and row USN’s before commiting the changes made to the database.

See also

autoincrement_usn

Auto-increments the local Rekordbox USN’s.

rollback()[source]#

Rolls back the uncommited changes to the database.

get_active_censor(**kwargs)[source]#

Creates a filtered query for the DjmdActiveCensor table.

get_album(**kwargs)[source]#

Creates a filtered query for the DjmdAlbum table.

get_artist(**kwargs)[source]#

Creates a filtered query for the DjmdArtist table.

get_category(**kwargs)[source]#

Creates a filtered query for the DjmdCategory table.

get_color(**kwargs)[source]#

Creates a filtered query for the DjmdColor table.

get_content(**kwargs)[source]#

Creates a filtered query for the DjmdContent table.

search_content(text)[source]#

Searches the contents of the DjmdContent table.

The search is case-insensitive and includes the following collumns of the DjmdContent table:

  • Album

  • Artist

  • Commnt

  • Composer

  • Genre

  • Key

  • OrgArtist

  • Remixer

Parameters:
textstr

The search text.

Returns:
resultslist[DjmdContent]

The resulting content elements.

get_cue(**kwargs)[source]#

Creates a filtered query for the DjmdCue table.

get_device(**kwargs)[source]#

Creates a filtered query for the DjmdDevice table.

get_genre(**kwargs)[source]#

Creates a filtered query for the DjmdGenre table.

get_history(**kwargs)[source]#

Creates a filtered query for the DjmdHistory table.

get_history_songs(**kwargs)[source]#

Creates a filtered query for the DjmdSongHistory table.

get_hot_cue_banklist(**kwargs)[source]#

Creates a filtered query for the DjmdHotCueBanklist table.

get_hot_cue_banklist_songs(**kwargs)[source]#

Creates a filtered query for the DjmdSongHotCueBanklist table.

get_key(**kwargs)[source]#

Creates a filtered query for the DjmdKey table.

get_label(**kwargs)[source]#

Creates a filtered query for the DjmdLabel table.

get_menu_items(**kwargs)[source]#

Creates a filtered query for the DjmdMenuItems table.

get_mixer_param(**kwargs)[source]#

Creates a filtered query for the DjmdMixerParam table.

get_my_tag(**kwargs)[source]#

Creates a filtered query for the DjmdMyTag table.

get_my_tag_songs(**kwargs)[source]#

Creates a filtered query for the DjmdSongMyTag table.

get_playlist(**kwargs)[source]#

Creates a filtered query for the DjmdPlaylist table.

get_playlist_songs(**kwargs)[source]#

Creates a filtered query for the DjmdSongPlaylist table.

get_playlist_contents(playlist, *entities)[source]#

Return the contents of a regular or smart playlist.

Parameters:
playlistDjmdPlaylist or int or str

The playlist instance. Can either be a DjmdPlaylist object or a playlist ID.

*entitiesBase

The table objects for which the query is created. If no entities are given, the query will return the DjmdContent objects.

Returns:
querysqlalchemy.orm.query.Query

The SQLAlchemy Query object. The query contains the content instances or the selected columns if entities are given.

Examples

Return the content instances in the playlist

>>> db = Rekordbox6Database()
>>> pl = db.get_playlist(Name="My Playlist").one()
>>> db.get_playlist_contents(pl).all()
[<DjmdContent(12345678   Title=Title1)>, <DjmdContent(23456789   Title=Title2)>]

Return only the content IDs

>>> db.get_playlist_contents(pl, DjmdContent.ID).all()
[('12345678',), ('23456789',)]
get_property(**kwargs)[source]#

Creates a filtered query for the DjmdProperty table.

Creates a filtered query for the DjmdRelatedTracks table.

Creates a filtered query for the DjmdSongRelatedTracks table.

get_sampler(**kwargs)[source]#

Creates a filtered query for the DjmdSampler table.

get_sampler_songs(**kwargs)[source]#

Creates a filtered query for the DjmdSongSampler table.

get_tag_list_songs(**kwargs)[source]#

Creates a filtered query for the DjmdSongTagList table.

get_sort(**kwargs)[source]#

Creates a filtered query for the DjmdSort table.

get_agent_registry(**kwargs)[source]#

Creates a filtered query for the AgentRegistry table.

get_cloud_agent_registry(**kwargs)[source]#

Creates a filtered query for the CloudAgentRegistry table.

get_content_active_censor(**kwargs)[source]#

Creates a filtered query for the ContentActiveCensor table.

get_content_cue(**kwargs)[source]#

Creates a filtered query for the ContentCue table.

get_content_file(**kwargs)[source]#

Creates a filtered query for the ContentFile table.

get_hot_cue_banklist_cue(**kwargs)[source]#

Creates a filtered query for the HotCueBanklistCue table.

get_image_file(**kwargs)[source]#

Creates a filtered query for the ImageFile table.

get_setting_file(**kwargs)[source]#

Creates a filtered query for the SettingFile table.

get_uuid_map(**kwargs)[source]#

Creates a filtered query for the UuidIDMap table.

generate_unused_id(table, is_28_bit=True, id_field_name='ID')[source]#

Generates an unused ID for the given table.

add_to_playlist(playlist, content, track_no=None)[source]#

Adds a track to a playlist.

Creates a new DjmdSongPlaylist object corresponding to the given content and adds it to the playlist.

Parameters:
playlistDjmdPlaylist or int or str

The playlist to add the track to. Can either be a DjmdPlaylist object or a playlist ID.

contentDjmdContent or int or str

The content to add to the playlist. Can either be a DjmdContent object or a content ID.

track_noint, optional

The track number to add the content to. If not specified, the track will be added to the end of the playlist.

Returns:
song: DjmdSongPlaylist

The song playlist object that was created from the content.

Raises:
ValueErrorIf the playlist is a folder or smart playlist.
ValueErrorIf the track number is less than 1 or to large.

Examples

Add a track to the end of a playlist:

>>> db = Rekordbox6Database()
>>> cid = 12345  # Content ID
>>> pid = 56789  # Playlist ID
>>> db.add_to_playlist(pid, cid)
<DjmdSongPlaylist(c803dfde-2236-4659-b3d7-e57221663375)>

Add a track to the beginning of a playlist:

>>> new_song = db.add_to_playlist(pid, cid, track_no=1)
>>> new_song.TrackNo
1
remove_from_playlist(playlist, song)[source]#

Removes a track from a playlist.

Parameters:
playlistDjmdPlaylist or int or str

The playlist to remove the track from. Can either be a DjmdPlaylist object or a playlist ID.

songDjmdSongPlaylist or int or str

The song to remove from the playlist. Can either be a DjmdSongPlaylist object or a song ID.

Examples

Remove a track from a playlist:

>>> db = Rekordbox6Database()
>>> pid = 56789
>>> pl = db.get_playlist(ID=pid)
>>> song = pl.Songs[0]
>>> db.remove_from_playlist(pl, song)
move_song_in_playlist(playlist, song, new_track_no)[source]#

Sets a new track number of a song.

Also updates the track numbers of the other songs in the playlist.

Parameters:
playlistDjmdPlaylist or int or str

The playlist the track is in. Can either be a DjmdPlaylist object or a playlist ID.

songDjmdSongPlaylist or int or str

The song to move inside the playlist. Can either be a DjmdSongPlaylist object or a song ID.

new_track_noint

The new track number of the song. Must be greater than 0 and less than the number of songs in the playlist.

Examples

Take a playlist containing a few tracks:

>>> db = Rekordbox6Database()
>>> pid = 56789
>>> pl = db.get_playlist(ID=pid)
>>> songs = sorted(pl.Songs, key=lambda x: x.TrackNo)
>>> [s.Content.Title for s in songs]  # noqa
['Demo Track 1', 'Demo Track 2', 'HORN', 'NOISE']

Move a track forward in a playlist:

>>> song = songs[2]
>>> db.move_song_in_playlist(pl, song, new_track_no=1)
>>> [s.Content.Title for s in sorted(pl.Songs, key=lambda x: x.TrackNo)]  # noqa
['HORN', 'Demo Track 1', 'Demo Track 2', 'NOISE']

Move a track backward in a playlist:

>>> song = songs[1]
>>> db.move_song_in_playlist(pl, song, new_track_no=4)
>>> [s.Content.Title for s in sorted(pl.Songs, key=lambda x: x.TrackNo)]  # noqa
['Demo Track 1', 'HORN', 'NOISE', 'Demo Track 2']
create_playlist(name, parent=None, seq=None, image_path=None)[source]#

Creates a new playlist in the database.

Parameters:
namestr

The name of the new playlist.

parentDjmdPlaylist or int or str, optional

The parent playlist of the new playlist. If not given, the playlist will be added to the root playlist. Can either be a DjmdPlaylist object or a playlist ID.

seqint, optional

The sequence number of the new playlist. If not given, the playlist will be added at the end of the parent playlist.

image_pathstr, optional

The path to the image file of the new playlist.

Returns:
playlistDjmdPlaylist

The newly created playlist.

Raises:
ValueErrorIf the parent playlist is not a folder.
ValueErrorIf the sequence number is less than 1 or to large.

Examples

Create a new playlist in the root playlist:

>>> db = Rekordbox6Database()
>>> pl = db.create_playlist("My Playlist")
>>> pl.ParentID
'root'

Create a new playlist in a folder:

>>> folder = db.get_playlist(Name="My Folder").one()
>>> pl = db.create_playlist("My Playlist", parent=folder)
>>> pl.ParentID
'123456'
create_playlist_folder(name, parent=None, seq=None, image_path=None)[source]#

Creates a new playlist folder in the database.

Parameters:
namestr

The name of the new playlist folder.

parentDjmdPlaylist or int or str, optional

The parent playlist of the new folder. If not given, the playlist will be added to the root playlist. Can either be a DjmdPlaylist object or a playlist ID.

seqint, optional

The sequence number of the new folder. If not given, the playlist will be added at the end of the parent playlist.

image_pathstr, optional

The path to the image file of the new playlist.

Returns:
playlist_folderDjmdPlaylist

The newly created playlist folder.

Examples

Create a new playlist folder in the root playlist:

>>> db = Rekordbox6Database()
>>> folder1 = db.create_playlist_folder("My Playlist Folder")
>>> folder1.ParentID
'root'

Create a new playlist folder in the other folder:

>>> folder2 = db.create_playlist("My Playlist Folder2", parent=folder1)
>>> folder2.ParentID
'123456'
create_smart_playlist(name, smart_list, parent=None, seq=None, image_path=None)[source]#

Creates a new smart playlist in the database.

Parameters:
namestr

The name of the new smart playlist.

smart_listSmartList

The smart list conditions to use for the new playlist.

parentDjmdPlaylist or int or str, optional

The parent playlist of the new playlist. If not given, the playlist will be added to the root playlist. Can either be a DjmdPlaylist object or a playlist ID.

seqint, optional

The sequence number of the new playlist. If not given, the playlist will be added at the end of the parent playlist.

image_pathstr, optional

The path to the image file of the new playlist.

Returns:
playlistDjmdPlaylist

The newly created playlist.

Examples

Create a new smart list which we will use for the new smart playlist:

>>> smart = SmartList(logical_operator=1)  # ALL conditions must be met
>>> smart.add_condition("genre", operator=1, value_left="House")  # is House

Create a new smart playlist in the root playlist: >>> db = Rekordbox6Database() >>> pl = db.create_smart_playlist(“My Smart Playlist”, smart) >>> pl.ID ‘123456789’

>>> pl.SmartList[:72]
'<NODE Id="123456789" LogicalOperator="1" AutomaticUpdate="1"><CONDITION '
delete_playlist(playlist)[source]#

Deletes a playlist or playlist folder from the database.

Parameters:
playlistDjmdPlaylist or int or str

The playlist or playlist folder to delete. Can either be a DjmdPlaylist object or a playlist ID.

Examples

Delete a playlist:

>>> db = Rekordbox6Database()
>>> pl = db.get_playlist(Name="My Playlist").one()
>>> db.delete_playlist(pl)

Delete a playlist folder:

>>> folder = db.get_playlist(Name="My Folder").one()
>>> db.delete_playlist(folder)
move_playlist(playlist, parent=None, seq=None)[source]#

Moves a playlist (folder) in the current parent folder or to a new one.

Parameters:
playlistDjmdPlaylist or int or str

The playlist or playlist folder to move. Can either be a DjmdPlaylist object or a playlist ID.

parentDjmdPlaylist or int or str, optional

The new parent playlist of the playlist. If not given, the playlist will be moved to seq in the current parent playlist. Can either be a DjmdPlaylist object or a playlist ID.

seqint, optional

The new sequence number of the playlist. If the parent argument is given, the playlist will be moved to seq in the new parent playlist or to the end of the new parent folder if seq=None. If the parent argument is not given, the playlist will be moved to seq in the current parent.

Examples

Take the following playlist tree:

>>> db = Rekordbox6Database()
>>> playlists = db.get_playlist().order_by(tables.DjmdPlaylist.Seq)
>>> [pl.Name for pl in playlists]  # noqa
['Folder 1', 'Folder 2', 'Playlist 1', 'Playlist 2', 'Playlist 3']

The playlists and folders above are all in the root plalyist folder. Move a playlist in the current parent folder:

>>> pl = db.get_playlist(Name="Playlist 2").one()  # noqa
>>> db.move_playlist(pl, seq=2)
>>> playlists = db.get_playlist().order_by(tables.DjmdPlaylist.Seq)
>>> [pl.Name for pl in playlists]  # noqa
['Folder 1', 'Playlist 2', 'Folder 2', 'Playlist 1', 'Playlist 3']

Move a playlist to a new parent folder:

>>> pl = db.get_playlist(Name="Playlist 1").one()  # noqa
>>> parent = db.get_playlist(Name="Folder 1").one()  # noqa
>>> db.move_playlist(pl, parent=parent)
>>> db.get_playlist(ParentID=parent.ID).all()
['Playlist 1']
rename_playlist(playlist, name)[source]#

Renames a playlist or playlist folder.

Parameters:
playlistDjmdPlaylist or int or str

The playlist or playlist folder to move. Can either be a DjmdPlaylist object or a playlist ID.

namestr

The new name of the playlist or playlist folder.

Examples

Take the following playlist tree:

>>> db = Rekordbox6Database()
>>> playlists = db.get_playlist().order_by(tables.DjmdPlaylist.Seq)
>>> [pl.Name for pl in playlists]  # noqa
['Playlist 1', 'Playlist 2']

Rename a playlist:

>>> pl = db.get_playlist(Name="Playlist 1").one()  # noqa
>>> db.rename_playlist(pl, name="Playlist new")
>>> playlists = db.get_playlist().order_by(tables.DjmdPlaylist.Seq)
>>> [pl.Name for pl in playlists]  # noqa
['Playlist new', 'Playlist 2']
add_album(name, artist=None, image_path=None, compilation=None, search_str=None)[source]#

Adds a new album to the database.

Parameters:
namestr

The name of the album. Must be a unique name (case-sensitive). If an album with the same name already exists in the database, use the ID of the existing album instead.

artiststr or int or DjmdArtist, optional

The artist of the album. Can either be a DjmdArtist object or an artist ID.

image_pathstr, optional

The path to the album cover image.

compilationbool, optional

Whether the album is a compilation album. If not given, the default value of False is used.

search_strstr, optional

The search string of the album.

Returns:
albumDjmdAlbum

The newly created album.

Raises:
ValueErrorIf an album with the same name already exists in the database.

Examples

Add a new album to the database:

>>> db = Rekordbox6Database()
>>> db.add_album(name="Album 1")
<DjmdAlbum(148754249  Name=Album 1)>

Add a new album to the database with an album artist:

>>> artist = db.get_artist(Name="Artist 1").one()  # noqa
>>> db.add_album(name="Album 2", artist=artist)
<DjmdAlbum(148754249  Name=Album 2)>

For setting the album of a track, the usual procedure is to first check if an entry with the same album name already exists in the database, and if not, add a new album:

>>> name = "Album name"
>>> content = db.get_content().one()
>>> album = db.get_album(Name=name).one_or_none()
>>> if album is None:
...     album = db.add_album(name=name)
>>> content.AlbumID = album.ID
add_artist(name, search_str=None)[source]#

Adds a new artist to the database.

Parameters:
namestr

The name of the artist. Must be a unique name (case-sensitive). If an artist with the same name already exists in the database, use the ID of the existing artist instead.

search_strstr, optional

The search string of the artist.

Returns:
artistDjmdArtist

The newly created artist.

Raises:
ValueErrorIf an artist with the same name already exists in the database.

Examples

Add a new artist to the database:

>>> db = Rekordbox6Database()
>>> db.add_artist(name="Artist 1")
<DjmdArtist(123456789, Name='Artist 1')>

Add a new artist to the database with a custom search string:

>>> db.add_artist(name="Artist 2", search_str="artist 2")
<DjmdArtist(123456789, Name='Artist 2')>

For setting the artist of a track, the usual procedure is to first check if an entry with the same artist name already exists in the database, and if not, add a new artist:

>>> name = "Artist name"
>>> content = db.get_content().one()
>>> artist = db.get_artist(Name=name).one_or_none()
>>> if artist is None:
...     artist = db.add_artist(name=name)
>>> content.ArtistID = artist.ID
add_genre(name)[source]#

Adds a new genre to the database.

Parameters:
namestr

The name of the genre. Must be a unique name (case-sensitive). If a genre with the same name already exists in the database, use the ID of the existing genre instead.

Returns:
genreDjmdGenre

The newly created genre.

Raises:
ValueErrorIf a genre with the same name already exists in the database.

Examples

Add a new genre to the database:

>>> db = Rekordbox6Database()
>>> db.add_genre(name="Genre 1")
<DjmdGenre(123456789 Name=Genre 1)>

For setting the genre of a track, the usual procedure is to first check if an entry with the same genre name already exists in the database, and if not, add a new genre:

>>> name = "Genre name"
>>> content = db.get_content().one()
>>> genre = db.get_genre(Name=name).one_or_none()
>>> if genre is None:
...     genre = db.add_genre(name=name)
>>> content.GenreID = genre.ID
add_label(name)[source]#

Adds a new label to the database.

Parameters:
namestr

The name of the label. Must be a unique name (case-sensitive). If a label with the same name already exists in the database, use the ID of the existing label instead.

Returns:
labelDjmdLabel

The newly created label.

Raises:
ValueErrorIf a label with the same name already exists in the database.

Examples

Add a new label to the database:

>>> db = Rekordbox6Database()
>>> db.add_label(name="Label 1")
<DjmdLabel(123456789 Name=Label 1)>

For setting the label of a track, the usual procedure is to first check if an entry with the same label name already exists in the database, and if not, add a new label:

>>> name = "Label name"
>>> content = db.get_content().one()
>>> label = db.get_label(Name=name).one_or_none()
>>> if label is None:
...     label = db.add_label(name=name)
>>> content.LabelID = label.ID
add_content(path, **kwargs)[source]#

Adds a new track to the database.

Parameters:
pathstr

Absolute path to the music file to be added.

**kwargs:

Keyword arguments passed to DjmdContent on creation. These arguments should be a valid DjmdContent field.

Returns:
contentDjmdContent

The newly created track.

Raises:
ValueErrorIf a track with the same path already exists in the database.
ValueErrorIf the file type is invalid.

Examples

Add a new track to the database:

>>> db = Rekordbox6Database()
>>> db.add_content("/Users/foo/Downloads/banger.mp3", Title="Banger")
<DjmdContent(123456789 Title=Banger)>
get_mysetting_paths()[source]#

Returns the file paths of the local Rekordbox MySetting files.

Returns:
pathslist[str]

the file paths of the local MySetting files.

get_anlz_dir(content)[source]#

Returns the directory path containing the ANLZ analysis files of a track.

Parameters:
contentDjmdContent or int or str

The content corresponding to a track in the Rekordbox v6 database. If an integer is passed the database is queried for the DjmdContent entry.

Returns:
anlz_dirPath

The path of the directory containing the analysis files for the content.

get_anlz_paths(content)[source]#

Returns all existing ANLZ analysis file paths of a track.

Parameters:
contentDjmdContent or int or str

The content corresponding to a track in the Rekordbox v6 database. If an integer is passed the database is queried for the DjmdContent entry.

Returns:
anlz_pathsdict[str, Path]

The analysis file paths for the content as dictionary. The keys of the dictionary are the file types (“DAT”, “EXT” or “EX2”).

read_anlz_files(content)[source]#

Reads all existing ANLZ analysis files of a track.

Parameters:
contentDjmdContent or int or str

The content corresponding to a track in the Rekordbox v6 database. If an integer is passed the database is queried for the DjmdContent entry.

Returns:
anlz_filesdict[str, AnlzFile]

The analysis files for the content as dictionary. The keys of the dictionary are the file paths.

get_anlz_path(content, type_)[source]#

Returns the file path of an ANLZ analysis file of a track.

Parameters:
contentDjmdContent or int or str

The content corresponding to a track in the Rekordbox v6 database. If an integer is passed the database is queried for the DjmdContent entry.

type_str, optional

The type of the analysis file to return. Must be one of “DAT”, “EXT” or “EX2”. “DAT” by default.

Returns:
anlz_pathPath or None

The file path of the analysis file for the content. If the file does not exist, None is returned.

read_anlz_file(content, type_)[source]#

Reads an ANLZ analysis file of a track.

Parameters:
contentDjmdContent or int or str

The content corresponding to a track in the Rekordbox v6 database. If an integer is passed the database is queried for the DjmdContent entry.

type_str, optional

The type of the analysis file to return. Must be one of “DAT”, “EXT” or “EX2”. “DAT” by default.

Returns:
anlz_fileAnlzFile or None

The analysis file for the content. If the file does not exist, None is returned.

update_content_path(content, path, save=True, check_path=True, commit=True)[source]#

Update the file path of a track in the Rekordbox v6 database.

This changes the FolderPath entry in the DjmdContent table and the path tag (PPTH) of the corresponding ANLZ analysis files.

Parameters:
contentDjmdContent or int or str

The DjmdContent element to change. If an integer is passed the database is queried for the content.

pathstr or Path

The new file path of the database entry.

savebool, optional

If True, the changes made are written to disc.

check_pathbool, optional

If True, raise an assertion error if the given file path does not exist.

commitbool, optional

If True, the changes are committed to the database. True by default.

Examples

If, for example, the file NOISE.wav was moved up a few directories (from …/Sampler/OSC_SAMPLER/PRESET ONESHOT/ to …/Sampler/) the file could no longer be opened in Rekordbox, since the database still contains the old file path:

>>> db = Rekordbox6Database()
>>> cont = db.get_content()[0]
>>> cont.FolderPath
C:/Music/PioneerDJ/Sampler/OSC_SAMPLER/PRESET ONESHOT/NOISE.wav

Updating the path changes the database entry

>>> new_path = "C:/Music/PioneerDJ/Sampler/PRESET ONESHOT/NOISE.wav"
>>> db.update_content_path(cont, path)
>>> cont.FolderPath
C:/Music/PioneerDJ/Sampler/PRESET ONESHOT/NOISE.wav

and updates the file path in the corresponding ANLZ analysis files:

>>> files = self.read_anlz_files(cont.ID)
>>> file = list(files.values())[0]
>>> file.get("path")
C:/Music/PioneerDJ/Sampler/PRESET ONESHOT/NOISE.wav
update_content_filename(content, name, save=True, check_path=True, commit=True)[source]#

Update the file name of a track in the Rekordbox v6 database.

This changes the FolderPath entry in the DjmdContent table and the path tag (PPTH) of the corresponding ANLZ analysis files.

Parameters:
contentDjmdContent or int or str

The DjmdContent element to change. If an integer is passed the database is queried for the content.

namestr

The new file name of the database entry.

savebool, optional

If True, the changes made are written to disc.

check_pathbool, optional

If True, raise an assertion error if the new file path does not exist.

commitbool, optional

If True, the changes are committed to the database. True by default.

See also

update_content_path

Update the file path of a track in the Rekordbox database.

Examples

Updating the file name changes the database entry

>>> db = Rekordbox6Database()
>>> cont = db.get_content()[0]
>>> cont.FolderPath
C:/Music/PioneerDJ/Sampler/OSC_SAMPLER/PRESET ONESHOT/NOISE.wav
>>> new_name = "noise"
>>> db.update_content_filename(cont, new_name)
>>> cont.FolderPath
C:/Music/PioneerDJ/Sampler/OSC_SAMPLER/PRESET ONESHOT/noise.wav

and updates the file path in the corresponding ANLZ analysis files:

>>> files = self.read_anlz_files(cont.ID)
>>> file = list(files.values())[0]
>>> cont.FolderPath == file.get("path")
True
to_dict(verbose=False)[source]#

Convert the database to a dictionary.

Parameters:
verbose: bool, optional

If True, print the name of the table that is currently converted.

Returns:
dict

A dictionary containing the database tables as keys and the table data as a list of dicts.

to_json(file, indent=4, sort_keys=True, verbose=False)[source]#

Convert the database to a JSON file.

copy_unlocked(output_file)[source]#