Create Video Clip
Description
The create_video_clip
function creates a video clip record in the system for a given device using details from a CreateVideoClip
object. It communicates with the backend API to initiate the creation process.
Function Signature:
def create_video_clip(
ws_config: WebServiceConfig,
device_name: str,
create_video_clip: CreateVideoClip
) -> tuple[int, str]:
Parameters
- ws_config (WebServiceConfig): Configuration object for the web service.
- device_name (str): The name of the device creating the clip. It will be sanitized and URL-encoded.
- create_video_clip (CreateVideoClip): An object containing metadata and options for the video clip to be created.
Returns
- tuple[int, str]: A tuple with:
- int: The HTTP response code from the server.
- str: The HTTP response body, often a status message or JSON string.
Example Usage
ws_config = WebServiceConfig(base_url="https://api.actionstreamer.com")
create_video_clip_obj = CreateVideoClip(start_time=..., end_time=..., tags=..., etc.)
device_name = "My Device 01"
response_code, response_string = create_video_clip(ws_config, device_name, create_video_clip_obj)
print(response_code, response_string)
Behavior
- Sanitizes and URL-encodes the
device_name
. - Sends a
POST
request to thev1/videoclip/{device_name}
endpoint. - Includes the JSON representation of the
CreateVideoClip
object in the request body. - Returns the response code and message from the web service.
Error Handling
- On exception:
- Sets
response_code
to-1
. - Includes an error message in
response_string
with the exception line number. - Logs the exception details to the console.
- Sets