You are here

function brightcove_upload_video in Brightcove Video Connect 7.2

Same name and namespace in other branches
  1. 6.2 brightcove.module \brightcove_upload_video()
  2. 6 brightcove.module \brightcove_upload_video()
  3. 7.3 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

$path: Filepath to video file.

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

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
ajax_upload_dialog_close_callback in brightcove_field/brightcove_field.module

File

./brightcove.module, line 355
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) {
  global $user;
  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);
      $encode_to = variable_get('brightcove_encode_to', 'MP4');
      $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;
}