ytdl-core 返回一个没有任何内容的流

问题描述 投票:0回答:1

我尝试在 AWS lambda 函数中使用 ytdl-core 将 YouTube 视频的 .mp4 上传到 S3 存储桶。但是,我无法让 ytdl 创建包含任何数据的流,因此没有任何内容写入 s3 存储桶。

这是我用来将视频上传到 s3 存储桶的代码片段。

if (video_url.includes("youtube")){
    const passthrough = new PassThrough();
    const video_file = ytdl(video_url, { quality: '18' });
    const pipe_response = video_file.pipe(passthrough);
    console.log(pipe_response);
    const key_name = id.concat('.', 'mp4');
    const s3Client = new S3Client({ region: REGION });
    const upload = new Upload({
      client: s3Client,
      params: {
        Bucket: BUCKET_NAME,
        Key: key_name,
        Body: passthrough
      },
      partSize: 1024*1024*64,
      leavePartsOnError: false,
    });
    try {
      const response = await upload.done();
      console.log(response);
      console.log('Upload done');
    } catch (err) {
      console.error('Error uploading video:', err);
    }
  }

我尝试对 ytdl 调用进行相当多的修改以使其正常工作,例如添加等待或更改选项,但我似乎无法让任何东西正常工作。流总是返回:

PassThrough {
  _readableState: ReadableState {
    state: 6160,
    highWaterMark: 524288,
    buffer: BufferList { head: null, tail: null, length: 0 },
    length: 0,

现在,当调用该函数时,没有任何内容被推送到缓冲区或 s3 存储桶。

ytdl-core 现在还能用吗?我看已经有一年没有更新了。我可以使用更好的 Nodejs 库吗?

node.js amazon-web-services amazon-s3 aws-lambda ytdl
1个回答
0
投票

套餐已折旧。改用这个 - distubejs/ytdl-core

© www.soinside.com 2019 - 2024. All rights reserved.