Control Panel — API Documentation

Documentation

API Documentation: sevu.request

Synopsis

This API creates a SEVU ticket. This ticket allows a user to view a protected video. This system allows you to restrict access to a specific video or subset of videos, to a specific IP address, timeframe and usage count.

Example Code (C#)

using System;
using System.IO;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using Newtonsoft.Json.Linq;
using RestSharp;

namespace ConsoleApplication1
{
    internal class Program
    {
        /**
         * Before you can use this example. 
         * You should references to Newtonsoft.Json.Linq and RestSharp
         * It can be done with Nuget Packgage manager console
         *          PM> Install-Package Newtonsoft.Json
         *          PM> Install-Package RestSharp
         * Or you download it from :
         * https://www.nuget.org/packages/Newtonsoft.Json/
         * https://www.nuget.org/packages/RestSharp/
         * 
         */
        private static void Main(string[] args)
        {
            var api_key = "[API KEY]";
            var cdn = 0; // CDN NUMBER 
            var privateKey = "[PRIVATE KEY]";
            var video = "[PATH TO YOUR VIDEO]";
            var app = "[YOUR APP NAME]";
            var content = CreateSevuTicket(api_key, cdn, app, video, privateKey);
            Console.Write(content);
            Console.WriteLine("Press ESC to stop");
            do
            {
                while (!Console.KeyAvailable)
                {
                    // Do something
                }
            } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
        }
        private static string CreateSevuTicket(string api_key, int cdn, string app, string video, string privateKey)
        {
            var data = new JObject();
            data["command"] = "sevu.request";
            data["api_key"] = api_key;
            data["timestamp"] = ((Int32) (DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds);
            data["cdn"] = cdn;
            data["app"] = app;
            data["video"] = video;
            data["pass"] = Guid.NewGuid().ToString();
            data["ip"] = "0.0.0.0/0";
            data["uses"] = 5;
            data["expires"] = string.Format("{0:yyyy-MM-dd H:mm:ss}", DateTime.Now.AddDays(1));
            var str = data.ToString().Replace("\r\n", "").Replace(" ", "").Replace("/", "\\/");
            var s = CreateSignature(str, privateKey);
            data["signature"] = s;
            var postData = data.ToString().Replace("\r\n", "").Replace(" ", "").Replace("/", "\\/");
            var restClient = new RestClient("https://api.scaleengine.net:443/stable/");
            var request = new RestRequest("", Method.POST);
            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            request.AddHeader("Content-Length", Convert.ToString(postData.Length + 5));
            request.AddParameter("json", postData);
            var response = restClient.Execute(request);
            var content = response.Content;
            return content;
        }
        private static string CreateSignature(string message, string secret)
        {
            secret = secret ?? "";
            var encoding = new ASCIIEncoding();
            byte[] keyByte = encoding.GetBytes(secret);
            byte[] messageBytes = encoding.GetBytes(message);
            using (var hmacsha256 = new HMACSHA256(keyByte))
            {
                byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);
                return Convert.ToBase64String(hashmessage);
            }
        }
    }
}
    

Request Fields

command [REQUIRED] [string] - API command to execute
cdn [REQUIRED] [int] - The ScaleEngine CDN ID of your account
api_key [REQUIRED] [string] - The API key provided as part of your account
timestamp [REQUIRED] [int] - The unix timestamp of your request, used to prevent authenticated API requests from being replayed
app [REQUIRED]
  • [string] - The ScaleEngine Application name to restrict viewing to
  • [string] - A pipe separated list of applications, optionally with wildcards.
    Example: myapp-vod|otherapp-*
video [REQUIRED]
  • [string] - The stream name or path of the VOD video the user is restricted to. VOD examples look like like: sestore3/username/path/filename.mp4
  • [string] - One of more stream name or VOD path separated by a pipe, optionally with wildcards. This allows for things like multi-bitrate streams or files, or allowing users access to a group of streams and videos.
    Example: mystream_* will match mystream_720p and mystream_360p.
    Example: file1.mp4|file2.mp4 will only allow the listed files to play
    Example: sestore3/username/set1/*|sestore3/username/set2/* will match any file in those directories
pass [REQUIRED] [string] - A randomly generated password. Should be unique for each request. Recommended length atleast 10 characters.
ip [REQUIRED]
  • [string] - The IP address to allow access from
  • [string] - The CIDR mask of a range of IP addresses to allow access from.
    Example: 192.168.0.0/24
    Example: 0.0.0.0/0 allows any IP address
  • [string] - The literal string 'auto' or 'auto/24'. This will update the ticket the first time it is used to restrict it to the IP address of the user. This will prevent account sharing, while at the same time dealing with edge cases such as users behind corporate firewalls or proxies that may have a different IP address on the website than they will use to access the video stream
uses [REQUIRED] [int] - The number of times the video will be allowed to start. This can be used to restrict how many times a ticket may be used, and helps further protect against account sharing
expires [REQUIRED] [datetime] - The expiration date of the ticket. After this time, access will no longer be allowed, the user will require a new ticket.
Example: 2024-03-19 16:42:57

Example Result (JSON)

    {
    "code": 2002,
    "message": "ScaleEngine Virtual Usher Ticket Granted",
    "status": "success",
    "ticket": {
        "key": "mystream.53ffc996dd39d5.39102367",
        "pass": "g63clVAI5wFPxY9vwVOJvw6L",
        "ip": "0.0.0.0/0",
        "video": "mystream",
        "app": "myapp-sevu",
        "created_date": "2014-08-29 00:30:14",
        "used_date": "0000-00-00 00:00:00",
        "uses": "5",
        "active": "1"
        },
    "handle_time":"0.3795 seconds"
    }
    

Result Fields

code [int] - API Response Code
message [string] - Debugging message
status [string] - "success" or "failure"
ticket
key [string] - The SEVU ticket. This is the string that combined with the password provided when the ticket was created allows a user access to a protected stream. Must be included in the server URL as the "key" parameter
pass [string] - The password provided by you when you requested the ticket. Must be included in the server URL as the "pass" parameter
ip [string] - The IP address provided in the request
video [string] - The video(s) or stream(s) that this ticket is valid for
app [string] - The application(s) that this ticket is valid for
created_date [datetime] - The datetime the ticket was created
used_date [datetime] - The datetime of the first time this ticket was used by a user
uses [int] - How many uses remain for this ticket, this number is decremented each time the ticket is used
active [bool] - 1 if the ticket is still active, 0 if it has been revoked
handle_time [float] - The amount of time spent processing your request