Skip to content

A simple PHP library to interact with the bunny.net Stream API.

License

Notifications You must be signed in to change notification settings

serch3/bunny-stream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bunny Stream PHP Library

A simple PHP library to interact with the Bunny Stream API.

Requires

In order to interact with the API you need the API Access Information (Stream->{Library}->API)

Installation

composer require serch3/bunny-stream

How to use:

Quick start

Create an instance of the \Bunny\Stream\Client with the authentication details:

$client = new \Bunny\Stream\Client('API_KEY', 'LIBRARY_ID');

Manage Videos:

Listing Videos:

$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 term string

  • $Page Page number. Default is 1 int

  • $Items Number of results per page. Default is 100 int

  • $Collection If set, the response will only contain videos that belong to this collection Id string

  • $OrderBy Determines the ordering of the result within the response. date/title string


Get Video

$client->getVideo($videoId);

$videoId ID of the video string


Update Video

$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


Delete Video

$client->deleteVideo($videoId);

$videoId Id of the video that will be permanently deleted string


Create Video Entry

$client->createVideo($title, $collectionId, $thumbnailTime);

$title Title of the video string

Optional:

  • $collectionId Collection Id string

  • $thumbnailTime Video time in ms to extract the main video thumbnail int32


Upload Video with Id

$client->uploadVideoWithVideoId($videoId, $path, $enabledResolutions);

$videoId Id of the video entry string

$path Video file path string

Optional:

  • $enabledResolutions Custom resolutions for the video string

Upload Video

$client->uploadVideo($title, $path, $collectionId, $thumbnailTime, $enabledResolutions);

$title Title of the video string

$path Video file path string

Optional:

  • $collectionId Collection Id string

  • $thumbnailTime Video time in ms to extract the main video thumbnail int32

  • $enabledResolutions Custom resolutions for the video string


Set Thumbnail

$client->setVideoThumbnail($videoId, $url);

$videoId Id of the video string

$url accessible thumbnail url string


Get Video Heatmap

$client->getVideoHeatmap($videoId);

$videoId Id of the video string


Get Video play data

$client->getVideoPlayData($videoId, $token, $expires);

$videoId Id of the video string

Optional:

  • $token Token to authenticate the request string

  • $expires Expiry time of the token int64


Get Video Statistics

$query = [
    'dateFrom' => 'm-d-Y',
    'dateTo' => 'm-d-Y',
    'hourly' => false,
    'videoGuid' => '...',
];
$client->getVideoStatistics($videoId, $query);

$videoId Id of the video string

Optional:

  • $query parameters array:
    • 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

Re-encode Video

$client->reencodeVideo($videoId);

$videoId Id of the video string


Add output codec to video (Requires Premium Encoding Plan)

$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


Repackage Video

$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.


Fetch Video

$client->fetchVideo($url, $title, $collectionId, $thumbnailTime, $headers);

$url The URL from which the video will be fetched from. string

Optional:

  • $title Title of the video string

  • $collectionId Collection Id string

  • $thumbnailTime Video time in ms to extract the main video thumbnail int32

  • $headers Additional headers that will be sent along with the fetch request. array


Add Caption

$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 caption string

Delete Caption

$client->deleteCaption($videoId, $srclang);

$videoId Id of the video string

$srclang Language shortcode for the caption. string


Transcribe video

$client->transcribeVideo($videoId, $language, $force);

$videoId Id of the video string

$language Language code for the transcription string

$force Default is false bool


Request Video resolutions info

$client->requestVideoResolutionsInfo($videoId);

$videoId Id of the video string


Cleanup unconfigured resolutions

$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 parameters array:
    • 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

Collections:

Listing Collections

$client->listCollections($search, $page, $items, $orderby, $includeThumbnails);

Optional:

  • $search if set, the response will be filtered to only contain collections that contain the search term string

  • $page Page number. Default is 1 int

  • $items Number of results per page. Default is 100 int

  • $orderby Determines the ordering of the result within the response. date/title string

  • $includeThumbnails If set to true, the response will include the thumbnail for each collection. Default is false bool


Get Collection

$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 false bool

Create Collection

$client->createCollection($name);

$name Name of the collection string


Update Collection

$client->updateCollection($collectionId, $name);

$collectionId Id of the collection string

$name Updated name of the collection string


Delete Collection

$client->deleteCollection($collectionId);

$collectionId Id of the collection to be deleted string


Returns

All methods return an associative array with the response from the API, or an exception if an error occurs. Check reference for specific responses.

About

A simple PHP library to interact with the bunny.net Stream API.

Resources

License

Stars

Watchers

Forks

Languages