/**
  * Determines if a video has recieved a callback alerting us that it is transcoded and ready for use
  *
  * @param $video_id
  *
  * @return bool
  */
 public static function is_video_transcoded($video_id)
 {
     $videos = new BC_Videos(new BC_CMS_API(new BC_Accounts()));
     $video = $videos->get_video_by_id($video_id);
     if (!$video) {
         return new WP_Error('brightcove-still-being-transcoded', esc_html__('No video was found', 'brightcove'));
     }
     $is_transcoded = get_post_meta($video->ID, '_brightcove_transcoded', true);
     return '1' === $is_transcoded;
 }
 /**
  * Add in process videos to media query results.
  * Also clear in process videos if they are already returned by brightcove.
  *
  * @param array $videos List of videos.
  *
  * @return array Processed list of videos.
  */
 public function add_in_process_videos($videos)
 {
     $video_ids = wp_list_pluck($videos, 'id');
     $video_post_ids = $this->videos->get_in_progress_videos();
     foreach ($video_post_ids as $video_post_id) {
         $in_process_video_id = BC_Utility::get_sanitized_video_id($video_post_id);
         if (in_array($in_process_video_id, $video_ids)) {
             wp_delete_post($video_post_id, true);
         } else {
             $videos[] = get_post_meta($video_post_id, '_brightcove_video_object', true);
         }
     }
     return $videos;
 }
 public function trigger_background_fetch()
 {
     $this->set_time_limit();
     $videos = new BC_Videos();
     $videos->sync_videos();
     $playlists = new BC_Playlists();
     $playlists->sync_playlists();
 }
 public function brightcove_media_upload()
 {
     global $bc_accounts;
     foreach (array('nonce', 'tags', 'name', 'account') as $parameter) {
         if (!isset($_POST[$parameter])) {
             wp_send_json_error();
         }
     }
     if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], '_bc_ajax_search_nonce')) {
         wp_send_json_error();
     }
     $account_hash = sanitize_text_field($_POST['account']);
     $account = $bc_accounts->set_current_account($account_hash);
     $tags = sanitize_text_field($_POST['tags']);
     $name = sanitize_text_field($_POST['name']);
     if (!is_array($account) || !is_string($name) || '' === $name) {
         $bc_accounts->restore_default_account();
         wp_send_json_error();
     }
     $ingestion_request_status = $this->video_upload->process_uploaded_video($_FILES, $account_hash, $tags, $name);
     $bc_accounts->restore_default_account();
     if (is_wp_error($ingestion_request_status)) {
         wp_send_json_error($ingestion_request_status->get_error_message());
     }
     wp_send_json_success($ingestion_request_status);
     $uploaded_file = wp_handle_upload($_FILES['file'], array('test_form' => false));
     if ($uploaded_file) {
         $uploaded_file['name'] = $name;
         $uploaded_file['tags'] = $tags;
         $uploaded_file['account'] = $account;
         $videos = new BC_Videos($this->cms_api);
         $videos->sync_videos();
         $bc_accounts->restore_default_account();
         wp_send_json_success($uploaded_file);
     } else {
         $bc_accounts->restore_default_account();
         wp_send_json_error(esc_html__('Unable to process file, does it have a valid extension?', 'brightcove'));
     }
 }