fent / fent/node-ytdl-core

Preventing Error 429: Too Many Requests

Open
#635 76 comments 15 reactions 0 assignees View on GitHub
bug released
Dominant language
JavaScript
Stars
4.7k
Forks
852
PR merge metrics
No merged PRs in 30d

Description

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:

```javascript
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);
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.