You are here

function brightcove_upload_video in Brightcove Video Connect 7.3

Same name and namespace in other branches
  1. 6.2 brightcove.module \brightcove_upload_video()
  2. 6 brightcove.module \brightcove_upload_video()
  3. 7.2 brightcove.module \brightcove_upload_video()
  4. 7.4 brightcove.module \brightcove_upload_video()
  5. 7.5 brightcove.module \brightcove_upload_video()

Upload video to Brightcove.

Parameters

string $path: Filepath to video file.

array $meta: Meta data array. Required values: array( 'name' => 'video name', 'shortDescription' => 'short description', );

string|NULL $encode_to: Container format to encode the video to. Possible values: "FLV", "MP4"

Return value

int|NULL Brightcove video id or NULL if not found.

See also

http://support.brightcove.com/en/docs/media-api-objects-reference#Video

2 calls to brightcove_upload_video()
ajax_brightcove_media_upload_callback in brightcove_media/brightcove_media.module
Ajax callback for upload form
_brightcove_upload_form_callback in ./brightcove.module
Upload the submitted video.

File

./brightcove.module, line 679
Brightcove module is an integration layer between any modules using Brightcove API. It makes all necessary checks for the API and makes settings available to the user.

Code

function brightcove_upload_video($path, $meta, $encode_to = NULL) {
  global $user;
  if ($encode_to === NULL) {
    $encode_to = variable_get('brightcove_encode_to', 'MP4');
  }
  if (empty($meta['name'])) {
    $meta['name'] = t('Video');
  }
  if (empty($meta['shortDescription'])) {
    $meta['shortDescription'] = t('Short Description');
  }
  $user_attribute = variable_get('brightcove_user_field', '');
  if (!empty($user_attribute)) {
    $meta['customFields'] = array(
      $user_attribute => $user->name,
    );
  }
  $bc = brightcove_initialize();
  try {
    $options = array();
    preg_match('/\\.(f4a|f4b|f4v|f4p|flv)$/i', $path, $invalid_extensions);
    if (!isset($invalid_extensions[1])) {

      // retrieve upload settings
      $create_multiple_renditions = (bool) variable_get('brightcove_create_multiple_renditions', TRUE);
      $preserve_source_rendition = (bool) variable_get('brightcove_preserve_source_rendition', 0);
      $options = array(
        'create_multiple_renditions' => $create_multiple_renditions,
        'encode_to' => $encode_to,
        'preserve_source_rendition' => $preserve_source_rendition,
      );
    }
    $id = $bc
      ->createMedia('video', $path, $meta, $options);
  } catch (Exception $error) {
    drupal_set_message(t('Video upload to Brightcove failed. Error: @error', array(
      '@error' => $error,
    )), 'error');
    return NULL;
  }
  return $id;
}