API (Application Programming Interface) is a set of methods that allow to access the features or data of Astra from external applications.
Stream Management
set-stream
This method create, remove, or modify streams. Request:
{
"cmd": "set-stream",
"id": "...",
"stream": {
"enable": true,
"type": "spts",
"id": "...",
"name": "...",
"input: [ ... ],
"output: [ ... ]
}
}
- id – unique stream identifier. Option required on stream modification. This option is not required to create a new stream.
- enable – required field, enabled srteam or not.
- type – required field, stream type. Available values: spts or mpts.
- id – unique stream identifier.
- name – stream name.
- input – list of the stream sources.
- output – list of the stream destinations.
To remove stream send similar request:
{
"cmd": "set-stream",
"id": "...",
"stream": {
"remove": true
}
}
get-stream
Get stream options. Request:
{
"cmd": "get-stream",
"id": "..."
}
Response:
{
"get-stream": "ok",
"stream": { ... }
}
stream - contains all stream options
toggle-stream
Turn off/on stream. Request:
{
"cmd": "toggle-stream",
"id": "..."
}
restart-stream
Restart stream. Request:
{
"cmd": "restart-stream",
"id": "..."
}
set-stream-input
Choose active input. Works only for streams with next backup types: passive, disable. Request:
{
"cmd": "set-stream-input",
"id": "...",
"input": "..."
}
input – input number. If option not defined will be started next input after the active
DVB Management
set-adapter
This method create, remove, or modify adapters. Request:
{
"cmd": "set-adapter",
"id": "...",
"adapter": {
"enable": true,
"type": "...",
"id": "...",
"name": "...",
"adapter": 0,
"device": 0,
...
}
}
- id – unique adapter identifier. Option required on adapter modification. This option is not required to create a new adapter.
- enable – required field. enabled adapter or not.
- type – required field. Adapter type. Available values: S, S2, T, T2, ATSC, ISDBT, C, C/A, C/B, C/C.
- id – unique adapter identifier.
- name – adapter name.
- adapter – adapter number /dev/dvb/adapter0
- device – device number /dev/dvb/adapter0/frontend0
- other options specific depends of the adapter type.
To remove adapter and all related streams send similar request:
{
"cmd": "set-adapter",
"id": "...",
"adapter": {
"remove": true
}
}
Attention! This method removes all related streams
get-adapter
Get adapter options. Request:
{
"cmd": "get-adapter",
"id": "..."
}
Response:
{
"get-adapter": "ok",
"adapter": { ... }
}
adapter – contains all stream options
restart-adapter
Restart adapter and all related streams. Request:
{
"cmd": "restart-adapter",
"id": "..."
}
Users Management
set-user
This method create, remove, or modify users. Request:
{
"cmd": "set-user",
"id": "...",
"user": {
"enable": true,
"type": 0,
"password": "...",
...
}
}
- id – unique user identifier (login)
- user – set of user data
- enable – required field. enabled account or not
- type – required field. user type: 1 - admin, 2 - read only, 3 - regular user (without access to the Astra administration interface)
- password
To remove user send similar request:
{
"cmd": "set-user",
"id": "...",
"user": {
"remove": true
}
}
toggle-user
Turn off/on user. Request:
{
"cmd": "toggle-user",
"id": "..."
}
Sessions
The method returns a list of current sessions. Answer format:
{
"cmd": "sessions"
}
The format of the session information: SESSION-INFO:
{
"client_id": N,
"channel_id": "...",
"channel_name": "...",
"addr": "...",
"uptime": N
}
- client_id — unique number of the session
- channel_id — stream ID
- channel_name — stream name
- addr — The IP address of the client. To get the IP address from HTTP header X-Real-IP or X-Forwarded-For, while proxying requests, you must use the auth_request.
- uptime — time, in seconds, since the beginning of the session
To end the session, you must use the close-session method:
{
"cmd": "close-session",
"id": N
}
- id — session number
Other
restart astra
Request:
{
"cmd": "restart"
}
loading configuration
Request:
{
"cmd": "load"
}
The answer is the contents of the configuration file.
get user config
{
"cmd": "get-user", "id": "login"
}
get stream status
{
"cmd": "check-stream", "id": "a001", "status": true
}
Response - content monitoring data.
{
"status": {
"onair": "...",
"active_input": "...",
"input": [
{
"scrambled": "...",
"cc_error": "...",
"bitrate": "...",
"pes_error": "..."
}
]
},
"check-stream": "ok"
}
- onair - the status of the stream active broadcast.
- active_input - the number of active input.
- input - array of the channel inputs
- scrambled - whether the stream is encrypted.
- cc_error - the current number of CC errors.
- bitrate - input bitrate.
- pes_error - number of current PES errors.
- check-stream": "ok" - checking the stream was a success.
If you pass the request as:
{
"cmd": "check-stream", "id": "a001"
}
the answer will only
"check-stream": "ok"
or "check-stream": "false"
- the status of the stream without additional data.
set serial number
{
"cmd": "set-license", "license": "xxx"
}
Use API
curl
curl -X POST \
-d '{"cmd": "api-method"}' \
http://admin:password@127.0.0.1:8000/control/
127.0.0.1:8000
is a server address and Astra portadmin:password
is an admin login and password
php
$req = json_encode(array(
'cmd' => 'api-method',
));
$ch = curl_init("http://127.0.0.1:8000/control/");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, "admin:password");
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$res = curl_exec($ch);
curl_close($ch);
127.0.0.1:8000
is a server address and Astra portadmin:password
is an admin login and password
$res
is a response data