Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-commit.ci] pre-commit autoupdate #150

Merged
merged 2 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:
- id: check-yaml

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.9
rev: v0.9.10
hooks:
# Run the linter.
- id: ruff
Expand Down
20 changes: 5 additions & 15 deletions pyrekordbox/anlz/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,9 @@ def set(self, beats, bpms, times):
n_bpms = len(bpms)
n_times = len(times)
if n_bpms != n_beats:
raise ValueError(
f"Number of bpms not equal to number of beats: {n_bpms} != {n_beats}"
)
raise ValueError(f"Number of bpms not equal to number of beats: {n_bpms} != {n_beats}")
if n_times != n_beats:
raise ValueError(
f"Number of times not equal to number of beats: {n_bpms} != {n_times}"
)
raise ValueError(f"Number of times not equal to number of beats: {n_bpms} != {n_times}")

# For now only values of existing beats can be set
if n_beats != n:
Expand All @@ -184,9 +180,7 @@ def set_beats(self, beats):
n = len(self.content.entries)
n_new = len(beats)
if n_new != n:
raise ValueError(
f"Number of beats not equal to current content length: {n_new} != {n}"
)
raise ValueError(f"Number of beats not equal to current content length: {n_new} != {n}")

for i, beat in enumerate(beats):
self.content.entries[i].beat = beat
Expand All @@ -195,9 +189,7 @@ def set_bpms(self, bpms):
n = len(self.content.entries)
n_new = len(bpms)
if n_new != n:
raise ValueError(
f"Number of bpms not equal to current content length: {n_new} != {n}"
)
raise ValueError(f"Number of bpms not equal to current content length: {n_new} != {n}")

for i, bpm in enumerate(bpms):
self.content.entries[i].tempo = int(bpm * 100)
Expand All @@ -206,9 +198,7 @@ def set_times(self, times):
n = len(self.content.entries)
n_new = len(times)
if n_new != n:
raise ValueError(
f"Number of times not equal to current content length: {n_new} != {n}"
)
raise ValueError(f"Number of times not equal to current content length: {n_new} != {n}")

for i, t in enumerate(times):
self.content.entries[i].time = int(1000 * t)
Expand Down
34 changes: 8 additions & 26 deletions pyrekordbox/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,7 @@ def read_rekordbox6_asar(rb6_install_dir: Union[str, Path]) -> str:
if not str(rb6_install_dir).endswith(".app"):
rb6_install_dir = rb6_install_dir / "rekordbox.app"
location = (
rb6_install_dir
/ "Contents"
/ "MacOS"
/ "rekordboxAgent.app"
/ "Contents"
/ "Resources"
rb6_install_dir / "Contents" / "MacOS" / "rekordboxAgent.app" / "Contents" / "Resources"
)
encoding = "cp437"
else:
Expand Down Expand Up @@ -360,9 +355,7 @@ def _get_rb_config(
return conf


def _get_rb5_config(
pioneer_prog_dir: Path, pioneer_app_dir: Path, dirname: str = ""
) -> dict:
def _get_rb5_config(pioneer_prog_dir: Path, pioneer_app_dir: Path, dirname: str = "") -> dict:
"""Get the program configuration for Rekordbox v5.x.x."""
major_version = 5
conf = _get_rb_config(pioneer_prog_dir, pioneer_app_dir, major_version, dirname)
Expand Down Expand Up @@ -414,8 +407,7 @@ def run(self):
pid = get_rekordbox_pid()
if pid:
raise RuntimeError(
"Rekordbox is running. "
"Please close Rekordbox before running the `KeyExtractor`."
"Rekordbox is running. Please close Rekordbox before running the `KeyExtractor`."
)
# Spawn Rekordbox process and attach to it
pid = frida.spawn(self.executable)
Expand Down Expand Up @@ -551,9 +543,7 @@ def _update_sqlite_key(opts, conf):
conf["dp"] = dp


def _get_rb6_config(
pioneer_prog_dir: Path, pioneer_app_dir: Path, dirname: str = ""
) -> dict:
def _get_rb6_config(pioneer_prog_dir: Path, pioneer_app_dir: Path, dirname: str = "") -> dict:
"""Get the program configuration for Rekordbox v6.x.x."""
major_version = 6
conf = _get_rb_config(pioneer_prog_dir, pioneer_app_dir, major_version, dirname)
Expand All @@ -571,9 +561,7 @@ def _get_rb6_config(
return conf


def _get_rb7_config(
pioneer_prog_dir: Path, pioneer_app_dir: Path, dirname: str = ""
) -> dict:
def _get_rb7_config(pioneer_prog_dir: Path, pioneer_app_dir: Path, dirname: str = "") -> dict:
"""Get the program configuration for Rekordbox v7.x.x."""
major_version = 7
conf = _get_rb_config(pioneer_prog_dir, pioneer_app_dir, major_version, dirname)
Expand Down Expand Up @@ -715,27 +703,21 @@ def update_config(

# Update Rekordbox 5 config
try:
conf = _get_rb5_config(
pioneer_install_dir, pioneer_app_dir, rb5_install_dirname
)
conf = _get_rb5_config(pioneer_install_dir, pioneer_app_dir, rb5_install_dirname)
__config__["rekordbox5"].update(conf)
except FileNotFoundError as e:
logger.info(e)

# Update Rekordbox 6 config
try:
conf = _get_rb6_config(
pioneer_install_dir, pioneer_app_dir, rb6_install_dirname
)
conf = _get_rb6_config(pioneer_install_dir, pioneer_app_dir, rb6_install_dirname)
__config__["rekordbox6"].update(conf)
except FileNotFoundError as e:
logger.info(e)

# Update Rekordbox 7 config
try:
conf = _get_rb7_config(
pioneer_install_dir, pioneer_app_dir, rb7_install_dirname
)
conf = _get_rb7_config(pioneer_install_dir, pioneer_app_dir, rb7_install_dirname)
__config__["rekordbox7"].update(conf)
except FileNotFoundError as e:
logger.info(e)
Expand Down
84 changes: 20 additions & 64 deletions pyrekordbox/db6/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,15 @@ def __init__(self, path=None, db_dir="", key="", unlock=True):
path = rb_config.get("db_path", "")
if not path:
pdir = get_config("pioneer", "install_dir")
raise FileNotFoundError(
f"No Rekordbox v6/v7 directory found in '{pdir}'"
)
raise FileNotFoundError(f"No Rekordbox v6/v7 directory found in '{pdir}'")
path = Path(path)
# make sure file exists
if not path.exists():
raise FileNotFoundError(f"File '{path}' does not exist!")
# Open database
if unlock:
if not _sqlcipher_available:
raise ImportError(
"Could not unlock database: 'sqlcipher3' package not found"
)
raise ImportError("Could not unlock database: 'sqlcipher3' package not found")
if not key:
try:
key = rb_config["dp"]
Expand Down Expand Up @@ -727,9 +723,7 @@ def get_uuid_map(self, **kwargs):

# -- Database updates --------------------------------------------------------------

def generate_unused_id(
self, table, is_28_bit: bool = True, id_field_name: str = "ID"
) -> int:
def generate_unused_id(self, table, is_28_bit: bool = True, id_field_name: str = "ID") -> int:
"""Generates an unused ID for the given table."""
max_tries = 1000000
for _ in range(max_tries):
Expand Down Expand Up @@ -804,20 +798,14 @@ def add_to_playlist(self, playlist, content, track_no=None):
uuid = str(uuid4())
id_ = str(uuid4())
now = datetime.datetime.now()
nsongs = (
self.query(tables.DjmdSongPlaylist)
.filter_by(PlaylistID=playlist.ID)
.count()
)
nsongs = self.query(tables.DjmdSongPlaylist).filter_by(PlaylistID=playlist.ID).count()
if track_no is not None:
insert_at_end = False
track_no = int(track_no)
if track_no < 1:
raise ValueError("Track number must be greater than 0")
if track_no > nsongs + 1:
raise ValueError(
f"Track number too high, parent contains {nsongs} items"
)
raise ValueError(f"Track number too high, parent contains {nsongs} items")
else:
insert_at_end = True
track_no = nsongs + 1
Expand Down Expand Up @@ -893,9 +881,7 @@ def remove_from_playlist(self, playlist, song):
playlist = self.get_playlist(ID=playlist)
if isinstance(song, (int, str)):
song = self.query(tables.DjmdSongPlaylist).filter_by(ID=song).one()
logger.info(
"Removing song with ID=%s from playlist with ID=%s", song.ID, playlist.ID
)
logger.info("Removing song with ID=%s from playlist with ID=%s", song.ID, playlist.ID)
now = datetime.datetime.now()
# Remove track from playlist
track_no = song.TrackNo
Expand Down Expand Up @@ -966,11 +952,7 @@ def move_song_in_playlist(self, playlist, song, new_track_no):
playlist = self.get_playlist(ID=playlist)
if isinstance(song, (int, str)):
song = self.query(tables.DjmdSongPlaylist).filter_by(ID=song).one()
nsongs = (
self.query(tables.DjmdSongPlaylist)
.filter_by(PlaylistID=playlist.ID)
.count()
)
nsongs = self.query(tables.DjmdSongPlaylist).filter_by(PlaylistID=playlist.ID).count()
if new_track_no < 1:
raise ValueError("Track number must be greater than 0")
if new_track_no > nsongs + 1:
Expand Down Expand Up @@ -1020,9 +1002,7 @@ def move_song_in_playlist(self, playlist, song, new_track_no):
self.registry.enable_tracking()
self.registry.on_move(moved)

def _create_playlist(
self, name, seq, image_path, parent, smart_list=None, attribute=None
):
def _create_playlist(self, name, seq, image_path, parent, smart_list=None, attribute=None):
"""Creates a new playlist object."""
table = tables.DjmdPlaylist
id_ = str(self.generate_unused_id(table, is_28_bit=True))
Expand All @@ -1047,9 +1027,7 @@ def _create_playlist(
else:
# Check if parent exists and is a folder
parent_id = parent
query = self.query(table.ID).filter(
table.ID == parent_id, table.Attribute == 1
)
query = self.query(table.ID).filter(table.ID == parent_id, table.Attribute == 1)
if not self.query(query.exists()).scalar():
raise ValueError("Parent does not exist or is not a folder")

Expand Down Expand Up @@ -1108,9 +1086,7 @@ def _create_playlist(

# Update masterPlaylists6.xml
if self.playlist_xml is not None:
self.playlist_xml.add(
id_, parent_id, attribute, now, lib_type=0, check_type=0
)
self.playlist_xml.add(id_, parent_id, attribute, now, lib_type=0, check_type=0)

return playlist

Expand Down Expand Up @@ -1158,9 +1134,7 @@ def create_playlist(self, name, parent=None, seq=None, image_path=None):
'123456'
"""
logger.info("Creating playlist %s", name)
return self._create_playlist(
name, seq, image_path, parent, attribute=PlaylistType.PLAYLIST
)
return self._create_playlist(name, seq, image_path, parent, attribute=PlaylistType.PLAYLIST)

def create_playlist_folder(self, name, parent=None, seq=None, image_path=None):
"""Creates a new playlist folder in the database.
Expand Down Expand Up @@ -1200,9 +1174,7 @@ def create_playlist_folder(self, name, parent=None, seq=None, image_path=None):
'123456'
"""
logger.info("Creating playlist folder %s", name)
return self._create_playlist(
name, seq, image_path, parent, attribute=PlaylistType.FOLDER
)
return self._create_playlist(name, seq, image_path, parent, attribute=PlaylistType.FOLDER)

def create_smart_playlist(
self, name, smart_list: SmartList, parent=None, seq=None, image_path=None
Expand Down Expand Up @@ -1277,9 +1249,7 @@ def delete_playlist(self, playlist):
playlist = self.get_playlist(ID=playlist)

if playlist.Attribute == 1:
logger.info(
"Deleting playlist folder '%s' with ID=%s", playlist.Name, playlist.ID
)
logger.info("Deleting playlist folder '%s' with ID=%s", playlist.Name, playlist.ID)
else:
logger.info("Deleting playlist '%s' with ID=%s", playlist.Name, playlist.ID)

Expand Down Expand Up @@ -1392,9 +1362,7 @@ def move_playlist(self, playlist, parent=None, seq=None):
else:
# Check if parent exists and is a folder
parent_id = str(parent)
query = self.query(table.ID).filter(
table.ID == parent_id, table.Attribute == 1
)
query = self.query(table.ID).filter(table.ID == parent_id, table.Attribute == 1)
if not self.query(query.exists()).scalar():
raise ValueError("Parent does not exist or is not a folder")

Expand All @@ -1415,9 +1383,7 @@ def move_playlist(self, playlist, parent=None, seq=None):
if seq < 1:
raise ValueError("Sequence number must be greater than 0")
elif seq > n + 1:
raise ValueError(
f"Sequence number too high, parent contains {n} items"
)
raise ValueError(f"Sequence number too high, parent contains {n} items")

if not insert_at_end:
# Get all playlists with seq between old_seq and seq
Expand Down Expand Up @@ -1551,9 +1517,7 @@ def rename_playlist(self, playlist, name):
with self.registry.disabled():
playlist.updated_at = now

def add_album(
self, name, artist=None, image_path=None, compilation=None, search_str=None
):
def add_album(self, name, artist=None, image_path=None, compilation=None, search_str=None):
"""Adds a new album to the database.

Parameters
Expand Down Expand Up @@ -1685,9 +1649,7 @@ def add_artist(self, name, search_str=None):

id_ = self.generate_unused_id(tables.DjmdArtist)
uuid = str(uuid4())
artist = tables.DjmdArtist.create(
ID=id_, Name=name, SearchStr=search_str, UUID=uuid
)
artist = tables.DjmdArtist.create(ID=id_, Name=name, SearchStr=search_str, UUID=uuid)
self.add(artist)
self.flush()
return artist
Expand Down Expand Up @@ -1829,9 +1791,7 @@ def add_content(self, path, **kwargs):
raise ValueError(f"Track with path '{path}' already exists in database")

id_ = self.generate_unused_id(tables.DjmdContent)
file_id = self.generate_unused_id(
tables.DjmdContent, id_field_name="rb_file_id"
)
file_id = self.generate_unused_id(tables.DjmdContent, id_field_name="rb_file_id")
uuid = str(uuid4())
content_link = self.get_menu_items(Name="TRACK").one()
date_created = datetime.date.today()
Expand Down Expand Up @@ -1988,9 +1948,7 @@ def read_anlz_file(self, content, type_):
return AnlzFile.parse_file(path)
return None

def update_content_path(
self, content, path, save=True, check_path=True, commit=True
):
def update_content_path(self, content, path, save=True, check_path=True, commit=True):
"""Update the file path of a track in the Rekordbox v6 database.

This changes the `FolderPath` entry in the ``DjmdContent`` table and the
Expand Down Expand Up @@ -2081,9 +2039,7 @@ def update_content_path(
logger.debug("Committing changes to the database")
self.commit()

def update_content_filename(
self, content, name, save=True, check_path=True, commit=True
):
def update_content_filename(self, content, name, save=True, check_path=True, commit=True):
"""Update the file name of a track in the Rekordbox v6 database.

This changes the `FolderPath` entry in the ``DjmdContent`` table and the
Expand Down
7 changes: 2 additions & 5 deletions pyrekordbox/db6/smartlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ class Condition:
def __post_init__(self):
if self.property not in PROPERTIES:
raise ValueError(
f"Invalid property: '{self.property}'! "
f"Supported properties: {PROPERTIES}"
f"Invalid property: '{self.property}'! Supported properties: {PROPERTIES}"
)

valid_ops = VALID_OPS[self.property]
Expand Down Expand Up @@ -232,9 +231,7 @@ def _get_condition_values(cond):
class SmartList:
"""Rekordbox smart playlist XML handler."""

def __init__(
self, logical_operator: int = LogicalOperator.ALL, auto_update: int = 0
):
def __init__(self, logical_operator: int = LogicalOperator.ALL, auto_update: int = 0):
self.playlist_id: Union[int, str] = ""
self.logical_operator: int = int(logical_operator)
self.auto_update: int = auto_update
Expand Down
Loading
Loading