From 6cd07a81a387b5a7c944c28c405b69dc41d03dac Mon Sep 17 00:00:00 2001 From: mister-ben Date: Thu, 16 May 2013 00:40:18 +0100 Subject: [PATCH 1/2] Added add_captioning and delete_captioning --- README.md | 40 +++++++++++++++++++++- bc-mapi.php | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 137 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 647091b..81c6082 100644 --- a/README.md +++ b/README.md @@ -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' @@ -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 @@ -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 diff --git a/bc-mapi.php b/bc-mapi.php index d68817b..48249f9 100644 --- a/bc-mapi.php +++ b/bc-mapi.php @@ -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 @@ -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'] = strtolower('delete_captions'); + $post['params'] = $params; + + $request['json'] = json_encode($post) . "\n"; + + return $this->putData($request, FALSE); + } + /** * Updates a media asset. * @access Public @@ -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); From 9f3a262f6cae121c5bc915e557ca6ae5b39220f6 Mon Sep 17 00:00:00 2001 From: 45aff0062cf1b0e55a6532b0a513db6be3952d17 Date: Thu, 23 Apr 2015 13:17:39 +0100 Subject: [PATCH 2/2] Fixed delete_captioning --- .gitignore | 3 ++- bc-mapi.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 5782d5e..3e8c2d4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/Icon.png \ No newline at end of file +/Icon.png +/test diff --git a/bc-mapi.php b/bc-mapi.php index 48249f9..963c523 100644 --- a/bc-mapi.php +++ b/bc-mapi.php @@ -808,7 +808,7 @@ public function deleteCaptions($id = NULL, $ref_id = NULL) throw new BCMAPIIdNotProvided($this, self::ERROR_ID_NOT_PROVIDED); } - $post['method'] = strtolower('delete_captions'); + $post['method'] = 'delete_captioning'; $post['params'] = $params; $request['json'] = json_encode($post) . "\n"; @@ -1657,4 +1657,4 @@ class BCMAPISearchTermsNotProvided extends BCMAPIException{} class BCMAPITokenError extends BCMAPIException{} class BCMAPITransactionError extends BCMAPIException{} -?> \ No newline at end of file +?>