You are here

function brightcove_mm_upload_video in Brightcove Video Connect 6.2

Same name and namespace in other branches
  1. 6 brightcove.media_mover.inc \brightcove_mm_upload_video()

Upload a video to Brightcove through Media Mover.

1 call to brightcove_mm_upload_video()
brightcove_media_mover in ./brightcove.module
Implementation of hook_media_mover().

File

./brightcove.media_mover.inc, line 14
Functions to implement Media Mover behavior for Brightcove.

Code

function brightcove_mm_upload_video($file, $configuration) {
  $title = $configuration['brightcove_mm_default_title'];
  $description = $configuration['brightcove_mm_default_description'];
  $tags = '';
  $node = NULL;
  $length = isset($configuration['brightcove_mm_description_length']) ? $configuration['brightcove_mm_description_length'] : 300;
  if ($file['nid']) {
    $node = node_load($file['nid']);
    if ($node) {
      $title = $node->title;
      if ($body = truncate_utf8(strip_tags($node->body), $length, TRUE, TRUE)) {
        $description = $body;
      }
    }
    else {
      watchdog('brightcove', 'Unable to upload !file to Brightcove, as it belongs to node %nid which has been deleted.', array(
        '!file' => l($file['filepath'], $file['filepath']),
        '%nid' => $file['nid'],
      ), WATCHDOG_ERROR);
    }
  }
  $filepath = media_mover_api_config_current_file($file);
  $fileinfo = pathinfo($filepath);

  // Create an array of required meta data.
  $meta = array(
    'name' => $title,
    'shortDescription' => $description,
    'referenceId' => brightcove_generate_reference(),
  );
  $video_id = brightcove_upload_video($filepath, $meta);
  watchdog('brightcove_mediamover', 'Successfully uploaded video to Brightcove: @video', array(
    '@video' => $title,
    '!id' => $video_id,
  ), WATCHDOG_NOTICE);
  return $title . ' [id:' . $video_id . ']';
}