Answer the question
In order to leave comments, you need to log in
Request and async in Node.JS What did I miss?
I'm trying to get the sizes of video clips from youtube:
var async = require('async')
var request = require('request');
var moveInfoLink = "http://www.youtube.com/get_video_info?video_id=",
moveLinkSufix = "&asv=3&el=detailpage&hl=en_US",
movieWrapperLink = "*********";
var answer = '';
var formatList = new Array();
var movieLinks = new Array();
function getYouTubeAnswer()
{
return new Promise(function(resolve)
{
........
});
}
function parseYouTubeData()
{
...............
}
var getFileSize = function(item, callback)
{
if(item['resolution'].match(/x720|x360/))
{
request
(
{
method: 'HEAD',
url: item['url']
},
function(err, resp, body)
{
console.log(resp.headers['content-length']);
callback(false, resp.headers['content-length']);
}
);
}
}
console.log(`Запускаемся`);
getYouTubeAnswer().then(function()
{
parseYouTubeData();
console.log(`Получаем размеры файлов`);
async.each
(
movieLinks,
getFileSize,
function(err, result)
{ // Вот сюда управление почему-то не попадает
if(err)
{
console.log('Какая-то ошибка');
console.log(err);
}
else
{
console.log('Закончили работу');
console.log(result);
}
}
);
});
Answer the question
In order to leave comments, you need to log in
Did you read the async documentation correctly?
each(arr, iteratee, [callback])
getFileSize is an iterator? does it return a callback on execution?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question