我尝试下载 YouTube 视频,但出现错误 410,有人知道如何修复吗?我使用的是 20.04 版本
使用节点下载
代码:
const fs = require('fs');
const ytdl = require('ytdl-core');
const stream = ytdl('https://www.youtube.com/watch?v=uVdEvxUlU0s', { filter: 'audioonly' }).pipe(fs.createWriteStream('video.mp3'));
console.log('Starting Download');
stream.on('data', chunk => {
console.log('downloaded', chunk.length);
});
stream.on('error', err => {
console.error(err);
});
stream.on('end', () => {
console.log('Finished');
});
日志:
Starting Download
/root/youtube/node_modules/miniget/dist/index.js:206
let err = new Miniget.MinigetError(`Status code: ${res.statusCode}`, res.statusCode);
^
MinigetError: Status code: 410
at ClientRequest.<anonymous> (/root/youtube/node_modules/miniget/dist/index.js:206:27)
at Object.onceWrapper (node:events:628:26)
at ClientRequest.emit (node:events:513:28)
at HTTPParser.parserOnIncomingClient (node:_http_client:701:27)
at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)
at TLSSocket.socketOnData (node:_http_client:542:22)
at TLSSocket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
Emitted 'error' event on PassThrough instance at:
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
statusCode: 410
}
Node.js v18.15.0