Use cases

Updated at:

This topic provides examples of basic API operations that you can perform using the Python Software Development Kit (SDK).

Initialize the client

import os
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_vs20181212 import models as vs_20181212_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_vs20181212.client import Client as vs20181212Client

config = open_api_models.Config(
    # Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
    access_key_id=os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
    # Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
    access_key_secret=os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
)
# For the endpoint, see https://api.aliyun.com/product/vs
config.endpoint = f'vs.cn-qingdao.aliyuncs.com'
c = vs20181212Client(config)

List Spaces

describe_groups_request = vs_20181212_models.DescribeGroupsRequest(
    page_num=1    # Optional. The page number to query.
)
runtime = util_models.RuntimeOptions()
resp = c.describe_groups_with_options(describe_groups_request, runtime)
print(resp)

Get a list of devices

  • You can query for a list of devices in a group using the group ID. If you do not know the group ID, see Retrieve a list of groups to find the target group.

describe_devices_request = vs_20181212_models.DescribeDevicesRequest(
    id='id'    # Optional. The group ID to use for the query.
)
runtime = util_models.RuntimeOptions()
resp = c.describe_devices_with_options(describe_devices_request, runtime)
print(resp)

Get a list of streams

  • You can query for a list of streams in a group using the group ID. If you do not know the group ID, see Retrieve a list of groups to find the target group.

  • You can also query for streams on a device using the device ID. If you do not know the device ID, see Retrieve a list of devices to find the target device.

describe_streams_request = vs_20181212_models.DescribeStreamsRequest(
    group_id='GroupId',      # Optional. The group ID to use for the query.
    device_id='DeviceId'     # Optional. The device ID to use for the query.
)
runtime = util_models.RuntimeOptions()
resp = c.describe_streams_with_options(describe_streams_request, runtime)
print(resp)

Get the playback URL for a stream

  • You can retrieve the playback URL using the stream ID. If you do not know the stream ID, see Retrieve a list of streams to find the target stream.

describe_stream_urlrequest = vs_20181212_models.DescribeStreamURLRequest(
    id='id',                # Required. The stream ID.
    out_protocol='rtmp',    # Required. The playback protocol. Valid values: rtmp, flv, and hls.
    auth_key='AuthKey',     # Required. The primary key associated with the playback domain name. This key is used to generate a signed URL.
    type='live'             # Optional. The stream type. Valid values: live and vod.
)
runtime = util_models.RuntimeOptions()
resp = c.describe_stream_urlwith_options(describe_stream_urlrequest, runtime)
print(resp)

Get a list of recordings

  • You can retrieve the list of recordings using the stream ID. If you do not know the stream ID, see Retrieve a list of streams to find the target stream.

describe_records_request = vs_20181212_models.DescribeRecordsRequest(
    type='record',         # Required. The type of stored record to query. Valid values: record (recording) and snapshot (screenshot).
    stream_id='StreamId',  # Required. The stream ID.
    start_time='StreamTime',  # Required. The start time for the query. Format: 2019-10-08T14:02:00Z.
    end_time='EndTime',   # Required. The end time for the query. Format: 2019-10-09T14:02:00Z.
    page_num=1,           # Optional. The page number. Default value: 1.
    page_size=20          # Optional. The number of entries per page. Default value: 20.
)
runtime = util_models.RuntimeOptions()
resp = c.describe_records_with_options(describe_records_request, runtime)
print(resp)