the usual place is in functions.php in your theme or child theme (recommended as updates will overwrite custom code in your theme) or a plugin you create yourself (pluginname.php).
I have put the best way to achieve this below, its not client side at all but I believe this will suit you better. Basically on every page load the code will run and upload the next 50 videos (if timing out reduce the figure below -- see comments) (you should remove the code when all videos are uploaded).
Also excuse me if there are any errors, typed this out on a txt file. Also i dont know the structure of the json returned, i dont have a api key to check, you will need to update the correct structure in the for loop to get the data you want...
function upload_videos(){
if(!get_option( 'vid_count' ) ){
$x=0;
update_option( 'vid_count', $x );
} else {
$x= (int) get_option('vid_count');
}
//might as well cache the file to speed things up
if( !file_exists ( 'videos.json' )){
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, 'https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=5000&playlistId=UUbRrCTEldKci2yWosUukSQQ&key=APIKEY');
$json = curl_exec($ch);
curl_close($ch);
$videos = fopen("videos.json", "w") or die("Unable to open file!");
fwrite($videos, $json);
fclose($videos);
unset($videos);
}
$videos = fopen("videos.json", "r");
$videos = json_decode($videos);
//get the structure of the array here and update the foreach loop to the right place in the object...
//remove this code when ready.....
var_dump($videos);
exit;
//end remove.....
/*
remember to update to the correct values....
we will do 50 at a time
*/
$max= $x+50; // adjust 50 downwards if needed
if($max > count( $videos['list'] ) )
$max= count( $videos['list'] );
if($max > $x)
return;
update_option('vid_count', $max );
for($v=$x; $v<=$max; $v++){
$id= wp_insert_post(
array(
'post_status'=>'publish',
'post_type'=>'video', //higher recommended to create a cpt and post template for this..
'post_title'=> $videos['list'][$v]->title, // sample --- dont know the format of the returned object
'content'=> 'whatever you want or html for the video, etc................'
));
//save the url into the metadata of the post....we can use this in templates to show the video....
update_post_meta($id, '_vid_url', $videos['list'][$v]->video_url);// sample --- dont know the format of the returned object
}
}
add_action('init', 'upload_videos');