Skip to content

Commit

Permalink
fix: improve error handling for incompatible RB versions (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanljones committed Feb 27, 2023
1 parent 5d3da0f commit 2019ecd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
17 changes: 9 additions & 8 deletions pyrekordbox/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,21 @@ def _get_rb6_config(pioneer_prog_dir: str, pioneer_app_dir: str):
if not os.path.exists(db_path):
raise FileNotFoundError(f"The Rekordbox database '{db_path}' doesn't exist!")

conf["db_path"] = db_path
# Read password from app.asar, see
# https://www.reddit.com/r/Rekordbox/comments/qou6nm/key_to_open_masterdb_file/
asar_data = read_rekordbox6_asar(conf["install_dir"])
match_result = re.search('pass: ".(.*?)"', asar_data)
if match_result is None:
raise ValueError("Incompatible rekordbox 6 database ignored.")
match = match_result.group(0)
pw = match.replace("pass: ", "").strip('"')
logging.warning("Incompatible rekordbox 6 database: Could not retrieve db-key.")
else:
match = match_result.group(0)
pw = match.replace("pass: ", "").strip('"')
cipher = blowfish.Cipher(pw.encode())
dp = base64.standard_b64decode(opts["dp"])
dp = b"".join(cipher.decrypt_ecb(dp)).decode()
conf["dp"] = dp

cipher = blowfish.Cipher(pw.encode())
dp = base64.standard_b64decode(opts["dp"])
dp = b"".join(cipher.decrypt_ecb(dp)).decode()

conf.update({"db_path": db_path, "dp": dp})
return conf


Expand Down
10 changes: 8 additions & 2 deletions pyrekordbox/db6/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ def open_rekordbox_database(path="", unlock=True, sql_driver=None):

if unlock:
# Read and decode master.db key
key = rb6_config["dp"]
try:
key = rb6_config["dp"]
except KeyError:
raise ValueError("Incompatible rekordbox 6 database: No key found")
logger.info("Key: %s", key)
# Unlock database
con.execute(f"PRAGMA key='{key}'")
Expand Down Expand Up @@ -160,7 +163,10 @@ def __init__(self, path="", unlock=True):
raise FileNotFoundError(f"File '{path}' does not exist!")
# Open database
if unlock:
key = rb6_config["dp"]
try:
key = rb6_config["dp"]
except KeyError:
raise ValueError("Incompatible rekordbox 6 database: No key found")
url = f"sqlite+pysqlcipher://:{key}@/{path}?"
engine = create_engine(url, module=sqlite3)
else:
Expand Down

0 comments on commit 2019ecd

Please sign in to comment.