I’m trying to call the following function to console.log the time and caption. I’m still having difficulty with ‘return’. The function works perfectly, it just doesn’t return time and caption values to the console log function. Thank you for your help!
console.log(youtubevideo('fakeytid'));
function youtubevideo(videoid) {
var request = require('request');
var options = {
'method': 'GET',
'url': 'https://www.googleapis.com/youtube/v3/videos?id='+videoid+'&part=contentDetails&key=' + 'APIKEY',
'headers': {
}
};
//Return time:
request(options, function (error, response) {
if (error) throw new Error(error);
responsebody = response.body;
var json = JSON.parse(responsebody);
var caption = json.items[0].contentDetails.caption;
var time = json.items[0].contentDetails.duration
var time = json.items[0].contentDetails.duration;
var time = time.replace(/PT|S/g, '');
var time = time.split(/M|H/);
var time = time.map(function(item) {
return parseInt(item, 10);
});
var time = time[0]*60 + time[1];
return time, caption
});
return time, caption
}