'PT35M13S', // בcp-webinar
'pB5YojrQOdc' => 'PT18S', // strategic-planning-3
'6IyxaiHVjHM' => 'PT1M17S', // ceo-coaching (EN)
'EU4plNVcKz8' => 'PT4M2S', // building-innovation
'UMAMsKUs5es' => 'PT55M29S', // improve-your-supply-chain
'HOdRMe15blo' => 'PT1M11S', // strategy-planing-now
'n_DhhevtfJI' => 'PT22M7S', // selling-your-business
'xqC_y4DRZM8' => 'PT49S', // growth-and-change
'gEsYin5WQM8' => 'PT40M49S', // business-consultant-for-quick-growth
'4gVUoKWV9IU' => 'PT6M16S', // how-to-get-to-finnacial-freedom
'QDGgMOoUc40' => 'PT2M13S', // ceo-coaching (HE) – TAB Quicksand
];
foreach ( $schema_output as &$block ) {
if ( ! is_array( $block ) ) continue;
// ItemList containing VideoObjects
if ( isset( $block['@type'] ) && $block['@type'] === 'ItemList' ) {
if ( ! empty( $block['itemListElement'] ) && is_array( $block['itemListElement'] ) ) {
foreach ( $block['itemListElement'] as &$item ) {
if ( isset( $item['@type'] ) && $item['@type'] === 'VideoObject' ) {
$item = nmk_enrich_video( $item, $duration_map );
}
}
unset( $item );
}
}
// Standalone VideoObject
if ( isset( $block['@type'] ) && $block['@type'] === 'VideoObject' ) {
$block = nmk_enrich_video( $block, $duration_map );
}
}
unset( $block );
return $schema_output;
}
function nmk_enrich_video( $video, $duration_map ) {
// Extract YouTube video ID from any URL field
$vid_id = ";
$url_fields = [ ’embedUrl', 'contentUrl', 'url' ];
foreach ( $url_fields as $field ) {
if ( empty( $video[ $field ] ) ) continue;
if ( preg_match(
'/(?:youtube(?:-nocookie)?.com/(?:embed/|watch?v=)|youtu.be/)([A-Za-z0-9_-]{11})/i',
$video[ $field ],
$m
) ) {
$vid_id = $m[1];
break;
}
}
if ( ! $vid_id ) return $video;
// 1. Inject duration if missing or not ISO 8601
if ( isset( $duration_map[ $vid_id ] ) ) {
$cur = $video['duration'] ?? ";
if ( empty( $cur ) || ! preg_match( '/^PTd/', $cur ) ) {
$video['duration'] = $duration_map[ $vid_id ];
}
}
// 2. Ensure thumbnailUrl is multi-resolution array (nmk_vidclean protocol)
if ( empty( $video['thumbnailUrl'] ) || is_string( $video['thumbnailUrl'] ) ) {
$video['thumbnailUrl'] = [
"https://i.ytimg.com/vi/{$vid_id}/maxresdefault.jpg",
"https://i.ytimg.com/vi/{$vid_id}/hqdefault.jpg",
"https://i.ytimg.com/vi/{$vid_id}/mqdefault.jpg",
];
}
// 3. Standardize embedUrl to /embed/ format
if ( isset( $video[’embedUrl'] ) ) {
$video[’embedUrl'] = "https://www.youtube.com/embed/{$vid_id}";
}
// 4. Standardize contentUrl
if ( isset( $video['contentUrl'] ) ) {
$video['contentUrl'] = "https://www.youtube.com/watch?v={$vid_id}";
}
return $video;
}
}