API Reference

Video Upload via S3

The S3 Watchfolder allows content to be ingested without having to use the Skylark UI. This is often used for batch ingesting content or for ingesting content from an upstream DAM/MAM.

When deployed, each Skylark account is created with a bucket named:

<environment>-<region>-skylark-ws-watchfolder

Security

You'll need to request your Watchfolder S3 credentials from the Customer Success Team.

Simple Mode Upload

In Simple Mode, when a video file is dropped into the watchfolder a Skylark Asset object is created. The Asset is created with a Data Source object named after the video file (without the extension), which allows the Asset to easily referenced without knowing its UID.

For each enabled Ingest Provider, an OVP object is associated to the Asset containing one or more URLs to the processed streams.

Processed videos are moved to the /processed directory when ingested successfully.

Simple Mode Example

  1. Upload file:
$ aws s3 cp my-video.mp4 myaccount-eu-west-1-skylark-ws-watchfolder
  1. Monitor the /processed directory to ensure file has been processed by all Ingest Providers

  2. Retrieve Asset by the original filename:

curl 'https://api.myenvironment.myaccount.skylarkplatform.io/api/assets/versions/data-source/my-video' \
  -H 'accept: application/json, text/plain, */*' \
  -H 'authorization: Bearer ...'

Advanced Mode Upload

In Advanced Mode, it’s possible to specify the Asset object details on the video file. This allows you to associate the video file to an existing Asset object, or create a new Asset while specifying attributes, such as title and text_track_url.

This is supported by S3 clients that allow metadata to be set on the S3 object. When uploading, set the asset metadata field to an Asset object: Skylark API

To associate the video file to an existing Asset, specify the Asset id using the uid field.

Advanced Mode Examples

Upload file to existing Asset:

aws s3 cp --metadata '{"asset": "{\"uid\": \"asse_35bbd8a914c84cd3850158ec2783f42a\"}"}' my-video.mp4 myenvironment-eu-west-1-skylark-ws-watchfolder

Upload file to new asset and link to text tracks:

import boto3
import json
import jmespath
import requests
from urllib.parse import urljoin
from pycognito.utils import RequestsSrpAuth, TokenType


auth = RequestsSrpAuth(
    username="[email protected]",
    password='',
    user_pool_id='eu-west-1_IeRtZg37h',
    user_pool_region='eu-west-1',
    client_id='13s4i5bb6qbpere7ns52dfdmph',
    auth_token_type=TokenType.ID_TOKEN
)

base_url = 'https://api.myenvironment.skylarkplatform.io/api/'

# Create new asset
asset_request_body = {
    'title': 'ABC 123 Title',
    'slug': 'abc-123-title',
    'asset_type_url': '/api/asset-types/<<uid of asset type>>',
}
asset_request = requests.post(urljoin(base_url, '/assets/'), json=asset_request_body, auth=auth)
asset_request.raise_for_status()
asset_response_json = asset_request.json()
asset_url = asset_response_json['self']
asset_uid = asset_response_json['uid']

# Create TextTrack object
text_track_request_body = {
    'language_code': 'en',
    'asset_urls': [asset_url],
}
text_track_request = requests.post(urljoin(base_url, '/text-tracks/'), json=text_track_request_body, auth=auth)
text_track_request.raise_for_status()
text_track_response_json = text_track_request.json()
text_track_url = text_track_response_json['self']

# create document for the text_track
# This needs a document type. Get the document type - name: 'Text track', which is created by default in Skylark deployment
document_type_params = {
  'name': 'Text track'
}
document_type_request = requests.get(urljoin(base_url, '/document-types/'), params=document_type_params, auth=auth)
document_type_request.raise_for_status()
document_type_response_json = document_type_request.json()
document_type_url = jmespath.search('objects[0].self', document_type_response_json)

# create document for the text_track
document_body = {
    'document_type_url': document_type_url,
    'content_url': text_track_url,
    'file_name': 'abc123.srt',
    'language': 'en-gb',
    'title': 'abc123.srt',
}
document_request = requests.post(urljoin(base_url, '/documents/'), json=document_body, auth=auth)
document_request.raise_for_status()
document_response_json = document_request.json()
# get file upload url
upload_document_url = document_response_json['upload_document_url']

# Upload SRT file contents to Document object
with open('abc123.srt', 'rb') as srt_file:
    srt_upload_request = requests.post(urljoin(base_url, upload_document_url), files={'file': srt_file}, auth=auth)
    srt_upload_request.raise_for_status()

# Prepare S3 object
session = boto3.Session(aws_access_key_id='', aws_secret_access_key='', region_name='')
s3_client = session.client('s3')

# Upload the video file and set metadata
bucket = 'myenvironment-eu-west-1-skylark-ws-watchfolder'
with open(ABC123-video.mp4, 'rb') as file:
    s3_client.upload_fileobj(
        file, 
        Bucket=bucket, 
        Key='ABC123-video.mp4',
        ExtraArgs={'Metadata': {'asset': json.dumps({'uid': asset_uid})}}
    )

In the advanced scenario for uploading a video for a new asset with text tracks, the asset object can be created with links to the text tracks.

Only the uid of the asset can be set in the metadata of the video being uploaded. The workflow service can extract the information of all the text tracks associated with an asset.