fent / node-ytdl-core

YouTube video downloader in javascript.
MIT License
4.51k stars 798 forks source link

410 status error #1284

Open Jagmesh opened 5 months ago

Jagmesh commented 5 months ago

Greetings!

I have, and it seems many of you too, a 410 Error.

This is the request that fails

    const videoInfo = await ytdl
      .getBasicInfo(url, {
        requestOptions: {
          headers: {
            cookie: this.configService.get<string>('YOUTUBE_REQUEST_COOKIES'),
            'x-youtube-identity-token': this.configService.get<string>('YOUTUBE_ID_TOKEN'),
          },
        },
      })
  1. There was no problem when I started to use ytdl and downloading videos/getting info. But after sometime, about a week, all requests began failing with 410 code error ([2024-05-03 21:58:40]: [ERROR][YOUTUBE_DOWNLOAD] Error: Status code: 410)
  2. Interesting part is that it doesn't work with any video I try. But everything works fine, when I ran an app on my PC. But when I upload it to the server, every .getBasicInfo request fails
  3. I tried to add COOKIE (as shown here). And it helped! But not for long. After 5-6 requests and ~hour passed, it began to respond with 410 again

So, I'm starting to suspect, that it is all due to IP. When I'm using the same app on my PC it all works, but it doesnt work on a remote server with a static IP

Could this be the problem? If yes, is there any suggestions on how it can be avoided?

"ytdl-core": "^4.11.5"

Full error (the same on both .getBasicInfo or on the ytdl(url) itself)

Error: Input stream error: Status code: 410
    at PassThrough.<anonymous> (/app/node_modules/fluent-ffmpeg-7/lib/processor.js:451:34)
    at PassThrough.emit (node:events:518:28)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  inputStreamError: MinigetError: Status code: 410
      at ClientRequest.<anonymous> (/app/node_modules/miniget/dist/index.js:206:27)
      at Object.onceWrapper (node:events:633:26)
      at ClientRequest.emit (node:events:518:28)
      at HTTPParser.parserOnIncomingClient (node:_http_client:698:27)
      at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)
      at TLSSocket.socketOnData (node:_http_client:540:22)
      at TLSSocket.emit (node:events:518:28)
      at addChunk (node:internal/streams/readable:559:12)
      at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
      at Readable.push (node:internal/streams/readable:390:5)
      at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23) {
    statusCode: 410
  }
}
Jagmesh commented 5 months ago

And I have refreshed COOKIES and it seems to be working again. At least for now

That's some black magic here

Jagmesh commented 5 months ago

After I refreshed COOKIES, requests worked for sometime. But now I am havin a 410 error again

Maybe anyone faced a same problem? What can be done to avoid this 410 error permanently?

Finalet commented 5 months ago

Experiencing the same issue. Works fine on a local machine, but throws 410 when deployed to a server

Jagmesh commented 5 months ago

Experiencing the same issue. Works fine on a local machine, but throws 410 when deployed to a server

Have you tesed with cookies added/removed?

cemalct commented 5 months ago

I'm having this as well, any work around?

Jagmesh commented 5 months ago

@cemalct I have been actively testing and have come to a conclusion that it has nothing to do with the ytdl-core package itself. I have tested diffrent libs and also use yt-dlp natively and all of them result in the same way: the 410 Error

So I believe that it's the problem with Youtube itself

And yet maybe anyone has any ideas for a work around? :D

The cookies stuff is working quite unstable

cemalct commented 5 months ago

then i think the only way to download is, streaming video byte byte into a file

Finalet commented 5 months ago

It seems like YouTube is just getting tired of our requests. Using ytdl through a proxy solved the issue.

aymenitc commented 4 months ago

It seems like YouTube is just getting tired of our requests. Using ytdl through a proxy solved the issue.

Can you plz give an examble code how to do it

timursevimli commented 12 hours ago

Send requests via proxy or use vpn