동시에 100 개 이상의 파일을 다운로드하려고합니다. 그러나 다운로드 기능을 실행할 때 맥북은 윈도우즈에서 다운받을 수는 없지만 (새로운 작업을 실행할 수 없음), 두 가지 경우 모두 유휴 네트워크에서는 다운로드가 진행되지 않는다.Node.JS가 동시에 수백 개의 파일을 다운로드 중
var express = require('express');
var router = express.Router();
var fs = require('fs');
var youtubedl = require('youtube-dl');
var links = require('../models/Links');
router.get('/', function (req, res, next) {
links.find({dlStatus: false}, function (err, docs) {
if (err) {
console.log(err);
res.end();
} else if (!docs) {
console.log('No incomplete downloads!');
res.end();
} else {
for (var i = 0; i < docs.length; i++) {
//todo scraping
var video = youtubedl(docs[i].url, [], {cwd: __dirname});
// Will be called when the download starts.
video.on('info', function (info) {
console.log('Download started');
console.log(info);
});
video.pipe(fs.createWriteStream('./downloads/' + docs[i].id + '-' + i + '.mp4'));
video.on('complete', function complete(info) {
links.findOneAndUpdate({url: info.webpage_url}, {dlStatus: true}, function (err, doc) {
if (err)console.log(err);
else console.log('Download completed!')
});
});
}
}
});
});
module.exports = router;
지금 누군가가 나를 여기에 도와주세요 수 있습니다 여기에
내 다운로드 모듈입니다? 파일을 다운로드 할 때 this 모듈을 사용하고 있습니다.
단일 다운로드 작업 중 ...? – vkstack
네, 동시에 5 번 다운로드를 시도했는데, 너무 효과가있었습니다. 이제 101 번으로 시도하고 있습니다. –
async.That을 사용하여 시도해보십시오. – vkstack