Skip to content
PHP SDK for api.video web-service (video encoding, hosting and secured delivery)
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.directory
.gitignore
CHANGELOG.md
README.md
composer.json
phpunit.xml.dist

README.md

api.video PHP SDK

Scrutinizer Code Quality Build Status

The api.video web-service helps you put video on the web without the hassle. This documentation helps you use the corresponding PHP client.

Quick start

Install:

$ composer require api-video/php-sdk

Usage:

<?php

require_once __DIR__ . 'vendor/autoload.php';

// Create client and authenticate
$client = new ApiVideo\Client\Client('xxxx');

// Create and upload a video resource from local drive
$video = $client->videos->upload(
    '/path/to/video.mp4', 
    array('title' => 'Course #4 - Part B')
);

// Create and upload a video resource from online source (third party)
$video = $client->videos->download(
    'https://www.exemple.com/path/to/video.mp4', 
    'Course #4 - Part B'
);

// Update video properties
$client->videos->update(
    $video->videoId, 
    array(
        'tags' => array('course', 'economics', 'finance')
    )
);

// Search video by tags filter and paginate results
$videos = $client->videos->search(
    array(
        'currentPage' => 1, 
        'pageSize' => 25, 
        'tags' => array('finance')
    )
);

foreach ($videos  as $video) {
    echo $video->title."\n";
}

// Delete video resource
$client->videos->delete($video->videoId);


// Upload a video thumbnail
$client->videos->uploadThumbnail('/path/to/thumbnail.jpg', $video->videoId);

// Update video thumbnail by picking image with video timecode
$client->videos->updateThumbnailWithTimeCode($video->videoId, '00:15:22.05');

// Create players with default values
$player = $client->players->create();

// Get a player
$player = $client->players->get($player->playerId);

// Search a player with paginate results
$players = $client->players->search(array('currentPage' => 1, 'pageSize' => 50));

$properties = array(
    'shapeMargin' => 10,
    'shapeRadius' => 3,
    'shapeAspect' => 'flat',
    'shapeBackgroundTop' => 'rgba(50, 50, 50, .7)',
    'shapeBackgroundBottom' => 'rgba(50, 50, 50, .8)',
    'text' => 'rgba(255, 255, 255, .95)',
    'link' => 'rgba(255, 0, 0, .95)',
    'linkHover' => 'rgba(255, 255, 255, .75)',
    'linkActive' => 'rgba(255, 0, 0, .75)',
    'trackPlayed' => 'rgba(255, 255, 255, .95)',
    'trackUnplayed' => 'rgba(255, 255, 255, .1)',
    'trackBackground' => 'rgba(0, 0, 0, 0)',
    'backgroundTop' => 'rgba(72, 4, 45, 1)',
    'backgroundBottom' => 'rgba(94, 95, 89, 1)',
    'backgroundText' => 'rgba(255, 255, 255, .95)',
    'language' => 'en',
    'enableApi' => false,
    'enableControls' => true,
    'forceAutoplay' => false,
    'hideTitle' => false,
    'forceLoop' => false
);

// Update player properties
$client->players->update($player->playerId, $properties);


// Delete a player
$client->players->delete($player->playerId);


// Upload video caption
$client->videos->captions->upload(
    'path/to/caption.vtt', 
    array(
        'videoId' => $video->videoId, 
        'language' => 'en'
    )
);

// Get video caption by language
$caption = $client->videos->captions->get($video->videoId, 'en');

// Update the default caption language
$client->videos->captions->updateDefault($video->videoId, 'en', true);

//Delete caption by language
$client->videos->captions->delete($video->videoId, 'en');

// Create a live
$live = $client->lives->create('Test live');

// Get video Analytics Data for the month of July 2018
$videoAnalytics = $client->analyticsVideo->get($video->videoId, '2018-07');

// Search Video Analytics Data between May 2018 and July 2018 and return the first 100 results
$analyticsVideo = $client->analyticsVideo->search(array('period' => '2018-05/2018-07', 'currentPage' => 1, 'pageSize' => 100));

// Get live Analytics Data for the month of July 2018
$liveAnalytics = $client->analyticsLive->get($live->liveStreamId, '2018-07');

// Search Live Analytics Data between May 2018 and July 2018 and return the first 100 results
$analyticsLive = $client->analyticsLive->search(array('period' => '2018-05/2018-07', 'currentPage' => 1, 'pageSize' => 100));

// Generate a token for delegated upload
$token = $client->tokens->generate();

Full API

<?php
/*
 *********************************
 *********************************
 *         VIDEO                 *
 *********************************
 *********************************
*/
$client = new ApiVideo\Client\Client($username, $password);

// Show a video
$client->videos->get($videoId);

// List or search videos
$client->videos->search(array $parameters = array(), $callback = null);

// Create video properties
$client->videos->create($title, $properties = array());

// Upload a video media file
// Create a video, if videoId is null
$client->videos->upload($source, array $properties = array(), $videoId = null);

// Create a video by downloading it from a third party
$client->videos->download($source, $title, array $properties = array());

// Update video properties
$client->videos->update($videoId, array $properties);

// Set video public
$client->videos->setPublic($videoId);

// Set video private
$client->videos->setPrivate($videoId);

// Delete video (file and data)
$client->videos->delete($videoId);

// Get last video request Error
$client->videos->getLastError();

// Delegated upload (generate a token for someone to upload a video into your account)
$token = $client->tokens->generate(); // string(3): "xyz"
// ...then upload from anywhere without authentication:
// $ curl https://ws.api.video/upload?token=xyz -F file=@video.mp4

/*
 *********************************
 *         VIDEO THUMBNAIL       *
 *********************************
*/

// Upload a thumbnail for video
$client->videos->uploadThumbnail($source, $videoId);

// Update video's thumbnail by picking timecode
$client->videos->updateThumbnailWithTimeCode($videoId, $timecode);

// Get last video request Error
$client->videos->getLastError();

/*
 *********************************
 *         VIDEO CAPTIONS        *
 *********************************
*/

// Get caption for a video
$client->videos->captions->get($videoId, $language);

// Get all captions for a video
$client->videos->captions->getAll($videoId);

// Upload a caption file for a video (.vtt)
$client->videos->captions->upload($source, array $properties);


// Set default caption for a video
$client->videos->captions->updateDefault($videoId, $language, $isDefault);

// Delete video's caption
$client->videos->captions->delete($videoId, $language);

// Get last video captions request Error
$client->videos->captions->getLastError();


/*
 *********************************
 *         PLAYERS               *
 *********************************
*/

// Get a player
$client->players->get($playerId);

// List players
$client->players->search(array $parameters = array(), $callback = null);

// Create a player
$client->players->create(array $properties = array());

// Update player's properties
$client->players->update($playerId, array $properties);

// Delete a player
$client->players->delete($playerId);

// Get last players request Error
$client->players->getLastError();

/*
 *********************************
 *********************************
 *         LIVE                 *
 *********************************
 *********************************
*/

// Show a live
$client->lives->get($liveStreamId);

// List or search lives
$client->lives->search(array $parameters = array(), $callback = null);

// Create live properties
$client->lives->create($name, $properties = array());

// Update live properties
$client->lives->update($liveStreamId, array $properties);

// Delete live (file and data)
$client->lives->delete($liveStreamId);

// Get last live request Error
$client->lives->getLastError();

/*
 *********************************
 *         LIVE THUMBNAIL       *
 *********************************
*/

// Upload a thumbnail for live
$client->lives->uploadThumbnail($source, $liveStreamId);

/*
 *********************************
 *         ANALYTICS             *
 *********************************
*/

// Get video analytics between period
$client->analyticsVideo->get($videoId, $period);

// Search videos analytics between period, filter with tags or metadata
$client->analyticsVideo->search($parameters);

// Get last video analytics request Error
$client->analyticsVideo->getLastError();

// Get live analytics between period
$client->analyticsLive->get($liveStreamId, $period);

// Search lives analytics between period, filter with tags or metadata
$client->analyticsLive->search($parameters);

// Get last live analytics request Error
$client->analyticsLive->getLastError();

Full API Details Implementation

Videos

Function Parameters Description Required Allowed Values
get videoId(string) Video identifier ✔️ -
search - - - -
- parameters(array) Search parameters
  • currentPage(int)
  • pageSize(int)
  • sortBy(string)
  • sortOrder(string)
  • keyword(string)
  • tags(string|array(string))
  • metadata(array(string))
- callback(function) callback function -
create - - - -
- title(string) Video title ✔️ -
- properties(array) Video properties
  • description(string)
  • tags(array(string))
  • playerId(string)
  • metadata(array(
    array(
    'key' => 'Key1',
    'value' => 'value1'
    ),
    array(
    'key' => 'Key2',
    'value' => 'value2'
    )
    )
upload - - - -
- source(string) Video media file ✔️ -
- properties(array) Video properties
  • title(string)
  • description(string)
  • tags(array(string))
  • playerId(string)
  • metadata(array(
    array(
    'key' => 'Key1',
    'value' => 'value1'
    ),
    array(
    'key' => 'Key2',
    'value' => 'value2'
    )
    )
- videoId(string) Video identifier -
download - - - -
- source(string) Video media file ✔️ -
- title(string) Video title ✔️ -
- properties(array) Video properties
  • description(string)
  • tags(array(string))
  • playerId(string)
  • metadata(array(
    array(
    'key' => 'Key1',
    'value' => 'value1'
    ),
    array(
    'key' => 'Key2',
    'value' => 'value2'
    )
    )
uploadThumbnail - - - -
- source(string) Image media file ✔️ -
- videoId(string) Video identifier ✔️ -
updateThumbnailWithTimeCode - - - -
- videoId(string) Video identifier ✔️ -
- timecode(string) Video timecode ✔️ 00:00:00.00
(hours:minutes:seconds.frames)
update - - - -
- videoId()string Video identifier ✔️ -
- properties(array) Video properties ✔️
  • title(string)
  • description(string)
  • tags(array(string))
  • playerId(string)
  • metadata(array(
    array(
    'key' => 'Key1',
    'value' => 'value1'
    ),
    array(
    'key' => 'Key2',
    'value' => 'value2'
    )
    )
setPublic videoId(string) Video identifier ✔️ -
setPrivate videoId(string) Video identifier ✔️ -
delete videoId(string) Video identifier ✔️ -

Players

Function Parameters Description Required Allowed Values
get playerId(string) Player identifier ✔️ -
create properties(array) Player properties
  • shapeMargin(int)
  • shapeRadius(int)
  • shapeAspect(string)
  • shapeBackgroundTop(string)
  • shapeBackgroundBottom(string)
  • text(string)
  • link(string)
  • linkHover(string)
  • linkActive(string)
  • trackPlayed(string)
  • trackUnplayed(string)
  • trackBackground(string)
  • backgroundTop(string)
  • backgroundBottom(string)
  • backgroundText(string)
  • enableApi(bool)
  • enableControls(bool)
  • forceAutoplay(bool)
  • hideTitle(bool)
update - - - -
- playerId(string) Player identifier ✔️ -
- properties(array) Player properties ✔️
  • shapeMargin(int)
  • shapeRadius(int)
  • shapeAspect(string)
  • shapeBackgroundTop(string)
  • shapeBackgroundBottom(string)
  • text(string)
  • link(string)
  • linkHover(string)
  • linkActive(string)
  • trackPlayed(string)
  • trackUnplayed(string)
  • trackBackground(string)
  • backgroundTop(string)
  • backgroundBottom(string)
  • backgroundText(string)
  • enableApi(bool)
  • enableControls(bool)
  • forceAutoplay(bool)
  • hideTitle(bool)
delete playerId(string) Player identifier ✔️ -

Captions

Function Parameters Description Required Allowed Values
get - - - -
- videoId(string) Video identifier ✔️ -
- language(string) Language identifier ✔️ 2 letters (ex: en, fr)
getAll videoId(string) Video identifier ✔️ -
upload - - - -
- source(string) Caption file ✔️ -
- properties(string) Caption properties ✔️
  • videoId(string)
  • language(string - 2 letters)
updateDefault - (array) - - -
- videoId Video identifier ✔️ -
- language (string) Language identifier ✔️ 2 letters (ex: en, fr)
- isDefault (string) Set default language ✔️ true/false
delete - (boolean) - - -
- videoId Video identifier ✔️ -
- language (string) Language identifier ✔️ 2 letters (ex: en, fr)

Lives

Function Parameters Description Required Allowed Values
get liveStreamId(string) Live identifier ✔️ -
search - - - -
- parameters(array) Search parameters
  • currentPage(int)
  • pageSize(int)
  • sortBy(string)
  • sortOrder(string)
- callback(function) callback function -
create - - - -
- name(string) Live name ✔️ -
- properties(array) Live properties
  • record(boolean)
  • playerId(string)
uploadThumbnail - - - -
- source(string) Image media file ✔️ -
- liveStreamId(string) Live identifier ✔️ -
update - - - -
- liveStreamId()string Live identifier ✔️ -
- properties(array) Live properties ✔️
  • title(string)
  • description(string)
  • tags(array(string))
  • playerId(string)
  • metadata(array(
    array(
    'key' => 'Key1',
    'value' => 'value1'
    ),
    array(
    'key' => 'Key2',
    'value' => 'value2'
    )
    )
delete liveStreamId(string) Live identifier ✔️ -

AnalyticsVideo

Function Parameters Description Required Allowed Values/Format
get - - - -
- videoId(string) Video identifier ✔️ -
- period (string) Period research
  • For a day : 2018-01-01
  • For a week: 2018-W01
  • For a month: 2018-01
  • For a year: 2018
  • Date range: 2018-01-01/2018-01-15
  • Week range: 2018-W01/2018-W03
  • Month range: 2018-01/2018-03
  • Year range: 2018/2020
search parameters(array) Search parameters
  • Pagination/Filters:
  • currentPage(int)
  • pageSize(int)
  • sortBy(string)
  • sortOrder(string)
  • tags(string|array(string))
  • metadata(array(string))
  • Period:
  • For a day : 2018-01-01
  • For a week: 2018-W01
  • For a month: 2018-01
  • For a year: 2018
  • Date range: 2018-01-01/2018-01-15
  • Week range: 2018-W01/2018-W03
  • Month range: 2018-01/2018-03
  • Year range: 2018/2020

AnalyticsLive

Function Parameters Description Required Allowed Values/Format
get - - - -
- liveStreamId(string) Live identifier ✔️ -
- period (string) Period research
  • For a day : 2018-01-01
  • For a week: 2018-W01
  • For a month: 2018-01
  • For a year: 2018
  • Date range: 2018-01-01/2018-01-15
  • Week range: 2018-W01/2018-W03
  • Month range: 2018-01/2018-03
  • Year range: 2018/2020
search parameters(array) Search parameters
  • Pagination/Filters:
  • currentPage(int)
  • pageSize(int)
  • sortBy(string)
  • sortOrder(string)
  • Period:
  • For a day : 2018-01-01
  • For a week: 2018-W01
  • For a month: 2018-01
  • For a year: 2018
  • Date range: 2018-01-01/2018-01-15
  • Week range: 2018-W01/2018-W03
  • Month range: 2018-01/2018-03
  • Year range: 2018/2020

Tokens

Function Parameters Description Required Allowed Values
generate - Token for delegated upload - -

Account

Function Parameters Description Required Allowed Values
get - Get account informations (quota, term) - -

More on api.video

A full technical documentation is available on https://docs.api.video/

You can’t perform that action at this time.