Example How to Create Drupal8 Node Programmatically that contains two media fields
$node = Node::create([
// The node entity bundle.
'type' => 'article',
'langcode' => 'en',
'created' => $created_date,
'changed' => $created_date,
// The user ID.
'uid' => 1,
'moderation_state' => 'published',
'title' => $title,
'field_article_section' => array('target_id'=>$section_target_id),
'field_author' => 111,
'field_article_main_image' => array('image' => [
'target_id' => $file->id()
],
'field_media_in_library'=> 1
),
'field_article_main_video' => array(
'field_media_video_embed_field' => $youtubeID,
'field_media_in_library'=> 1
),
'field_article_body_summary' => [
'summary' => substr(strip_tags($text), 0, 100),
'value' => $text,
'format' => 'rich_text'
]
]);
$node->save();