58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
"""Parse two .pdb files with the kaitai schema and summarise differences."""
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent / "src"))
|
|
from io import BytesIO
|
|
from kaitaistruct import KaitaiStream
|
|
from kaitai.rekordbox_pdb import RekordboxPdb
|
|
|
|
|
|
PAGE_TYPE_NAMES = {t.value: t.name for t in RekordboxPdb.PageType}
|
|
|
|
|
|
def summarise(path: Path):
|
|
data = path.read_bytes()
|
|
pdb = RekordboxPdb(is_ext=False, _io=KaitaiStream(BytesIO(data)))
|
|
print(f"\n=== {path} ({path.stat().st_size} bytes) ===")
|
|
print(f"page_size={pdb.len_page} num_tables={pdb.num_tables} next_unused_page={pdb.next_unused_page} sequence={pdb.sequence}")
|
|
for tbl in pdb.tables:
|
|
ptype = PAGE_TYPE_NAMES.get(tbl.type.value, str(tbl.type))
|
|
page_count = 0
|
|
row_count = 0
|
|
err = None
|
|
try:
|
|
ref = tbl.first_page
|
|
while True:
|
|
page = ref.body
|
|
page_count += 1
|
|
if page.is_data_page:
|
|
for rg in page.row_groups:
|
|
for rpw in rg.rows:
|
|
if rpw.present:
|
|
row_count += 1
|
|
if ref.index == tbl.last_page.index:
|
|
break
|
|
ref = page.next_page
|
|
if page_count > 5000:
|
|
break
|
|
except Exception as e:
|
|
err = f"{type(e).__name__}: {e}"
|
|
line = f" {ptype:24s} first={tbl.first_page.index:>4} last={tbl.last_page.index:>4} pages={page_count:>3} rows={row_count}"
|
|
if err:
|
|
line += f" ERR={err}"
|
|
print(line)
|
|
return pdb
|
|
|
|
|
|
def main():
|
|
base = Path(__file__).parent
|
|
ref = base / "data/MAPLE/PIONEER/rekordbox/export.pdb"
|
|
ours = base / "data/usb/PIONEER/rekordbox/export.pdb"
|
|
summarise(ref)
|
|
summarise(ours)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|