ybd-project / ytdl-core

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

Unhandled Rejection: TypeError: Cannot read properties of undefined (reading 'thumbnails') #1

Closed kimgh06 closed 3 months ago

kimgh06 commented 3 months ago

Describe the bug

When I try to get a video via ytdl() on serverless deployments.

Unhandled Rejection: TypeError: Cannot read properties of undefined (reading 'thumbnails')
    at Object.k [as cleanVideoDetails] (/var/task/.next/server/app/api/get_video/route.js:1:28364)
    at P (/var/task/.next/server/app/api/get_video/route.js:3:377)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js process exited with exit status: 128. The logs above can help with debugging the issue.

Debug File

Environment

ybd-project commented 3 months ago

Thank you for your report. We are currently identifying the cause of the bug and fixing it. We would appreciate it if you could provide us with the URL of the video in which the bug is occurring.

ybd-project commented 3 months ago

Version v5.0.4, which appears to fix this bug, is now available. Please try it.

kimgh06 commented 3 months ago

Ok, I tried it and another bug appears.

Unhandled Rejection: InvalidArgumentError: invalid url
    at /var/task/node_modules/undici/index.js:57:13
    at Object.f [as request] (/var/task/.next/server/app/api/get_video/route.js:6:4436)
    at /var/task/.next/server/app/api/get_video/route.js:6:217
    at i.getOrSet (/var/task/.next/server/app/api/get_video/route.js:1:7818)
    at O (/var/task/.next/server/app/api/get_video/route.js:6:172)
    at Object.D [as decipherFormats] (/var/task/.next/server/app/api/get_video/route.js:6:851)
    at L (/var/task/.next/server/app/api/get_video/route.js:3:848)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  code: 'UND_ERR_INVALID_ARG'
}
Node.js process exited with exit status: 128. The logs above can help with debugging the issue.
ybd-project commented 3 months ago

That has been fixed in v5.0.4. Please try a fresh install.

kimgh06 commented 3 months ago

Oh, I will

ybd-project commented 3 months ago

Also, v5.0.4 contains useless logs and data. v5.0.5 should be installed.

kimgh06 commented 3 months ago

Checked it.

ybd-project commented 3 months ago

Checked it.

Is it working?

kimgh06 commented 3 months ago

No, another bug appears on vercel.

Unhandled Rejection: Error: This video is unavailable
    at y (/var/task/.next/server/app/api/get_video/route.js:1:20233)
    at /var/task/.next/server/app/api/get_video/route.js:1:22211
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js process exited with exit status: 128. The logs above can help with debugging the issue.
ybd-project commented 3 months ago

What is the video URL?

kimgh06 commented 3 months ago

And here are warning messages. image

kimgh06 commented 3 months ago

What is the video URL?

https://www.youtube.com/watch?v=oMfMUfgjiLg G N R - Sweet child o' mine

ybd-project commented 3 months ago

And here are warning messages. image

It is normal. Currently, iOS and Android players will output that log because of the error.

ybd-project commented 3 months ago

What is the video URL?

https://www.youtube.com/watch?v=oMfMUfgjiLg G N R - Sweet child o' mine

Do you specify a poToken?

kimgh06 commented 3 months ago

Yes, I did.


const poToken = process.env.NEXT_PUBLIC_PO_TOKEN
const visitorData = process.env.NEXT_PUBLIC_VISITOR_DATA
const stream = ytdl(`https://youtube.com/watch?v=${url}`, {
          agent,
          filter: 'audioonly',
          quality: 'highestaudio',
          format: 'mp3',
          poToken,
          visitorData
        }).on('error', e => {
          console.log(e, 'error at get_video')
          throw e;
        });
ybd-project commented 3 months ago

Try generating a new one. Also, what is specified in the agent?

kimgh06 commented 3 months ago

The agent for cookies.

const cookies = [{
          "domain": ".youtube.com",
          "expirationDate": 1956442831.220501,
          "hostOnly": false,
          "httpOnly": true,
          "name": "__Secure-1PSID",
          "path": "/",
          "sameSite": "unspecified",
          "secure": true,
          "session": false,
          "storeId": "0",
          "value": "g.a000mAgEOqoSd3RlbdBjNWAGnCWmcFtdOYwMaAYNJhfnnAyqaONtGaKgncRerL0dDxPwwp8sGQACgYKAZcSARUSFQHGX2MiaMV9LPBojznMJKAJiJcXyBoVAUF8yKqTxm8uenq1M5aIWXtBZrX00076",
          "id": 2
        },]
        const agent = ytdl.createAgent(cookies)

and I try generate new token and will reply.

ybd-project commented 3 months ago

Please do not specify cookies.

kimgh06 commented 3 months ago

Ok.

kimgh06 commented 3 months ago

I applied my new token on serverless environment variables, but same error appears on logs.

Unhandled Rejection: Error: This video is unavailable
    at y (/var/task/.next/server/app/api/get_video/route.js:1:19869)
    at /var/task/.next/server/app/api/get_video/route.js:1:21847
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js process exited with exit status: 128. The logs above can help with debugging the issue.
ybd-project commented 3 months ago

Glitch and Vercel Functions do not generate errors, so it is possible that the poToken and visitorData are incorrect, either due to geographical factors or because the poToken and visitorData are incorrect.

Vercel: https://ytdl-core-test.vercel.app/api/v3/info/full/?videoUrl=https://youtu.be/oMfMUfgjiLg Glitch: http://marsh-numerous-oak.glitch.me/stream/basic/?ytid=oMfMUfgjiLg

ybd-project commented 3 months ago

The issue has been resolved and the issue is closed.

kimgh06 commented 3 months ago

My Biggest mistake. image image

And I edited my variable. Thanks!

ybd-project commented 3 months ago

That was good to know :)