Node.js在公司网络中下载多个文件

时间:2018-07-24 13:25:58

标签: node.js http request

我想下载数千个10秒的音频文件。 这些文件由apache服务器管理。如果只有几个文件(例如50s,100s),我可以成功下载,但是当达到500个文件或更大的特定大小时,我会在某些文件上得到 ERR_CONNECTION_REFUSED 。 我正在使用请求模块下载文件,这是我的代码,其中包含路径列表:

function makeRequest(url_path, callback) {
    const url = url_path.url;
    const start = url_path.start;
    const duration = url_path.duration

    var audio_file = url.split('/');
    audio_file = audio_file[audio_file.length - 1];

    const tmp_file_path = path.join(cat_dir, '___' + audio_file);
    const file_path = path.join(cat_dir, audio_file);

    download(url, tmp_file_path, (err) => {
        if (err) {
            callback(err);
        } else {
            var command = 'ffmpeg -ss ' + start + ' -t ' + duration + ' -i ' + tmp_file_path + ' ' + file_path;

            const {
                exec
            } = require('child_process');

            const child = exec(command, function (error, stdout, stderr) {
                if (error !== null) {
                    console.log('Error ffmpeg command : ' + error)
                    callback(error);
                }

                fs.unlink(tmp_file_path, (err) => {
                    if (err)
                        console.log('Error deleting temp file')
                });

                callback();
            });
        }
    });
}

//Limit parallel requests by making 100 requests per time.
async.eachLimit(paths, 100, makeRequest, function (err) {
    if (err)
        main_cb(err);

    console.log('Download files done for : ' + className);
    main_cb(null);
});

我落后于公司代理,这可能是问题所在,但我仍然不知道为什么。

0 个答案:

没有答案
相关问题