Live Slicer API Tutorials

Goal: Control the Live Slicer via the Live Slicer API to perform the following actions:

Software Prerequisites:

  • Live Slicer

Knowledge Prerequisites:

  • Basic RESTful API
  • Basic Python Coding

Key Steps:

  1. Slicing to a new asset.
  2. Stop slicing.
  3. Replacing content.
  4. Marking an ad for replacement.

Slicing to a New Asset

The content_start endpoint may be used to force the Live Slicer to:

A start timecode promotes frame accuracy when executing Live Slicer commands. By default, this start timecode is set to the oldest frame in the Live Slicer's buffer.
Learn more.

Run the following Python script to create a new asset whose title is set to "My New Program."

import urllib2, json

SLICER_IP = "127.0.0.1"  # localhost
SLICER_PORT = 65009      # default port

body = json.dumps({"title":"My New Program"})
request = urllib2.urlopen("http://%s:%d/content_start" % (SLICER_IP, SLICER_PORT), body)
response = json.loads(request.read())
assert response["error"] == 0	

From the Content tab in the CMS, verify that the Live Slicer is slicing into a new asset.

Stop Slicing

The blackout endpoint forces the Live Slicer into blackout mode. The Live Slicer will stop slicing into the current asset and blackout content will be streamed to viewers.

Run the following Python script to blackout the live stream.

import urllib2, json

SLICER_IP = "127.0.0.1"  # localhost
SLICER_PORT = 65009      # default port

body = json.dumps({"start_timecode":"00:00:00;00"}) # timecode format HH:MM:SS;Frame
request = urllib2.urlopen("http://%s:%d/blackout" % (SLICER_IP, SLICER_PORT), body)
response = json.loads(request.read())
assert response["error"] == 0	

Call the content_start endpoint to create an asset into which the Live Slicer will resume slicing.

Replacing Content

Content from a linear feed may be replaced with an assetRefers to media (i.e., audio/video content) associated with either your account or a library shared with your account..

An example of a content replacement scenario occurs when an affiliate is not licensed to broadcast a sporting event online. In this scenario, the sporting event would be replaced with one or more assets.

Content replacement requires the following information:

The Python script provided below replaces 100 seconds from a linear feed with an asset whose duration is 100 seconds.

Verify and/or update the values defined in lines 5 - 7 to match an asset in your libraryThe library is a central repository for on-demand content. View the library's content via the Content tab in the CMS.. After which, run this Python script.

import urllib2, json

SLICER_IP = "127.0.0.1"  # localhost
SLICER_PORT = 65009      # default port
SECTION_TO_BE_REPLACED_DURATION = 100.0 # type=float, unit=seconds, full duration of content to be replaced
REPLACEMENT_ASSET_EXTERNAL_ID = "MyReplacementAsset"
REPLACEMENT_ASSET_DURATION = 100.0 # type=float, unit=seconds

body = json.dumps({"duration":SECTION_TO_BE_REPLACED_DURATION,"replacements": \
    [{"external_id":REPLACEMENT_ASSET_EXTERNAL_ID,"duration":REPLACEMENT_ASSET_DURATION}]})
request = urllib2.urlopen("http://%s:%d/replace_content" % (SLICER_IP, SLICER_PORT), body)
response = json.loads(request.read())
assert response["error"] == 0	

Marking an Ad for Replacement

Any of the following endpoints may be used to replace an ad within a linear feed:

Endpoint Usage

replace_pod

Replace ads when the ad break duration is known.

pod_start

Start an ad break with an unknown duration.

pod_end

End an ad break started via the pod_start endpoint.

Commons reasons for replacing ads are broadcast licensing issues, making ads more pertinent to a particular locale, or to leverage viewer's ad preferences.

Run the following Python script to mark the next 180 seconds as an ad break that can be replaced with alternate content.

import urllib2, json

SLICER_IP = "127.0.0.1"  # localhost
SLICER_PORT = 65009      # default port
AD_POD_DURATION = 180.0  # type=float, unit=seconds

body = json.dumps({"duration":AD_POD_DURATION})
request = urllib2.urlopen("http://%s:%d/replace_pod" % (SLICER_IP, SLICER_PORT), body)
response = json.loads(request.read())
assert response["error"] == 0