API usage examples

    Counting the number of hls/http sessions:

    curl -s -X POST -d '{ "cmd": "sessions" }' \
    http://login:pass@tv.server.ip:port/control/|grep client_id|wc -l
    

    Switching input:
    (For example , turning off the channel with erotic content in the daytime)

    curl -X POST -d '{"cmd":"set-stream-input", \
    "id":"a006","input":2}'  http://login:pass@tv.server.ip:port/control/         
    

    Where:
    a006 - stream id, "input":2 - input number. The numbering of the inputs begins with one.


    Create user:

    curl -X POST -d '{"cmd": "set-user", "id": "user6541", \
    "user": {"enable": true, "type": 3, \
    "password": "user6541",  "conlimit": "5", "ip": "172.31.2.6", \
    "packages": ["ALL"] }}' http://login:pass@tv.server.ip:port/control/
    

    Where:
    "id": "user6541" - User login. Is the user id.
    "enable": true - User is active.
    "type": 3 - User group. (1 - administrator, 2 - observer, 3 - user)
    "password": "user6541" - user password
    "conlimit": "5" - Limit on simultaneous connections.
    "ip": "172.31.2.6" - User's ip address.
    "packages": ["ALL"] - A package of channels available to the user.


    Get user configuration:

    curl -X POST  -d '{"cmd": "get-user", "id": "user6541"}' \
    http://login:pass@tv.server.ip:port/control/
    

    Where:
    user6541 - user login.


    Create/edit stream:

    curl -X POST -d '{"cmd": "set-stream","id": "a01h","stream": \
    {"id":"a01h","name":"test","enable": true,  "type": "spts", \
    "input": ["udp://251.34.21.5:1234], "output": ["http://0:8078/fox"] } }'\
    http://login:pass@tv.server.ip:port/control/
    

    Where:
    "name":"test" - stream name
    "id": "a01h" - stream id


    Set image in stream tile
    Image

    Create a script:

     #!/bin/bash
    
    AUTH="admin:pass"
    ADDR="127.0.0.1:8000"
    
    if [ -z "$1" ] ; then
        curl -s http://$ADDR/playlist.m3u8 | grep '^http' | sed 's/.*\/play\/\([^\/]*\).*/\1/' | while read ID ; do
            $0 shot $ID &
        done
    elif [ "$1" = "shot" ] ; then
        ID="$2"
        /usr/bin/ffmpeg -i "http://$ADDR/play/$ID" -v quiet -ss 2 -y -t 1 -vframes 1 -vf scale=160:100 -f image2 "/tmp/$ID.png" & sleep 3s && kill -9 $!
        IMG=$(cat /tmp/$ID.png | base64)
        echo "{\"cmd\":\"set-stream-image\", \"id\":\"$ID\", \"url\":\"data:image/png;base64,$IMG\"}" | curl -s -X POST -d "@-" http://$AUTH@$ADDR/control/
    fi
    

    Edit the lines:
    AUTH="admin:pass" - your login and password
    ADDR="127.0.0.1:8000" - ip and port where Astra is running