Skip to content
This repository has been archived by the owner on Jun 11, 2019. It is now read-only.

Added add_captioning and delete_captioning #28

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/Icon.png
/Icon.png
/test
40 changes: 39 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ This example shows how to define additional API call parameters using a key-valu
Find Query - True Find All
--------------------------
Brightcove limits the "find_all_videos" call to 100 results, requiring pagination and numerous API calls. This example shows how to use the findAll() method to do this automatically.
**WARNING: Use very carefully** *
**WARNING: Use very carefully**

// Define our parameters
$params = array(
'video_fields' => 'id,name'
Expand Down Expand Up @@ -241,6 +242,34 @@ This example details how to upload a image to a Brightcove account. This code is

// Upload the image, assign to a video, and save the image asset ID
$id = $bc->createImage('video', $file, $metaData, 123456789);

Create - Captions - Upload file
-------------------------------
This example details how to upload a captions file to a Video Cloud account. This code is handling data that was passed from a form. As with the image example, the temp file will be renamed.

// Move the file out of 'tmp', or rename
rename($_FILES['bcCaptions']['tmp_name'], '/tmp/' . $_FILES['bcCaptions']['name']);
$file = '/tmp/' . $_FILES['bcCaptions']['name'];

// Upload the captions, assign to a video
$id = $bc->createCaptions('video', NULL, $file, NULL, NULL, 123456789);

// Optionally add file size and / or checksum to ensure the file uploaded correctly
$maxsize = filesize($file);
$checksum = md5_file($file);

// Upload using maxsize and checksum, to a video by reference ID
$id = $bc->createCaptions('video', NULL, $file, $maxsize, $checksum, NULL, "my_video");

Create - Captions - With URL
----------------------------
This example details how to add captions to a video in Video Cloud using a remotely hosted captions file.

// Captions URL
$captionsUrl = "http://example.com/captions.xml";

// Add captions to video ID 123456789
$id = $bc->createCaptions('video', $captionsUrl, NULL, NULL, NULL, 123456789);


Create - Playlist
Expand Down Expand Up @@ -282,6 +311,15 @@ This example shows how to delete a video, but the same method will work for a pl

// Delete a 'video' by ID, and cascade the deletion
$bc->delete('video', 123456789, NULL, TRUE);

Delete - Captions
-----------------
This example shows how to delete captions from a video.

// Delete captions by ID
$bc->deleteCaptions(123456789);
// Delete captions by reference ID
$bc->deleteCaptions(NULL, "my_video");


Status - Video Upload
Expand Down
101 changes: 99 additions & 2 deletions bc-mapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,71 @@ public function createImage($type = 'video', $file = NULL, $meta, $id = NULL, $r
return $this->putData($request)->result;
}

/**
* Adds captions by remote URL or by upload to Brightcove.
* @access Public
* @since 2.0.5
* @param string [$type] The type of object to upload image for
* @param string [$url] The URL to the file
* @param string [$file] The location of the temporary file
* @param int [$maxsize] The maximum size of the file
* @param string [$checksum] The MD5 checksum of the file
* @param int [$id] The ID of the video to assign the captions to
* @param string [$ref_id] The reference ID of the video to assign the captions to
* @return mixed The captions asset
*/
public function createCaptions($type = 'video', $url = NULL, $file = NULL, $maxsize = NULL, $checksum = NULL, $id = NULL, $ref_id = NULL)
{
$request = array();
$post = array();
$params = array();
$media = array();

if(strtolower($type) == 'video')
{
$post['method'] = 'add_captioning';
} else {
throw new BCMAPIInvalidType($this, self::ERROR_INVALID_TYPE);
}

if(isset($id))
{
$params[strtolower($type) . '_id'] = $id;
} elseif(isset($ref_id)) {
$params[strtolower($type) . '_reference_id'] = $ref_id;
} else {
throw new BCMAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED);
}

if(isset($url)) {
$media['url'] = $url;
$media['isRemote'] = TRUE;
} elseif (isset($file)) {
$media['filename'] = $file;
$media['displayName'] = basename($file);
if(isset($maxsize)) {
$params['maxsize'] = $maxsize;
}
if(isset($checksum)) {
$params['checksum'] = $checksum;
}
}

$params['token'] = $this->token_write;
$params['caption_source'] = $media;

$post['params'] = $params;

$request['json'] = json_encode($post) . "\n";

if(isset($file))
{
$request['file'] = '@' . $file;
}

return $this->putData($request)->result;
}

/**
* Uploads a logo overlay file to Brightcove.
* @access Public
Expand Down Expand Up @@ -719,6 +784,38 @@ public function deleteOverlay($id = NULL, $ref_id = NULL, $options = NULL)
return $this->putData($request, FALSE);
}

/**
* Deletes captions.
* @access Public
* @since 2.0.5
* @param int [$id] The ID of the captions asset
* @param string [$ref_id] The reference ID of the captions asset
*/
public function deleteCaptions($id = NULL, $ref_id = NULL)
{
$request = array();
$post = array();
$params = array();

$params['token'] = $this->token_write;

if(isset($id))
{
$params['video_id'] = $id;
} elseif(isset($ref_id)) {
$params['video_reference_id'] = $ref_id;
} else {
throw new BCMAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED);
}

$post['method'] = 'delete_captioning';
$post['params'] = $params;

$request['json'] = json_encode($post) . "\n";

return $this->putData($request, FALSE);
}

/**
* Updates a media asset.
* @access Public
Expand Down Expand Up @@ -1317,7 +1414,7 @@ private function getData($url)
* @return object An object containing all API return data
*/
private function putData($request, $return_json = TRUE)
{
{
if(!isset($this->token_write))
{
throw new BCMAPITokenError($this, self::ERROR_WRITE_TOKEN_NOT_PROVIDED);
Expand Down Expand Up @@ -1560,4 +1657,4 @@ class BCMAPISearchTermsNotProvided extends BCMAPIException{}
class BCMAPITokenError extends BCMAPIException{}
class BCMAPITransactionError extends BCMAPIException{}

?>
?>