@@ -114,19 +114,15 @@ def __init__(self, path=None, db_dir="", key="", unlock=True):
114
114
path = rb_config .get ("db_path" , "" )
115
115
if not path :
116
116
pdir = get_config ("pioneer" , "install_dir" )
117
- raise FileNotFoundError (
118
- f"No Rekordbox v6/v7 directory found in '{ pdir } '"
119
- )
117
+ raise FileNotFoundError (f"No Rekordbox v6/v7 directory found in '{ pdir } '" )
120
118
path = Path (path )
121
119
# make sure file exists
122
120
if not path .exists ():
123
121
raise FileNotFoundError (f"File '{ path } ' does not exist!" )
124
122
# Open database
125
123
if unlock :
126
124
if not _sqlcipher_available :
127
- raise ImportError (
128
- "Could not unlock database: 'sqlcipher3' package not found"
129
- )
125
+ raise ImportError ("Could not unlock database: 'sqlcipher3' package not found" )
130
126
if not key :
131
127
try :
132
128
key = rb_config ["dp" ]
@@ -727,9 +723,7 @@ def get_uuid_map(self, **kwargs):
727
723
728
724
# -- Database updates --------------------------------------------------------------
729
725
730
- def generate_unused_id (
731
- self , table , is_28_bit : bool = True , id_field_name : str = "ID"
732
- ) -> int :
726
+ def generate_unused_id (self , table , is_28_bit : bool = True , id_field_name : str = "ID" ) -> int :
733
727
"""Generates an unused ID for the given table."""
734
728
max_tries = 1000000
735
729
for _ in range (max_tries ):
@@ -804,20 +798,14 @@ def add_to_playlist(self, playlist, content, track_no=None):
804
798
uuid = str (uuid4 ())
805
799
id_ = str (uuid4 ())
806
800
now = datetime .datetime .now ()
807
- nsongs = (
808
- self .query (tables .DjmdSongPlaylist )
809
- .filter_by (PlaylistID = playlist .ID )
810
- .count ()
811
- )
801
+ nsongs = self .query (tables .DjmdSongPlaylist ).filter_by (PlaylistID = playlist .ID ).count ()
812
802
if track_no is not None :
813
803
insert_at_end = False
814
804
track_no = int (track_no )
815
805
if track_no < 1 :
816
806
raise ValueError ("Track number must be greater than 0" )
817
807
if track_no > nsongs + 1 :
818
- raise ValueError (
819
- f"Track number too high, parent contains { nsongs } items"
820
- )
808
+ raise ValueError (f"Track number too high, parent contains { nsongs } items" )
821
809
else :
822
810
insert_at_end = True
823
811
track_no = nsongs + 1
@@ -893,9 +881,7 @@ def remove_from_playlist(self, playlist, song):
893
881
playlist = self .get_playlist (ID = playlist )
894
882
if isinstance (song , (int , str )):
895
883
song = self .query (tables .DjmdSongPlaylist ).filter_by (ID = song ).one ()
896
- logger .info (
897
- "Removing song with ID=%s from playlist with ID=%s" , song .ID , playlist .ID
898
- )
884
+ logger .info ("Removing song with ID=%s from playlist with ID=%s" , song .ID , playlist .ID )
899
885
now = datetime .datetime .now ()
900
886
# Remove track from playlist
901
887
track_no = song .TrackNo
@@ -966,11 +952,7 @@ def move_song_in_playlist(self, playlist, song, new_track_no):
966
952
playlist = self .get_playlist (ID = playlist )
967
953
if isinstance (song , (int , str )):
968
954
song = self .query (tables .DjmdSongPlaylist ).filter_by (ID = song ).one ()
969
- nsongs = (
970
- self .query (tables .DjmdSongPlaylist )
971
- .filter_by (PlaylistID = playlist .ID )
972
- .count ()
973
- )
955
+ nsongs = self .query (tables .DjmdSongPlaylist ).filter_by (PlaylistID = playlist .ID ).count ()
974
956
if new_track_no < 1 :
975
957
raise ValueError ("Track number must be greater than 0" )
976
958
if new_track_no > nsongs + 1 :
@@ -1020,9 +1002,7 @@ def move_song_in_playlist(self, playlist, song, new_track_no):
1020
1002
self .registry .enable_tracking ()
1021
1003
self .registry .on_move (moved )
1022
1004
1023
- def _create_playlist (
1024
- self , name , seq , image_path , parent , smart_list = None , attribute = None
1025
- ):
1005
+ def _create_playlist (self , name , seq , image_path , parent , smart_list = None , attribute = None ):
1026
1006
"""Creates a new playlist object."""
1027
1007
table = tables .DjmdPlaylist
1028
1008
id_ = str (self .generate_unused_id (table , is_28_bit = True ))
@@ -1047,9 +1027,7 @@ def _create_playlist(
1047
1027
else :
1048
1028
# Check if parent exists and is a folder
1049
1029
parent_id = parent
1050
- query = self .query (table .ID ).filter (
1051
- table .ID == parent_id , table .Attribute == 1
1052
- )
1030
+ query = self .query (table .ID ).filter (table .ID == parent_id , table .Attribute == 1 )
1053
1031
if not self .query (query .exists ()).scalar ():
1054
1032
raise ValueError ("Parent does not exist or is not a folder" )
1055
1033
@@ -1108,9 +1086,7 @@ def _create_playlist(
1108
1086
1109
1087
# Update masterPlaylists6.xml
1110
1088
if self .playlist_xml is not None :
1111
- self .playlist_xml .add (
1112
- id_ , parent_id , attribute , now , lib_type = 0 , check_type = 0
1113
- )
1089
+ self .playlist_xml .add (id_ , parent_id , attribute , now , lib_type = 0 , check_type = 0 )
1114
1090
1115
1091
return playlist
1116
1092
@@ -1158,9 +1134,7 @@ def create_playlist(self, name, parent=None, seq=None, image_path=None):
1158
1134
'123456'
1159
1135
"""
1160
1136
logger .info ("Creating playlist %s" , name )
1161
- return self ._create_playlist (
1162
- name , seq , image_path , parent , attribute = PlaylistType .PLAYLIST
1163
- )
1137
+ return self ._create_playlist (name , seq , image_path , parent , attribute = PlaylistType .PLAYLIST )
1164
1138
1165
1139
def create_playlist_folder (self , name , parent = None , seq = None , image_path = None ):
1166
1140
"""Creates a new playlist folder in the database.
@@ -1200,9 +1174,7 @@ def create_playlist_folder(self, name, parent=None, seq=None, image_path=None):
1200
1174
'123456'
1201
1175
"""
1202
1176
logger .info ("Creating playlist folder %s" , name )
1203
- return self ._create_playlist (
1204
- name , seq , image_path , parent , attribute = PlaylistType .FOLDER
1205
- )
1177
+ return self ._create_playlist (name , seq , image_path , parent , attribute = PlaylistType .FOLDER )
1206
1178
1207
1179
def create_smart_playlist (
1208
1180
self , name , smart_list : SmartList , parent = None , seq = None , image_path = None
@@ -1277,9 +1249,7 @@ def delete_playlist(self, playlist):
1277
1249
playlist = self .get_playlist (ID = playlist )
1278
1250
1279
1251
if playlist .Attribute == 1 :
1280
- logger .info (
1281
- "Deleting playlist folder '%s' with ID=%s" , playlist .Name , playlist .ID
1282
- )
1252
+ logger .info ("Deleting playlist folder '%s' with ID=%s" , playlist .Name , playlist .ID )
1283
1253
else :
1284
1254
logger .info ("Deleting playlist '%s' with ID=%s" , playlist .Name , playlist .ID )
1285
1255
@@ -1392,9 +1362,7 @@ def move_playlist(self, playlist, parent=None, seq=None):
1392
1362
else :
1393
1363
# Check if parent exists and is a folder
1394
1364
parent_id = str (parent )
1395
- query = self .query (table .ID ).filter (
1396
- table .ID == parent_id , table .Attribute == 1
1397
- )
1365
+ query = self .query (table .ID ).filter (table .ID == parent_id , table .Attribute == 1 )
1398
1366
if not self .query (query .exists ()).scalar ():
1399
1367
raise ValueError ("Parent does not exist or is not a folder" )
1400
1368
@@ -1415,9 +1383,7 @@ def move_playlist(self, playlist, parent=None, seq=None):
1415
1383
if seq < 1 :
1416
1384
raise ValueError ("Sequence number must be greater than 0" )
1417
1385
elif seq > n + 1 :
1418
- raise ValueError (
1419
- f"Sequence number too high, parent contains { n } items"
1420
- )
1386
+ raise ValueError (f"Sequence number too high, parent contains { n } items" )
1421
1387
1422
1388
if not insert_at_end :
1423
1389
# Get all playlists with seq between old_seq and seq
@@ -1551,9 +1517,7 @@ def rename_playlist(self, playlist, name):
1551
1517
with self .registry .disabled ():
1552
1518
playlist .updated_at = now
1553
1519
1554
- def add_album (
1555
- self , name , artist = None , image_path = None , compilation = None , search_str = None
1556
- ):
1520
+ def add_album (self , name , artist = None , image_path = None , compilation = None , search_str = None ):
1557
1521
"""Adds a new album to the database.
1558
1522
1559
1523
Parameters
@@ -1685,9 +1649,7 @@ def add_artist(self, name, search_str=None):
1685
1649
1686
1650
id_ = self .generate_unused_id (tables .DjmdArtist )
1687
1651
uuid = str (uuid4 ())
1688
- artist = tables .DjmdArtist .create (
1689
- ID = id_ , Name = name , SearchStr = search_str , UUID = uuid
1690
- )
1652
+ artist = tables .DjmdArtist .create (ID = id_ , Name = name , SearchStr = search_str , UUID = uuid )
1691
1653
self .add (artist )
1692
1654
self .flush ()
1693
1655
return artist
@@ -1829,9 +1791,7 @@ def add_content(self, path, **kwargs):
1829
1791
raise ValueError (f"Track with path '{ path } ' already exists in database" )
1830
1792
1831
1793
id_ = self .generate_unused_id (tables .DjmdContent )
1832
- file_id = self .generate_unused_id (
1833
- tables .DjmdContent , id_field_name = "rb_file_id"
1834
- )
1794
+ file_id = self .generate_unused_id (tables .DjmdContent , id_field_name = "rb_file_id" )
1835
1795
uuid = str (uuid4 ())
1836
1796
content_link = self .get_menu_items (Name = "TRACK" ).one ()
1837
1797
date_created = datetime .date .today ()
@@ -1988,9 +1948,7 @@ def read_anlz_file(self, content, type_):
1988
1948
return AnlzFile .parse_file (path )
1989
1949
return None
1990
1950
1991
- def update_content_path (
1992
- self , content , path , save = True , check_path = True , commit = True
1993
- ):
1951
+ def update_content_path (self , content , path , save = True , check_path = True , commit = True ):
1994
1952
"""Update the file path of a track in the Rekordbox v6 database.
1995
1953
1996
1954
This changes the `FolderPath` entry in the ``DjmdContent`` table and the
@@ -2081,9 +2039,7 @@ def update_content_path(
2081
2039
logger .debug ("Committing changes to the database" )
2082
2040
self .commit ()
2083
2041
2084
- def update_content_filename (
2085
- self , content , name , save = True , check_path = True , commit = True
2086
- ):
2042
+ def update_content_filename (self , content , name , save = True , check_path = True , commit = True ):
2087
2043
"""Update the file name of a track in the Rekordbox v6 database.
2088
2044
2089
2045
This changes the `FolderPath` entry in the ``DjmdContent`` table and the
0 commit comments