67 lines
2.1 KiB
Python
67 lines
2.1 KiB
Python
"""Generate a disposable, synthetic Serato library from the sample manifest."""
|
|
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
from typing import Optional
|
|
|
|
|
|
SAMPLE_ROOT = Path(__file__).parent
|
|
SERATO_PATH_PREFIX = "Users/sample-user/OneDrive/Jukebox/"
|
|
|
|
|
|
def load_manifest() -> dict:
|
|
return json.loads((SAMPLE_ROOT / "manifest.json").read_text(encoding="utf-8"))
|
|
|
|
|
|
def build_sample(output: Optional[Path] = None) -> Path:
|
|
root = output or SAMPLE_ROOT / "generated"
|
|
manifest = load_manifest()
|
|
music_root = root / "Music"
|
|
serato_root = root / "Serato" / "_Serato_"
|
|
|
|
for relative_path in manifest["tracks"]:
|
|
track_path = music_root / relative_path
|
|
track_path.parent.mkdir(parents=True, exist_ok=True)
|
|
track_path.write_bytes(
|
|
f"Synthetic Serato Doctor fixture: {relative_path}\n".encode("utf-8")
|
|
)
|
|
|
|
for crate in manifest["crates"]:
|
|
is_smart = crate["type"] == "smart"
|
|
folder_name = "SmartCrates" if is_smart else "Subcrates"
|
|
crate_root = serato_root / folder_name
|
|
crate_root.mkdir(parents=True, exist_ok=True)
|
|
output_name = (
|
|
Path(crate["name"]).with_suffix(".scrate").name
|
|
if is_smart
|
|
else crate["name"]
|
|
)
|
|
for other_folder in ("Subcrates", "Smartcrates", "SmartCrates"):
|
|
for stale_name in (
|
|
crate["name"],
|
|
Path(crate["name"]).with_suffix(".scrate").name,
|
|
):
|
|
stale_path = serato_root / other_folder / stale_name
|
|
if stale_path.exists() and stale_path != crate_root / output_name:
|
|
stale_path.unlink()
|
|
records = "".join(
|
|
f"{SERATO_PATH_PREFIX}{relative_path}otrk"
|
|
for relative_path in crate["references"]
|
|
)
|
|
(crate_root / output_name).write_bytes(records.encode("utf-16-le"))
|
|
|
|
return root
|
|
|
|
|
|
def main() -> None:
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--output", type=Path)
|
|
args = parser.parse_args()
|
|
root = build_sample(args.output)
|
|
print(f"Generated synthetic library: {root}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|