Stored Data Integration

Hello everyone,

I am currently trying to automize my GFX workflow for an upcoming sports broadcast event.
I have tested CasparCG and really like it! Thank you for this awesome tool!
Sadly I am facing an issue with the Stored Data.
I have managed to get my data from an API into a .json format and send over automatically to CasparCG. - Great job me!

The server receives the data correctly and sends me:

[2024-12-12 13:02:19.140] [info] Received message from 127.0.0.1: DATA STORE currentDriver.json {“startnumber”: “1”, “firstname”: “George”, “lastname”: “Hemingway”, “nation”: “GBR”, “bike”: “Beta”, “age”: 16, “year”: 2008, “currentDriver”: true}\r\n

Now I have created a new template, as I usualy do with Loopic. With the Keys: startnumber, firstname, …

You can find the template here:

I can also see the data coming into my Client Tool Bar under stored data.
By draging and dropping it on my template it filles out the f0 (Key) - “Name of the data package” (Value) and adds the checkmark “Use stored data”.

But my data is not linked automaticly. - Can anyone help me with that? Did anyone manage to get a working workflow for the API - Stored Data - Template style?

I have also tried to use different Keys: f0, f1, age, .age

Thank you very much in advance for the assistance!

I think, that maybe something went wrong with the storage of the data, as the DATA STORE command would maybe need to have some escapes for the " and stuff. Have you tried to look at the file stored in CasparCG? There is a folder, usually called “data” that contains a file for each dataset stored. In your case it might be called “currentDriver.json.ftd” (Dataset names usually do not contain an extension, like .json). Open this file and look, what it contains and if that is a valid json.

Thank you for the quick reply!

That could very well be the issue. I took a look at the .json.ftd file and it only says:
{startnumber

I kind of ignored it, since I got the reply from the server.

So you say, that the format of:

{
“startnumber”: “1”,[…]

is wrong and probably needs to be something like:

{
“startnumber” : “1” ,[…]

I will fiddle around with it and will keep you updated!

See here and scroll down to “special sequences”. So the command you send to Caspar should read {\"startnumber\": \"1\", [...] to make it work. It will then write a valid json into the dataset.

Thank you very much, with your help I have managed to get the right data stored!

Thank you so much!

For anyone needing help, here is my file for sending over the .json file to the CasparCG Client:

import json
import os
import socket

# CasparCG Server IP und Port
CASPAR_HOST = "localhost"
CASPAR_PORT = 5250

# Pfad zum DATA-Ordner
DATA_FOLDER = "C:\\Users\\[USER]\\DATA"

def send_to_casparcg(command):
    """Sende Befehle an den CasparCG-Server"""
    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
        sock.connect((CASPAR_HOST, CASPAR_PORT))
        sock.sendall(command.encode('utf-8') + b'\r\n')
        response = sock.recv(4096).decode('utf-8')
        print(response)

def load_json_files(folder):
    """Lese alle JSON-Dateien im Ordner"""
    data_files = [f for f in os.listdir(folder) if f.endswith('.json')]
    stored_data = {}
    for file_name in data_files:
        file_path = os.path.join(folder, file_name)
        with open(file_path, 'r', encoding='utf-8') as f:
            try:
                data = json.load(f)
                stored_data[file_name] = data
            except json.JSONDecodeError:
                print(f"Fehler beim Lesen von {file_name}")
    return stored_data

def format_json_for_caspar(data):
    """Konvertiere JSON-Daten in das benötigte CasparCG-Format"""
    return json.dumps(data).replace('"', '\\"')

def update_stored_data(stored_data):
    """Daten als Stored Data zu CasparCG hinzufügen"""
    for key, data in stored_data.items():
        # Konvertiere die Daten in den erforderlichen CasparCG-String
        formatted_data = format_json_for_caspar(data)
        # Generiere den Befehl für DATA STORE
        command = f"DATA STORE {key} \"{formatted_data}\""
        # Sende den Befehl an CasparCG
        send_to_casparcg(command)

# Hauptprogramm
if __name__ == "__main__":
    # Lade alle JSON-Dateien aus dem angegebenen Ordner
    data = load_json_files(DATA_FOLDER)
    if data:
        # Aktualisiere die Daten im CasparCG Data Store
        update_stored_data(data)
    else:
        print("Keine JSON-Dateien gefunden.")