Push 0.10.0

This commit is contained in:
Oracle 2026-05-18 16:31:58 +02:00
parent 266f3fc76d
commit 12c05afa57
Signed by: Oracle
SSH key fingerprint: SHA256:x4/RtnjUyuHkdvmwNDsWSfcfF1V5PNr3OpriZqOvCX8
25 changed files with 2016 additions and 645 deletions

View file

@ -2,7 +2,7 @@
# -*- coding: utf8 -*-
# libray - Libre Blu-Ray PS3 ISO Tool
# Copyright © 2018 - 2021 Nichlas Severinsen
# Copyright © 2018 - 2024 Nichlas Severinsen
#
# This file is part of libray.
#
@ -21,28 +21,54 @@
# This script transforms Datfile.dat and keys/*.key keyfiles into a sqlite3 keys.db
# Keys.db is then moved to libray/data/keys.db and packaged with libray in setup.py.
# Libray checks if this file is bundled with it and checks if it has a key for the .iso using a crc32 of it.
# Libray checks if this file is bundled with it and has logic to identify the correct key.
# TODO: In theory we could add the game-serials (BLUS-0000) and check that first.
import bs4
import csv
import sys
import shutil
import sqlite3
import pathlib
import argparse
import requests
if __name__ == '__main__':
db_path = pathlib.Path('keys.db')
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--database', type=pathlib.Path, default='keys.db', help='Path to keys.db')
parser.add_argument('-k', '--keys', type=pathlib.Path, default='keys', help='Path to .key keys')
parser.add_argument('--show-missing', action='store_true', help='Show titles missing keys')
args = parser.parse_args()
if db_path.exists():
db_path.unlink()
if args.database.exists():
args.database.unlink()
db = sqlite3.connect(db_path)
# Check if there's a mapping csv that maps the keynames to title IDs
mapping = pathlib.Path('keys.csv')
title_ids = {}
if mapping.exists():
with open(mapping, 'r') as infile:
reader = csv.DictReader(infile, delimiter=',', quotechar='"', )
for row in reader:
title_ids[row['md5']] = {
'title_id': row['title_id'],
'filename': row['filename'],
'size': row['size'],
'crc32': row['crc32'],
}
db = sqlite3.connect(args.database)
c = db.cursor()
c.execute('CREATE TABLE games (name TEXT, size TEXT, crc32 TEXT, md5 TEXT, sha1 TEXT, key BLOB)')
c.execute('CREATE TABLE games (title_id TEXT, name TEXT, size TEXT, crc32 TEXT, md5 TEXT, sha1 TEXT, key BLOB)')
db.commit()
cwd = pathlib.Path(__file__).resolve().parent
@ -72,17 +98,36 @@ if __name__ == '__main__':
name = game.find('description').text.strip()
attrs = game.find('rom').attrs
entry = [name, attrs['size'], attrs['crc'], attrs['md5'], attrs['sha1']]
try:
title_map = title_ids[attrs['md5']]
assert title_map['size'] == attrs['size']
assert title_map['crc32'] == attrs['crc']
title_id = title_map['title_id']
except (KeyError, AssertionError):
title_id = None
# Some of the records are spaces:
if not title_id:
title_id = None
entry = [title_id, name, attrs['size'], attrs['crc'], attrs['md5'], attrs['sha1']]
try:
with open(cwd / ('keys/' + name + '.key'), 'rb') as keyfile:
entry.append(keyfile.read())
except FileNotFoundError:
warnings += 1
c.execute('INSERT INTO games (name, size, crc32, md5, sha1) VALUES (?, ?, ?, ?, ?)', entry)
if args.show_missing:
print('Warning: missing keyfile for %s [%s]' % (name, attrs['crc']))
c.execute('INSERT INTO games (title_id, name, size, crc32, md5, sha1) VALUES (?, ?, ?, ?, ?, ?)', entry)
continue
c.execute('INSERT INTO games VALUES (?, ?, ?, ?, ?, ?)', entry)
c.execute('INSERT INTO games VALUES (?, ?, ?, ?, ?, ?, ?)', entry)
db.commit()
@ -93,7 +138,7 @@ if __name__ == '__main__':
if not data_path.exists():
data_path.mkdir()
shutil.copyfile(db_path, ((cwd.parent / 'libray') / 'data/') / db_path.name)
shutil.copyfile(args.database, ((cwd.parent / 'libray') / 'data/') / args.database.name)
print('Warning: no keyfiles for %s titles' % str(warnings))