You are here

function scald_dailymotion_register in Scald: Media Management made easy 6

Creates an atom based on a DailyMotion video id or an object containing the video informations..

Parameters

$video: Unique identifier of the video on dailymotion, or object returned by scald_dailymotion_video.

Return value

integer Unique identifier of the new atom

2 calls to scald_dailymotion_register()
scald_dailymotion_cron in scald_dailymotion/scald_dailymotion.module
Implements hook_cron.
scald_dailymotion_search_form_submit in scald_dailymotion/scald_dailymotion.pages.inc
Handlers import form submission.

File

scald_dailymotion/scald_dailymotion.module, line 119
Defines a DailyMotion provider for Scald.

Code

function scald_dailymotion_register($video) {
  global $user;

  // Fetch the needed informations from DailyMotion
  if (is_object($video)) {
    $infos = $video;
  }
  else {
    $infos = scald_dailymotion_video($video);
  }

  // Check if the video has already been imported to prevent duplicated
  $old = scald_dailymotion_already_imported($infos->id);
  if ($old) {
    return $old;
  }

  // Download a copy of the video thumbnail. This makes it possible
  // to do interesting things when used with ImageCache for example.
  $thumb = drupal_http_request($infos->thumbnail['src']);
  $dir = file_directory_path() . '/dailymotion';
  if ($thumb->code == 200 && file_check_directory($dir, FILE_CREATE_DIRECTORY)) {
    $dest = $dir . '/' . $infos->id . '.jpg';
    $file = file_save_data($thumb->data, $dest);
  }

  // Create an atom
  $atom = new stdClass();
  $atom->type = 'video';
  $atom->provider = 'scald_dailymotion';
  $atom->base_id = $infos->id;
  $atom->publisher = $user->uid;
  $atom->title = $infos->title;
  $aid = scald_author_get_id(array(
    'name' => $infos->author,
    'url' => 'dailymotion://user/' . $info->author,
  ));
  $atom->authors = array(
    $aid,
  );

  // And save it
  $atom_sid = scald_register_atom((array) $atom);

  // Finally, return this id
  return $atom_sid;
}