function _update_fields_with_file_data($video_id, $remote_url)
 {
     $this->remove_existing_video($this->manager->get_value('entry_id'));
     $this->manager->set_value('transcoding_status', 'converting');
     $this->manager->set_value('entry_id', $video_id);
     $this->manager->set_value('integration_library', 'vimeo');
     $this->manager->set_value('media_publication_datetime', date('Y-m-d H:i:s'));
     // update the duration field of the media work.
     $data_obj = $this->shim->get_video_data($this->manager->get_value('entry_id'));
     if ($data_obj) {
         $this->manager->set_value('media_duration', format_seconds_as_human_readable(intval($data_obj->duration)));
     }
     if ($remote_url) {
         $this->manager->set_value('tmp_file_name', '');
     }
 }
 /**
  * This callback generates the thumbnail image for the video.  It also updates some metadata 
  * such as duration for the entity.
  */
 public function _process_callback()
 {
     $username = reason_check_authentication();
     reason_update_entity($this->manager->get_value('id'), get_user_id($username), array('media_publication_datetime' => date('Y-m-d H:i:s')), false);
     if ($this->manager->get_value('youtube_url') && $this->manager->get_value('entry_id') != $this->original_entry_id) {
         // create image file in the youtube temp directory
         $tmp_path = YoutubeShim::get_temp_dir() . 'tmp_thumbnail_' . $this->manager->get_value('id');
         $f = fopen($tmp_path, 'w');
         $image_url = $this->shim->get_thumbnail($this->manager->get_value('entry_id'));
         $contents = get_reason_url_contents($image_url);
         fwrite($f, $contents);
         fclose($f);
         // Create a reason entity out of the temp image file
         if (!empty($tmp_path) and file_exists($tmp_path) && $username) {
             if ($id = $this->create_image_entity($username)) {
                 $im = new ImageManager();
                 $im->thumbnail_width = REASON_STANDARD_MAX_THUMBNAIL_WIDTH;
                 $im->thumbnail_height = REASON_STANDARD_MAX_THUMBNAIL_HEIGHT;
                 $im->max_width = REASON_STANDARD_MAX_IMAGE_WIDTH;
                 $im->max_height = REASON_STANDARD_MAX_IMAGE_HEIGHT;
                 $im->load_by_type(id_of('image'), $id, get_user_id($username));
                 $im->handle_standard_image($id, $tmp_path);
                 $im->create_default_thumbnail($id);
                 $values = array();
                 foreach ($im->get_element_names() as $element_name) {
                     $values[$element_name] = $im->get_value($element_name);
                 }
                 reason_update_entity($id, get_user_id($username), $values, false);
                 // Remove any existing association with an image and replace it with this new one
                 delete_relationships(array('entity_a' => $this->manager->get_value('id'), 'type' => relationship_id_of('av_to_primary_image')));
                 create_relationship($this->manager->get_value('id'), $id, relationship_id_of('av_to_primary_image'));
             }
         }
         // update the duration field of the media work.
         $data_obj = $this->shim->get_video_data($this->manager->get_value('entry_id'));
         if (!empty($data_obj)) {
             reason_update_entity($this->manager->get_value('id'), get_user_id($username), array('media_duration' => format_seconds_as_human_readable(intval($data_obj->length))), false);
         }
     }
 }
function get_human_readable_duration($duration)
{
    $seconds = intval($duration) / 1000.0;
    return format_seconds_as_human_readable($seconds);
}
function update_metadata($media_work, $shim)
{
    // update the duration field of the media work.
    $data_obj = $shim->get_video_data($media_work->get_value('entry_id'));
    if ($data_obj && property_exists($data_obj, 'duration') && property_exists($data_obj, 'thumbnails') && !$data_obj->is_transcoding) {
        reason_update_entity($media_work->get_value('id'), $media_work->get_value('created_by'), array('transcoding_status' => 'ready', 'media_duration' => format_seconds_as_human_readable(intval($data_obj->duration))), false);
        return true;
    }
    return false;
}