A simple PHP library to interact with the Bunny Stream API.
In order to interact with the API you need the API Access Information (Stream->{Library}->API)
composer require serch3/bunny-stream
Create an instance of the \Bunny\Stream\Client with the authentication details:
$client = new \Bunny\Stream\Client('API_KEY', 'LIBRARY_ID');
$client->listVideos();
$client->listVideos($search, $page, $items, $collection, $orderby); //filtered results
Optional:
-
$Search
if set, the response will be filtered to only contain videos that contain the search termstring
-
$Page
Page number. Default is 1int
-
$Items
Number of results per page. Default is 100int
-
$Collection
If set, the response will only contain videos that belong to this collection Idstring
-
$OrderBy
Determines the ordering of the result within the response. date/titlestring
$client->getVideo($videoId);
$videoId
ID of the video string
$body = [
'title' => '...',
'collectionId' => '...',
'chapters' => [
[
'title' => 'Chapter 1',
'start' => 0,
'end' => 300,
]
],
'moments' => [
[
'label' => 'Awesome Scene 1',
'timestamp' => 70,
],
],
'metaTags' => [
[
'property' => 'description',
'value' => 'My Video Description',
],
],
];
$client->updateVideo($videoId, $body);
$videoId
Id of the video string
$body
Updated video details array
$client->deleteVideo($videoId);
$videoId
Id of the video that will be permanently deleted string
$client->createVideo($title, $collectionId, $thumbnailTime);
$title
Title of the video string
Optional:
-
$collectionId
Collection Idstring
-
$thumbnailTime
Video time in ms to extract the main video thumbnailint32
$client->uploadVideoWithVideoId($videoId, $path, $enabledResolutions);
$videoId
Id of the video entry string
$path
Video file path string
Optional:
$enabledResolutions
Custom resolutions for the videostring
$client->uploadVideo($title, $path, $collectionId, $thumbnailTime, $enabledResolutions);
$title
Title of the video string
$path
Video file path string
Optional:
-
$collectionId
Collection Idstring
-
$thumbnailTime
Video time in ms to extract the main video thumbnailint32
-
$enabledResolutions
Custom resolutions for the videostring
$client->setVideoThumbnail($videoId, $url);
$videoId
Id of the video string
$url
accessible thumbnail url string
$client->getVideoHeatmap($videoId);
$videoId
Id of the video string
$client->getVideoPlayData($videoId, $token, $expires);
$videoId
Id of the video string
Optional:
-
$token
Token to authenticate the requeststring
-
$expires
Expiry time of the tokenint64
$query = [
'dateFrom' => 'm-d-Y',
'dateTo' => 'm-d-Y',
'hourly' => false,
'videoGuid' => '...',
];
$client->getVideoStatistics($videoId, $query);
$videoId
Id of the video string
Optional:
$query
parametersarray
:- dateFrom - The start date of the statistics. If no value is passed, the last 30 days will be returned.
date-time
- dateTo - The end date of the statistics. If no value is passed, the last 30 days will be returned.
date-time
- hourly - If true, the statistics data will be returned in hourly groupping.
boolean
- videoGuid - The GUID of the video for which the statistics will be returned
string
- dateFrom - The start date of the statistics. If no value is passed, the last 30 days will be returned.
$client->reencodeVideo($videoId);
$videoId
Id of the video string
$client->addOutputCodec($videoId, $codec);
$videoId
Id of the video string
$codec
Output codec to be added int
- 0 = x264
- 1 = vp9
- 2 = hevc
- 3 = av1
$client->repackageVideo($videoId, $keepOriginalFiles);
$videoId
Id of the video string
$keepOriginalFiles
Marks whether previous file versions should be kept in storage, allows for faster repackage later on. Default is true.
$client->fetchVideo($url, $title, $collectionId, $thumbnailTime, $headers);
$url
The URL from which the video will be fetched from. string
Optional:
-
$title
Title of the videostring
-
$collectionId
Collection Idstring
-
$thumbnailTime
Video time in ms to extract the main video thumbnailint32
-
$headers
Additional headers that will be sent along with the fetch request.array
$client->addCaption($videoId, $srclang, $path, $label);
$videoId
Id of the video string
$srclang
Language shortcode for the caption. string
$path
Caption file path (.vtt/.srt) string
Optional:
$label
Label of the captionstring
$client->deleteCaption($videoId, $srclang);
$videoId
Id of the video string
$srclang
Language shortcode for the caption. string
$client->transcribeVideo($videoId, $language, $force);
$videoId
Id of the video string
$language
Language code for the transcription string
$force
Default is false bool
$client->requestVideoResolutionsInfo($videoId);
$videoId
Id of the video string
$config = [
'deleteNonConfiguredResolutions' => true,
'deleteOriginal' => false,
'deleteMp4Files' => true,
'dryRun' => false,
];
$resolutions = "240p,360p,480p";
$client->cleanupResolutions($videoId, $resolutions, $query);
$videoId
Id of the video string
$resolutions
List of resolutions to be removed array
Optional:
$query
parametersarray
:- resolutionsToDelete - List of resolutions to be removed
array
- deleteNonConfiguredResolutions - If set to true, all resolutions that are not configured in the video will be removed
boolean
- deleteOriginal - If set to true, the original file will be removed.
boolean
- deleteMp4Files - If set to true, all mp4 files will be removed.
boolean
- dryRun - If set to true, no actual file manipulation will happen, only informational data will be returned.
boolean
- resolutionsToDelete - List of resolutions to be removed
$client->listCollections($search, $page, $items, $orderby, $includeThumbnails);
Optional:
-
$search
if set, the response will be filtered to only contain collections that contain the search termstring
-
$page
Page number. Default is 1int
-
$items
Number of results per page. Default is 100int
-
$orderby
Determines the ordering of the result within the response. date/titlestring
-
$includeThumbnails
If set to true, the response will include the thumbnail for each collection. Default is falsebool
$client->getCollection($collectionId, $includeThumbnails);
$collectionId
Id of the collection string
Optional:
$includeThumbnails
If set to true, the response will include the thumbnail URL for the collection. Default is falsebool
$client->createCollection($name);
$name
Name of the collection string
$client->updateCollection($collectionId, $name);
$collectionId
Id of the collection string
$name
Updated name of the collection string
$client->deleteCollection($collectionId);
$collectionId
Id of the collection to be deleted string
All methods return an associative array with the response from the API, or an exception if an error occurs. Check reference for specific responses.