Implement JSONification

This commit is contained in:
Jakob Moser 2025-06-20 19:54:55 +02:00
parent 2c555ba8e0
commit 6840a57e0b
Signed by: jakob
GPG Key ID: 3EF2BA2851B3F53C
3 changed files with 42 additions and 1 deletions

View File

@ -1,10 +1,11 @@
# Karaokatalog # Karaokatalog
Tools to manage an Ultrastar DX song library. Features include: Tools to manage an UltraStar DX song library. Features include:
1. Deduplication 1. Deduplication
2. Organization 2. Organization
3. Recoding 3. Recoding
4. Jsonification
## Setup ## Setup
@ -55,3 +56,13 @@ python3 -m karaokatalog.organize $SONG_LIBRARY
```bash ```bash
python3 -m karaokatalog.recode $SONG_LIBRARY python3 -m karaokatalog.recode $SONG_LIBRARY
``` ```
### Jsonification
**Create a `songs.json` file with some song metadata in the root library dir.**
This operation is risk-free: If a `songs.json` already exists, it is kept intact (so no data loss possible).
```bash
python3 -m karaokatalog.jsonify $SONG_LIBRARY
```

View File

View File

@ -0,0 +1,30 @@
import json
import logging
from karaokatalog.get_parser import get_parser
from karaokatalog.Library import Library
logging.basicConfig(
format="%(asctime)s [%(levelname)s] %(message)s", level=logging.INFO
)
if __name__ == "__main__":
args = get_parser(
"jsonify", "Create a JSON file containing metadata of all songs in the library"
).parse_args()
logging.info("Karaokatalog Jsonification started")
logging.info("Loading library")
library = Library.from_dir(args.library_path)
logging.info("Library loaded")
songs = [song.as_dict() for song in library.songs]
json_path = args.library_path / "songs.json"
logging.info(f"Writing JSON to {json_path}")
with json_path.open("x", encoding="utf-8") as f:
json.dump(songs, f, ensure_ascii=False, indent=4)
logging.info("Karaokatalog Jsonification done")