/** * Upload a video for processing * * Sends the URL of a video's master copy to the Dynamic Ingest API for processing. * * @since 1.0.0 * * @param string $video_id the ID of the video we're adding the master to * @param string $video_url the url of the video stored locally * @param string $profile the profile to use for processing * @param bool $callback true to specify a local callback url or false * * @return string|bool the id of the ingest request or false on failure */ public function video_upload($video_id, $video_url, $profile = 'balanced-high-definition', $callback = true) { $data = array('profile' => sanitize_text_field($profile)); $data['master'] = array('url' => esc_url_raw($video_url)); if (true === $callback) { $auth = BC_Utility::get_auth_key_for_id($video_id); $data['callbacks'] = array(get_admin_url() . 'admin-ajax.php?action=bc_ingest&id=' . $video_id . '&auth=' . $auth); } return $this->send_request(esc_url_raw(self::DI_BASE_URL . $this->get_account_id() . '/videos/' . $video_id . '/ingest-requests'), 'POST', $data); }
/** * We receive a post with JSON (nothing in $_POST) * $_GET['id'] must contain the video ID * $_GET['auth'] must contain the anti spoof hash. */ public function ingest_callback() { $json = file_get_contents('php://input'); $decoded = json_decode($json, true); if (!isset($decoded['entity']) || !isset($_GET['id']) || !isset($_GET['auth']) || "SUCCESS" !== $decoded['status']) { exit; } $video_id = BC_Utility::sanitize_and_generate_meta_video_id($_GET['id']); $valid_auth = BC_Utility::get_auth_key_for_id($video_id); if (BC_Utility::sanitize_and_generate_meta_video_id($decoded['entity']) !== $video_id) { // We get lots of callbacks so we want to make sure that it's not // one of the transcodes that has completed, but rather this video. exit; } if ($valid_auth !== $_GET['auth']) { // Someone was spoofing callbacks? exit; } BC_Utility::remove_pending_uploads($video_id); // @todo: Set video uploaded state as complete. $this->trigger_background_fetch(); exit; }