ybd-project / ytdl-core

Fast and secure YouTube downloader for JavaScript and TypeScript
MIT License
28 stars 5 forks source link

Web Creator, iOS, and Android player APIs all returned errors #5

Closed hicay closed 3 months ago

hicay commented 3 months ago

Describe the bug

Works locally fine! But not in AWS Lambda for download https://github.com/ybd-project/ytdl-core/blob/2062b0934c5aea2296fc43b619e86cc29a6ad329/src/info.ts#L522

 const videoReadableStream = ytdl(
      `https://www.youtube.com/watch?v=${videoId}`,
      {
        filter: 'audioandvideo',
        quality: 'lowest',
      }
);

videoReadableStream
        .pipe(writeStream)
        .on('finish', async () => {
          this.logger.log(`VIDEO_DOWNLOAD_FINISHED`);
...
...
...

Error Details (Log)

{
    "errorType": "Runtime.UnhandledPromiseRejection",
    "errorMessage": "Error: Web Creator, iOS, and Android player APIs all returned errors.",
    "reason": {
        "errorType": "Error",
        "errorMessage": "Web Creator, iOS, and Android player APIs all returned errors.",
        "stack": [
            "Error: Web Creator, iOS, and Android player APIs all returned errors.",
            "    at _getBasicInfo (/var/task/dist/main.js:265353:15)",
            "    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"
        ]
    },
    "promise": {},
    "stack": [
        "Runtime.UnhandledPromiseRejection: Error: Web Creator, iOS, and Android player APIs all returned errors.",
        "    at process.<anonymous> (file:///var/runtime/index.mjs:1276:17)",
        "    at process.emit (node:events:529:35)",
        "    at process.emit (node:domain:489:12)",
        "    at emit (node:internal/process/promises:149:20)",
        "    at processPromiseRejections (node:internal/process/promises:283:27)",
        "    at process.processTicksAndRejections (node:internal/process/task_queues:96:32)"
    ]
}

Environment

ybd-project commented 3 months ago

Specify poToken and visitorData as the second argument of the ytdl function.

hicay commented 3 months ago

Thannk you @ybd-project . I tried different type of solutions and fixed it. Best one is;

const info = await ytdl.getInfo(
      `https://www.youtube.com/watch?v=${videoId}`,
      {
        agent,
        poToken: PO_TOKEN,
        visitorData: VISITOR_DATA,
      },
    );
// Get info first and download from info
const videoReadableStream = ytdl.downloadFromInfo(info, {
      filter: 'audioandvideo',
      quality: 'lowest',
      poToken: PO_TOKEN,
      visitorData: VISITOR_DATA,
    });