skip to Main Content

I am trying to use ytdl-core in an AWS lambda function to upload an .mp4 of a youtube video to an S3 bucket. However, I cannot get ytdl to create a stream with any data in it, so nothing is getting written to the s3 bucket.

Here is the snippet of code I am using to upload the video to the s3 bucket.

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);
    }
  }

I have tried modifying the ytdl call quite a bit to get it to work, such as adding an await, or changing the options but I can’t seem to get anything to work. The streams always return:

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

Right now nothing is getting pushed to the buffer or the s3 bucket when the function is called.

Does ytdl-core even work right now? I see it has not been updated in a year. Is there a better library for nodejs that I could be using?

2

Answers


  1. The package has been depreciated. Use this instead – distubejs/ytdl-core

    Login or Signup to reply.
  2. On August 13, 2024, ytdl-core was officially depreciated by its maintainers. The recommendation is that you move to another package, such as @distube/ytdl-core, which works for most cases.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search