Node-ytdl-core: Preventing Error 429: Too Many Requests

Created on 26 May 2020  路  48Comments  路  Source: fent/node-ytdl-core

I'm using ytdl-core from a browser, using browserify. Cross-domain requests are not allowed, so I'm using CORS Anywhere proxy to bypass CORS Header related errors.

After a few requests, I'm getting error 429s from YouTube, saying that I may be making too many requests (not really, one or two per minute at the most, downloading a webm stream). The method crashes afterward and won't do any additional requests.

Google seems to block the entire origin domain, so it won't work for anyone with the same origin header (I haven't verified yet).

There are multiple things wrong:

  • How can I prevent this? I'd like to have some sort of rate throttling so it doesn't incur into 429 errors. It renders ytdl completely unusable for a long time (no exact amount, last time it was more than an hour)
  • No error is thrown by ytdl whatsoever. This is not good because there is no way to handle the error. The callback never gets invoked, and error handlers are never called.

Code example:

const ytdl = require('ytdl-core');
const concat = require('concat-stream');
 var concatStream = concat((arrayBuffer) =>
        {
            console.log('file downloaded');
           // Processing of video blob goes here...
        });

        var ytstream = ytdl(YOUTUBE_VIDEOURL,
            {
                requestOptions: {
                    transform: (parsed) =>
                    {  
                        var parsedHeaders = parsed.headers;
                        return {
                            host: 'cors-anywhere.herokuapp.com/', 
                            path: "http://youtube.com" + parsed.path,
                            maxRedirects: 10,
                            headers: parsedHeaders
                        }
                    },
                },
            });

        ytstream.on('error', function(e)
        {
           // Never gets called
        })
        .pipe(concatStream);
bug

Most helpful comment

  • How can I prevent this? I'd like to have some sort of rate throttling so it doesn't incur into 429 errors. It renders ytdl completely unusable for a long time (no exact amount, last time it was more than an hour)

I'm going to be adding throttling so that it doesn't make requests too fast to prevent these errors

  • No error is thrown by ytdl whatsoever. This is not good because there is no way to handle the error. The callback never gets invoked, and error handlers are never called.

will be fixed soon

All 48 comments

  • How can I prevent this? I'd like to have some sort of rate throttling so it doesn't incur into 429 errors. It renders ytdl completely unusable for a long time (no exact amount, last time it was more than an hour)

I'm going to be adding throttling so that it doesn't make requests too fast to prevent these errors

  • No error is thrown by ytdl whatsoever. This is not good because there is no way to handle the error. The callback never gets invoked, and error handlers are never called.

will be fixed soon

I am a fairly new JS developer I come from old school C/C++ background and I am seriously really confused with this.

I am trying to get ytdl-core to pass cookies to miniget because this is a solution for the 429 error. I have tested using cookies with youtube-dl and it works perfectly but I want to make it work with ytdl-core because that other project is using deprecated libraries and I don't feel good with that.

const ytdl = require('ytdl-core');
const cookiefile = require('cookiefile');

const cookiemap = new cookiefile.CookieMap('cookies.txt');
const cookies = cookiemap.toRequestHeader().replace ('Cookie: ','');

stream = ytdl(URL, {
    quality: 'highestaudio',
    highWaterMark: 1024 * 1024 * 1024,
    requestOptions: {
        headers: {
            'Cookie': cookies
        }
    }
});

cookies.txt is a cookies export from chrome.
I have also modified miniget's index.js so that it prints out variable "parsed" on line 126 just so that I can see what I'm doing.
When I run the above code, I get the following output for parsed:

Url {
  protocol: 'https:',
  slashes: true,
  auth: null,
  host: 'www.youtube.com',
  port: null,
  hostname: 'www.youtube.com',
  hash: null,
  search: '?v=Rbm6GXllBiw&hl=en&bpctr=1590461824&pbj=1',
  query: 'v=Rbm6GXllBiw&hl=en&bpctr=1590461824&pbj=1',
  pathname: '/watch',
  path: '/watch?v=Rbm6GXllBiw&hl=en&bpctr=1590461824&pbj=1',
  href: 'https://www.youtube.com/watch?v=Rbm6GXllBiw&hl=en&bpctr=1590461824&pbj=1',
  maxRedirects: 2,
  maxRetries: 2,
  maxReconnects: 0,
  backoff: { inc: 100, max: 10000 },
  headers: {
    Cookie: 'my-cookies-here',
    'x-youtube-client-name': '1',
    'x-youtube-client-version': '2.20191008.04.01'
  }
}

Under headers, "cookie" is not inside quotes just like the rest of the headers and I guess it's natural that I get the following error:

(node:7309) UnhandledPromiseRejectionWarning: Error: Error parsing info: JSON.parse(...).reduce is not a function
    at exports.getBasicInfo (/home/user/project/node_modules/ytdl-core/lib/info.js:43:11)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async Object.exports.<computed> [as getBasicInfo] (/home/user/project/node_modules/ytdl-core/lib/info.js:297:18)
    at async exports.getFullInfo (/home/user/project/node_modules/ytdl-core/lib/info.js:188:14)
    at async Object.exports.<computed> [as getFullInfo] (/home/user/project/node_modules/ytdl-core/lib/info.js:297:18)

But when I use any other header name (for example 'custom-header', it gets inserted correctly like this:

Url {
  protocol: 'https:',
  slashes: true,
  auth: null,
  host: 'www.youtube.com',
  port: null,
  hostname: 'www.youtube.com',
  hash: null,
  search: '?v=TnAgc1kgvLc&hl=en&bpctr=1590462647&pbj=1',
  query: 'v=TnAgc1kgvLc&hl=en&bpctr=1590462647&pbj=1',
  pathname: '/watch',
  path: '/watch?v=TnAgc1kgvLc&hl=en&bpctr=1590462647&pbj=1',
  href: 'https://www.youtube.com/watch?v=TnAgc1kgvLc&hl=en&bpctr=1590462647&pbj=1',
  maxRedirects: 2,
  maxRetries: 2,
  maxReconnects: 0,
  backoff: { inc: 100, max: 10000 },
  headers: {
    'custom-header': 'my-cookies-here',
    'x-youtube-client-name': '1',
    'x-youtube-client-version': '2.20191008.04.01'
  }
}

The above does not produce a JSON.parse error, it produces the usual Error: Status code: 429 which means I guess that the header was valid and went through the request.

So whichever name I use for header name is valid except for Cookie. Why is that? I've been trying to figure this out for the past 6 hours. I apologize in advance if my question is silly. My JS background is very limited.

the way that console.log prints objects, it will put quotes around attribute names that contain a non-alphanumeric character, it does not affect the actual internal attribute name used.

as for why it's not working and the error you're getting, try lowercasing the header name to "cookie".

if that doesn't work, it's likely that having that cookie there prevents the endpoint ytdl-core uses internally to work. you could try only setting the cookie during the download. something like

let info = await ytdl.getInfo(id);
ytdl.downloadFromInfo(info, { requestOptions: { Cookie: cookie } });

Thank you for the speedy answer. I'm afraid this doesn't work.. I still get the 429 error but now I get it from the getInfo() function. I need to set cookie for every request that I send to youtube and I can't find an example code anywhere online about setting cookies with ytdl-core that works :(

Maybe you could add an example for cookies in the example folder than you have?

If you are not throttled by youtube with error 429 you can recreate the scenario trying to download a private video. Only when using cookies you will be able to get it.

Same here. Getting a bursty stream of requests blocks all videos. Would love to see a correct cookie implementation

I have a similar problem with my discord.js bot and ytdl by itself. If i use ytdl "anyurl" --print-url it throws the Error: 429. When i use ytdl-core for my discord bot, the bot joins but has no audio. The player doesnt receive any ytdl data. (buffer length: 0). The error started around 7 to 8 months using the bot on 1 Server.

I am also getting this error, it was working fine all this time (since I started using it, 3 months ago) but now I am suddenly getting a 429 error with my Discord Bot. It still happens after small requests even when the Bot did not request any data for around 12 hours.

@NafiAF I solved the problem for me. I waited around 4 to 5 days and then it was gone. The error triggeres when ur bot gets too many requests in a small amount of time. Then Google blocks the bot for some days to prevent DDOS. This is what works for me :)

@NafiAF Personally I have solved this issue by not using ytdl-core anymore. I have moved to youtube-dl because that one has easy support for cookies. When you use cookies so that you are logged into youtube, the error 429 does not occur anymore.

For what it's worth, @fent and @akanellis 's solution of using cookies worked, at least for now. I just hope my account doesn't get blocked or something.

I navigated to youtube.com in chrome, opened dev console, and copied the cookies from a network request.
Then do:

ytdl(<id>, {
            ...
            requestOptions: {
                headers: {
                    'Cookie': '<paste cookie as string>'
                }
            }
        })

Apparently, even using oauth isn't immune to 429.
Using oauth in the request options (e.g. {filter:'audioonly', requestOptions: {headers: {Authorization: 'Bearer ...'}}}gives me ~15-25 videos, before getting another 429.
Refreshing the access token (but using the same refresh token and thereby not requiring user re-login) gives me another 15-25 videos.
This is just ~1 video per 3-5 minutes.
(I'm only 75% this comment is accurate :), I'll update it once I verify it again)

Confirmed, my above comment is accurate. Refreshing the oath token does resolve the issue. It took 20 downloads to reach http 429. I guess something like this should work then

ytdl(...)
  .on('error', error => {
    if (error.message === 'Status code: 429') {
      // refreh token
      // try again
    }
  })

I'm 429 blocked now too so I've been playing around with cookies. I've narrowed it down to these three:
'SID=xxx; HSID=xxx; SSID=xxxx;'

I've been able to make successful calls after setting these manually.
They are all set to expire in July 2022, so hopefully I can get some good use out of them until then.

@eric-mathison Were you able to make requests from a blocked IP?

@eric-mathison Were you able to make requests from a blocked IP?

I couldn't confirm that my IP was blocked, but I kept getting error 429 from my node application running local on my laptop. I waited over 14 hours and it was still receiving this error. Passing those 3 cookies is working. I just finished downloading 52 videos in around 7 minutes time. They are small 75mb and I downloaded them slow, 1 at a time. So far so good.

Screenshot_20200818_130349

Does not seem to work on a server that's already blocked.

Screenshot_20200818_131032

Edit: Same request works fine in Postman.

Screenshot_20200818_130349

Does not seem to work on a server that's already blocked.

Screenshot_20200818_131032

Edit: Same request works fine in Postman.

it's showing 10 headers in postman, maybe that's helping

@fent Those are standard headers, I generated the curl command using postman.

Update:
I disabled IPv6 on the server.
Without headers and cookie:
Screenshot_20200818_192330

With headers and cookie
Screenshot_20200818_192106

Update 2:
Did not last long, went back to 429.

Screenshot_20200818_130349

Does not seem to work on a server that's already blocked.

Screenshot_20200818_131032

Edit: Same request works fine in Postman.

@WaqasIbrahim that doesn't look like an IP block. You are getting blocked by reCaptcha. See if you can curl the get_video_info url directly. YouTube doesn't block the watch url. Only the get info.

@eric-mathison get_video_info seems to be working but watch page URL is used first. get_video_info is a fallback URL.

@eric-mathison get_video_info seems to be working but watch page URL is used first. get_video_info is a fallback URL.

Eh, you're probably right. I was just able to get it working from the get_video_info URL since the watch pages never broke for me.

My IP was blocked and i can confirm that. setting proxy or anything didn't work. Had to spin up a new server.

Services on my host have been having this issue as of recently. In fact, I've been unable to use ytdl at all for the last few days. I have been unsuccessful in using cookies to fix the problem. I'm not sure what to do about it.

Can you add a openvpn or some vpn option as a parameter to use with this. It'll be super helpful.

I'm 429 blocked now too so I've been playing around with cookies. I've narrowed it down to these three:
'SID=xxx; HSID=xxx; SSID=xxxx;'

I've been able to make successful calls after setting these manually.
They are all set to expire in July 2022, so hopefully I can get some good use out of them until then.

This worked for me. I'm getting tons of requests and didn't receive the error anymore.

I'm 429 blocked now too so I've been playing around with cookies. I've narrowed it down to these three:
'SID=xxx; HSID=xxx; SSID=xxxx;'
I've been able to make successful calls after setting these manually.
They are all set to expire in July 2022, so hopefully I can get some good use out of them until then.

This worked for me. I'm getting tons of requests and didn't receive the error anymore.

Can you describe how to achieve that ?

For what it's worth, @fent and @akanellis 's solution of using cookies worked, at least for now. I just hope my account doesn't get blocked or something.

I navigated to youtube.com in chrome, opened dev console, and copied the cookies from a network request.
Then do:

ytdl(<id>, {
            ...
            requestOptions: {
                headers: {
                    'Cookie': '<paste cookie as string>'
                }
            }
        })

@lxcool9243 The above comment explains how. Just open a request (one that says 'log_event?alt=json...', something like that) at the left when you're in the Network tab on youtube.com in Chrome Dev Tools. Scroll down to the Request Headers and you'll find a string called 'coockie'. This is the one you should copy and paste as in the example above. I did this while I was logged in, but I don't think that has an impact on your outcome.

Use the coockie in every ytdl request, also when you're requesting video info & the hassle will be gone :) It worked perfectly for me.

Hope this helps! Kind regards, Jens.

For what it's worth, @fent and @akanellis 's solution of using cookies worked, at least for now. I just hope my account doesn't get blocked or something.
I navigated to youtube.com in chrome, opened dev console, and copied the cookies from a network request.
Then do:

ytdl(<id>, {
            ...
            requestOptions: {
                headers: {
                    'Cookie': '<paste cookie as string>'
                }
            }
        })

@lxcool9243 The above comment explains how. Just open a request (one that says 'log_event?alt=json...', something like that) at the left when you're in the Network tab on youtube.com in Chrome Dev Tools. Scroll down to the Request Headers and you'll find a string called 'coockie'. This is the one you should copy and paste as in the example above. I did this while I was logged in, but I don't think that has an impact on your outcome.

Use the coockie in every ytdl request, also when you're requesting video info & the hassle will be gone :) It worked perfectly for me.

Hope this helps! Kind regards, Jens.

Thanks for the explanation @jensbrehmen and for the quick reply.

This is the issue i have been getting.
MinigetError: Status code: 429 at ClientRequest.<anonymous> (C:\Users\HP\Desktop\music\node_modules\ytdl-core-discord\node_modules\miniget\dist\index.js:163:31) at Object.onceWrapper (events.js:422:26) at ClientRequest.emit (events.js:315:20) at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:596:27) at HTTPParser.parserOnHeadersComplete (_http_common.js:119:17) at TLSSocket.socketOnData (_http_client.js:469:22) at TLSSocket.emit (events.js:315:20) at addChunk (_stream_readable.js:295:12) at readableAddChunk (_stream_readable.js:271:9) at TLSSocket.Readable.push (_stream_readable.js:212:10)

for those getting this, do you know if the error comes from the getInfo() call, or does it happen after the download has started?

for those getting this, do you know if the error comes from the getInfo() call, or does it happen after the download has started?

i get this erro on my website downloader
the erro happening before download start
the download dont start

for those getting this, do you know if the error comes from the getInfo() call, or does it happen after the download has started?

i get this erro on my website downloader
the erro happening before download start
the download dont start

Nov 24 05:18:01 (node:34) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
Nov 24 05:18:01 at TLSSocket.Readable.push (_stream_readable.js:209:10)
Nov 24 05:18:01 at readableAddChunk (_stream_readable.js:268:9)
Nov 24 05:18:01 at addChunk (_stream_readable.js:286:12)
Nov 24 05:18:01 at TLSSocket.emit (events.js:310:20)
Nov 24 05:18:01 at TLSSocket.socketOnData (_http_client.js:476:22)
Nov 24 05:18:01 at HTTPParser.parserOnHeadersComplete (_http_common.js:119:17)
Nov 24 05:18:01 at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:603:27)
Nov 24 05:18:01 at ClientRequest.emit (events.js:310:20)
Nov 24 05:18:01 at Object.onceWrapper (events.js:417:26)
Nov 24 05:18:01 at ClientRequest. (/usr/src/app/node_modules/miniget/dist/index.js:150:31)
Nov 24 05:18:01 (node:34) UnhandledPromiseRejectionWarning: Error: Status code: 429
Nov 24 05:18:01 (node:34) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Nov 24 05:18:01 (node:34) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
Nov 24 05:18:01 at TLSSocket.Readable.push (_stream_readable.js:209:10)
Nov 24 05:18:01 at readableAddChunk (_stream_readable.js:268:9)
Nov 24 05:18:01 at addChunk (_stream_readable.js:286:12)
Nov 24 05:18:01 at TLSSocket.emit (events.js:310:20)
Nov 24 05:18:01 at TLSSocket.socketOnData (_http_client.js:476:22)
Nov 24 05:18:01 at HTTPParser.parserOnHeadersComplete (_http_common.js:119:17)
Nov 24 05:18:01 at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:603:27)
Nov 24 05:18:01 at ClientRequest.emit (events.js:310:20)
Nov 24 05:18:01 at Object.onceWrapper (events.js:417:26)
Nov 24 05:18:01 at ClientRequest. (/usr/src/app/node_modules/miniget/dist/index.js:150:31)
Nov 24 05:18:01 (node:34) UnhandledPromiseRejectionWarning: Error: Status code: 429

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'player_response' of undefined

would you be able to log the specific request causing the error?

in my machine locally download works
but in my website dont work

Nov 24 06:05:58 (node:28) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Nov 24 06:05:58 (node:28) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
Nov 24 06:05:58 at async exports.getInfo (/usr/src/app/node_modules/ytdl-core/lib/info.js:337:14)
Nov 24 06:05:58 at async exports.getBasicInfo (/usr/src/app/node_modules/ytdl-core/lib/info.js:39:14)
Nov 24 06:05:58 at processTicksAndRejections (internal/process/task_queues.js:97:5)
Nov 24 06:05:58 at pipeline (/usr/src/app/node_modules/ytdl-core/lib/info.js:126:19)
Nov 24 06:05:58 (node:28) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'player_response' of undefined

I'm getting the 429 status code too, sadly.
This is what I get in console

Error: input stream: Status code: 429
at ClientRequest.<anonymous> (/home/container/node_modules/miniget/dist/index.js:150:31)
at Object.onceWrapper (events.js:417:26)
at ClientRequest.emit (events.js:310:20)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:603:27)
at HTTPParser.parserOnHeadersComplete (_http_common.js:119:17)
at TLSSocket.socketOnData (_http_client.js:476:22)
at TLSSocket.emit (events.js:310:20)
at addChunk (_stream_readable.js:286:12)
at readableAddChunk (_stream_readable.js:268:9)
at TLSSocket.Readable.push (_stream_readable.js:209:10)

Are there any fixes for this?

Package Version: 3.2.2

i set cookies and getting same error

`app.get("/download", (req,res) => {
var URL = req.query.URL;
const COOKIE = '4AeIEw4detV7rm_BRXWXcP0FZ07hfzCWJ6Yj-RXjzV5qA1Bfn554Frt5nSlA5WV6jVupZA.; HSID=A8-pDBP8hDr98uzSL; SSID=AgKxooBc-x_TmLQNp;';
ytdl(URL, {
requestOptions: {
headers: {
cookie: COOKIE,
}
}
}).pipe(res);
ytdl.getInfo(URL).then(info => {
console.log('title:', info.videoDetails.title);
console.log('rating:', info.player_response.videoDetails.averageRating);
console.log('uploaded by:', info.videoDetails.author.name);
const json = JSON.stringify(info, null, 2)
res.header("Content-Disposition", "attachment;filename=" + encodeURI(info.videoDetails.title) + '.mp4');

});`

The solution is to set cookies.
How to get cookies?

navigate to YouTube in a web browser
open up dev tools (opt+cmd+j on mac)
go to the Network tab
Click on a request on the left
scroll down to "Request Headers"
find the "cookie" header and copy its entire contents, That would be cookies

The solution is to set cookies.

How to get cookies?

navigate to YouTube in a web browser

open up dev tools (opt+cmd+j on mac)

go to the Network tab

Click on a request on the left

scroll down to "Request Headers"

find the "cookie" header and copy its entire contents, That would be cookies

Did you start using cookies before or after you start getting the 429 error?

I started using a cookie header after I started getting a 429 but I still get that response nonetheless.

@fent The issue also is coming from getInfo() too

I got also the 429 issue. It's coming from the _getBasicInfo_-method.

Error: Status code: 429
    at ClientRequest.httpLib.request (C:\Users\BenjaminM\Desktop\yt-downloader\node_modules\miniget\dist\index.js:190:31)
    at Object.onceWrapper (events.js:286:20)
    at ClientRequest.emit (events.js:198:13)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:565:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:111:17)
    at TLSSocket.socketOnData (_http_client.js:451:20)
    at TLSSocket.emit (events.js:198:13)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:269:11)
    at TLSSocket.Readable.push (_stream_readable.js:224:10) statusCode: 429 }

But with setting a cookie to the request header, it's gone.

i fount the solution
the solution is set cookies to all methods requests

would you be able to log the specific request causing the error?

@fent On 4.1.4, 429 occurred when getInfo is getting a watch page for html5player with a valid cookie. Now I have to use the embed page to get html5player. getBasicInfo still works.

Hi all,
I've been using ytdl core and now I'm also having the 429 error all of sudden after month of successful usage.
I've read the thread and here where I'm at:

const COOKIE = "HSID=XXX; SSID=XXX; SID=XXX;";
      const info = await ytdl.getInfo(videoId, { requestOptions: { headers: {cookie: COOKIE}} });
      const format = ytdl.chooseFormat(info.formats, { quality: 'highestaudio', requestOptions: { headers: {cookie: COOKIE}} });
      const stream = ytdl(videoId, { quality: 'highestaudio', requestOptions: { headers: {cookie: COOKIE}}});

but still 429 Error:

ERROR  Status code: 429
10:17:11 AM web.1 |    at ClientRequest.<anonymous> (node_modules/ytdl-core/node_modules/miniget/dist/index.js:190:31)
10:17:11 AM web.1 |    at Object.onceWrapper (node:events:434:26)
10:17:11 AM web.1 |    at ClientRequest.emit (node:events:327:20)
10:17:11 AM web.1 |    at ClientRequest.EventEmitter.emit (node:domain:486:12)
10:17:11 AM web.1 |    at HTTPParser.parserOnIncomingClient [as onIncoming] (node:_http_client:652:27)
10:17:11 AM web.1 |    at HTTPParser.parserOnHeadersComplete (node:_http_common:126:17)
10:17:11 AM web.1 |    at TLSSocket.socketOnData (node:_http_client:518:22)
10:17:11 AM web.1 |    at TLSSocket.emit (node:events:327:20)
10:17:11 AM web.1 |    at TLSSocket.EventEmitter.emit (node:domain:486:12)
10:17:11 AM web.1 |    at addChunk (node:internal/streams/readable:304:12)
10:17:11 AM web.1 |    at readableAddChunk (node:internal/streams/readable:279:9)
10:17:11 AM web.1 |    at TLSSocket.Readable.push (node:internal/streams/readable:218:10)
10:17:11 AM web.1 |    at TLSWrap.onStreamRead (node:internal/stream_base_commons:192:23)

Did I miss something?
For now it's only doing it on my localhost but I'm worried it'll start on my prod server. Although I think here the IP is dynamic... (Heroku).

@flapflap I had to set full cookies string in order for it to work

I also had to manually set x-youtube-identity-token, which, quoting from examples:

You can find this by going to a video's watch page, viewing the source, and searching for "ID_TOKEN".

That's how my final request looks like:

videoInfo = await ytdl.getInfo(video, {
  requestOptions: {
    headers: {
      Cookie: FULL_COOKIE_STR_FROM_YOUTUBE,
      'x-youtube-identity-token':
        'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
    },
  },
});

You have to do it for every request you're going to make

Cool thanks. Going to try that :)

To prevent the error 429 I usually add proper headers to the miniget requests (user-agent accepted language) and the 429 disappear.

const DEFAULT_HEADERS = {
    "User-Agent": getFirefoxUserAgent()
    ,"Accept-Language": "en-US,en;q=0.5"
}

Miniget.defaultOptions.headers=DEFAULT_HEADERS

// keep user agent up to date with some magic

function getFirefoxUserAgent(){
    let date = new Date()
    let version = ((date.getFullYear() - 2018) * 4 + Math.floor(date.getMonth() / 4) + 58) + ".0"
    return `Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:${version} Gecko/20100101 Firefox/${version}`
}

The "requestOptions" seems to be a better way than hacking index.js btw 馃槂

I only use cookies to retrieve my subs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

r0hin picture r0hin  路  3Comments

GamerXD4 picture GamerXD4  路  5Comments

ajgeiss0702 picture ajgeiss0702  路  5Comments

cloudrac3r picture cloudrac3r  路  5Comments

CheweyZ picture CheweyZ  路  6Comments