pyrekordbox.devicelib_plus.database#

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

Bases: Exception

class pyrekordbox.devicelib_plus.database.DeviceLibraryPlus(path=None, key='', unlock=True)[source]#

Bases: object

Rekordbox Device Library Plus database handler.

Parameters:
pathstr or Path

The path of the exportLibrary.db database file.

keystr, optional

The database key. By default, pyrekordbox automatically uses a known key. This parameter is only required if the key 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.device_lib_plus.models

Device Library Plus table definitions

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.

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 = DeviceLibraryPlus()
>>> 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 Content table

>>> db = DeviceLibraryPlus()
>>> query = db.query(Content)

Query the title attribute of the Content table

>>> db = DeviceLibraryPlus()
>>> query = db.query(Content.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.

flush()[source]#

Flushes the buffer of the SQLAlchemy session instance.

commit()[source]#

Commit the changes made to the database.

rollback()[source]#

Rolls back the uncommited changes to the database.

get_album(**kwargs)[source]#

Creates a filtered query for the Album table.

get_artist(**kwargs)[source]#

Creates a filtered query for the Artist table.

get_category(**kwargs)[source]#

Creates a filtered query for the Category table.

get_color(**kwargs)[source]#

Creates a filtered query for the Color table.

get_content(**kwargs)[source]#

Creates a filtered query for the Content table.

get_cue(**kwargs)[source]#

Creates a filtered query for the Cue table.

get_genre(**kwargs)[source]#

Creates a filtered query for the Genre table.

get_history(**kwargs)[source]#

Creates a filtered query for the History table.

get_history_content(**kwargs)[source]#

Creates a filtered query for the HistoryContent table.

get_hot_cue_banklist(**kwargs)[source]#

Creates a filtered query for the HotCueBankList table.

get_hot_cue_banklist_cue(**kwargs)[source]#

Creates a filtered query for the HotCueBankListCue table.

get_image(**kwargs)[source]#

Creates a filtered query for the Image table.

get_key(**kwargs)[source]#

Creates a filtered query for the Key table.

get_label(**kwargs)[source]#

Creates a filtered query for the Label table.

get_menu_item(**kwargs)[source]#

Creates a filtered query for the MenuItem table.

get_my_tag(**kwargs)[source]#

Creates a filtered query for the MyTag table.

get_my_tag_content(**kwargs)[source]#

Creates a filtered query for the MyTagContent table.

get_playlist(**kwargs)[source]#

Creates a filtered query for the Playlist table.

get_playlist_content(**kwargs)[source]#

Creates a filtered query for the PlaylistContent table.

get_property(**kwargs)[source]#

Creates a filtered query for the Property table.

Creates a query for the RecommendedLike table.

get_sort(**kwargs)[source]#

Creates a filtered query for the Sort table.

add_album(name, artist_id=None, image_id=None, is_compilation=False, search_string=None)[source]#

Create a new album entry in the database.

Parameters:
namestr

The name of the album.

artist_idint, optional

The ID of the artist associated with the album. If None, no artist is set.

image_idint, optional

The ID of the album image. If None, no image is set.

is_compilationbool, optional

Flag indicating if the album is a compilation. Defaults to False.

search_stringstr, optional

A search string for the album. Defaults to None.

Returns:
models.Album

The newly created album object.

add_artist(name, search_string=None)[source]#

Create a new artist entry in the database.

Parameters:
namestr

The name of the artist.

search_stringstr, optional

A search string for the artist. Defaults to None.

Returns:
models.Artist

The newly created artist object.

add_category(menu_item_id, seq, is_visible=True)[source]#

Create a new category entry in the database.

Parameters:
menu_item_idint

The ID of the menu item associated with the category.

seqint

The sequence number of the category.

is_visiblebool, optional

Flag indicating if the category is visible. Defaults to True.

Returns:
models.Category

The newly created category object.

add_color(name)[source]#

Create a new color entry in the database.

Parameters:
namestr

The name of the color.

Returns:
models.Color

The newly created color object.

add_content(path, file_type, bitrate=0, bit_depth=0, sampling_rate=0, analysis_path=None, **kwargs)[source]#

Create a new content entry in the database.

Parameters:
pathPathLike

The path to the content file.

file_typeint

The type of the content file.

bitrateint, optional

The bitrate of the content file. Defaults to 0.

bit_depthint, optional

The bit depth of the content file. Defaults to 0.

sampling_rateint, optional

The sampling rate of the content file. Defaults to 0.

analysis_pathPathLike, optional

The path to the analysis data file on the device. Defaults to None.

**kwargsAny

Arbitrary keyword arguments used to set additional attributes of the content.

Returns:
models.Content

The newly created content object.

add_content_from_db(path, djmd_content)[source]#

Create a new content entry in the database from a DjmdContent object.

Parameters:
pathPathLike

The path to the content file.

djmd_contentDjmdContent

The DjmdContent object containing the content data.

Returns:
models.Content

The newly created content object.

add_genre(name)[source]#

Create a new genre entry in the database.

Parameters:
namestr

The name of the genre.

Returns:
models.Genre

The newly created genre object.

add_image(path)[source]#

Create a new image entry in the database.

Parameters:
pathPath

The path to the image file.

Returns:
models.Image

The newly created image object.

add_key(name)[source]#

Create a new key entry in the database.

Parameters:
namestr

The name of the key.

Returns:
models.Key

The newly created key object.

add_label(name)[source]#

Create a new label entry in the database.

Parameters:
namestr

The name of the label.

Returns:
models.Label

The newly created label object.

add_menu_item(kind, name)[source]#

Create a new menu item entry in the database.

Parameters:
kindint

The kind of the menu item.

namestr

The name of the menu item.

Returns:
models.MenuItem

The newly created menu item object.

add_my_tag(name, seq=None, attribute=0, parent_id=0)[source]#

Create a new MyTag entry in the database.

Parameters:
namestr

The name of the MyTag.

seqint, optional

The sequence number of the MyTag. If None, the new myTag entry will be added to the end of the parent myTag. Defaults to None.

attributeint, optional

The attribute of the MyTag. Defaults to 0.

parent_idint, optional

The ID of the parent MyTag. Defaults to 0, which means the MyTag is a top-level tag.

Returns:
models.MyTag

The newly created MyTag object.

add_my_tag_content(my_tag_id, content_id)[source]#

Create a new MyTagContent entry in the database.

Parameters:
my_tag_idint

The ID of the MyTag associated with the content.

content_idint

The ID of the content associated with the MyTag.

Returns:
models.MyTagContent

The newly created MyTagContent object.

add_playlist(name, seq=None, parent_id=0, image_id=None)[source]#

Create a new playlist entry in the database.

Parameters:
namestr

The name of the playlist.

seqint, optional

The sequence number of the playlist. If None, the new playlist entry will be added to the end of the parent playlist. Defaults to None.

parent_idint, optional

The ID of the parent playlist. Defaults to 0, which means the playlist is a top-level playlist.

image_idint, optional

The ID of the playlist image. Defaults to None, which means no image is set.

Returns:
models.Playlist

The newly created playlist object.

add_playlist_folder(name, seq=None, parent_id=0)[source]#

Create a new playlist folder entry in the database.

Parameters:
namestr

The name of the playlist.

seqint, optional

The sequence number of the playlist. If None, the new playlist entry will be added to the end of the parent playlist. Defaults to None.

parent_idint, optional

The ID of the parent playlist. Defaults to 0, which means the playlist is a top-level playlist.

Returns:
models.Playlist

The newly created playlist object.

add_playlist_content(playlist_id, content_id, seq=None)[source]#

Create a new playlist content entry in the database.

Parameters:
playlist_idint

The ID of the playlist associated with the content.

content_idint

The ID of the content associated with the playlist.

seqint, optional

The sequence number of the content in the playlist. If None, it will be set to the next available sequence number.

Returns:
models.PlaylistContent

The newly created playlist content object.

add_property(my_tag_master_dbid, device_name='', db_version=1000, background_color_type=0)[source]#

Create a new property entry in the database.

Parameters:
my_tag_master_dbidint

The MyTag master database ID.

device_namestr, optional

The device name of the property. Defaults to an empty string.

db_versionint, optional

The database version. Defaults to 1000.

background_color_typeint, optional

The background color type. Defaults to 0.

Returns:
models.Property

The newly created property object.

update_content_count()[source]#

Update the content count in the property table.

Create a new recommended like entry in the database.

Parameters:
content_id_1int

The ID of the first content.

content_id_2int

The ID of the second content.

ratingint

The rating of the recommendation.

Returns:
models.RecommendedLike

The newly created recommended like object.

add_sort(menu_item_id, seq, is_visible=True, is_selected_as_column=False)[source]#

Create a new sort entry in the database.

Parameters:
menu_item_idint

The ID of the menu item associated with the sort.

seqint

The sequence number of the sort.

is_visiblebool, optional

Flag indicating if the sort is visible. Defaults to True.

is_selected_as_columnbool, optional

The selected as sub-column flag of the sort entry. Defaults to False.

Returns:
models.Sort

The newly created sort object.

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.