Verified Commit 6840a57e authored by Jakob Moser's avatar Jakob Moser
Browse files

Implement JSONification

parent 2c555ba8
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
# Karaokatalog

Tools to manage an Ultrastar DX song library. Features include:
Tools to manage an UltraStar DX song library. Features include:

1. Deduplication
2. Organization
3. Recoding
4. Jsonification

## Setup

@@ -55,3 +56,13 @@ python3 -m karaokatalog.organize $SONG_LIBRARY
```bash
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
```
+0 −0

Empty file added.

+30 −0
Original line number Diff line number Diff line
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")