/**
  * Endpoint to allow the transcoding session to send updated information about the VideoPress video when it completes a stage of transcoding.
  *
  * @param array $vp_info
  *
  * @return array|bool
  */
 public function update_videopress_info($vp_info)
 {
     $errors = null;
     foreach ($vp_info as $vp_item) {
         $id = $vp_item['post_id'];
         $guid = $vp_item['guid'];
         $attachment = get_post($id);
         if (!$attachment) {
             $errors[] = array('id' => $id, 'error' => 'Post not found');
             continue;
         }
         $attachment->guid = $vp_item['original'];
         $attachment->file = $vp_item['original'];
         wp_update_post($attachment);
         // Update the vp guid and set it to a direct meta property.
         update_post_meta($id, 'videopress_guid', $guid);
         $meta = wp_get_attachment_metadata($attachment->ID);
         $current_poster = get_post_meta($id, '_thumbnail_id');
         $meta['width'] = $vp_item['width'];
         $meta['height'] = $vp_item['height'];
         $meta['original']['url'] = $vp_item['original'];
         $meta['videopress'] = $vp_item;
         $meta['videopress']['url'] = 'https://videopress.com/v/' . $guid;
         if (!$current_poster && isset($vp_item['poster']) && !empty($vp_item['poster'])) {
             $thumbnail_id = videopress_download_poster_image($vp_item['poster'], $id);
             update_post_meta($id, '_thumbnail_id', $thumbnail_id);
         }
         wp_update_attachment_metadata($attachment->ID, $meta);
         // update the meta to tell us that we're processing or complete
         update_post_meta($id, 'videopress_status', videopress_is_finished_processing($attachment->ID) ? 'complete' : 'processing');
     }
     if (count($errors) > 0) {
         return array('errors' => $errors);
     } else {
         return true;
     }
 }
Example #2
0
/**
 * Creates a local media library item of a remote VideoPress video.
 *
 * @param $guid
 * @param int $parent_id
 *
 * @return int|object
 */
function create_local_media_library_for_videopress_guid($guid, $parent_id = 0)
{
    $vp_data = videopress_get_video_details($guid);
    if (!$vp_data || is_wp_error($vp_data)) {
        return $vp_data;
    }
    $args = array('post_date' => $vp_data->upload_date, 'post_title' => wp_kses($vp_data->title, array()), 'post_content' => wp_kses($vp_data->description, array()), 'post_mime_type' => 'video/videopress', 'guid' => sprintf('https://videopress.com/v/%s', $guid));
    $attachment_id = wp_insert_attachment($args, null, $parent_id);
    if (!is_wp_error($attachment_id)) {
        update_post_meta($attachment_id, 'videopress_guid', $guid);
        wp_update_attachment_metadata($attachment_id, array('width' => $vp_data->width, 'height' => $vp_data->height));
        $thumbnail_id = videopress_download_poster_image($vp_data->poster, $attachment_id);
        update_post_meta($attachment_id, '_thumbnail_id', $thumbnail_id);
    }
    return $attachment_id;
}