node-ytdl-core: "Proxy with auth" example not working.

Hi, i tried the proxy with auth example and got a 400 Bad Request response. Then i changed the path: parsed.href to path: parsed.path now i get the error To many redirects does anybody else got it to work?

Here is a test Proxy if smbd. want to test. {“host”:“217.29.63.224”,“port”:“10798”,“user”:“SgpHms”,“pass”:“6QQu3N”}

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 22 (8 by maintainers)

Commits related to this issue

Most upvoted comments

I just tried a couple of random proxies from there, took a few minutes to start up but eventually it did start downloading.

const ytdl = require('..');
const Agent = require('https-proxy-agent');

const host = '177.54.130.149';
const port = '59044';
const proxy = `http://${host}:${port}`;
const agent = new Agent(proxy);
const stream = ytdl('https://www.youtube.com/watch?v=2UBFIhS1YBk', {
  requestOptions: { agent }
});

console.log('Starting Download');

stream.on('data', (chunk) => {
  console.log('downloaded', chunk.length);
});

stream.on('end', () => {
  console.log('Finished');
});

I noticed that the ones that don’t support https give an error, even if I try using the request module just to make sure

const request = require('request');

const url = 'https://www.youtube.com/watch?v=2UBFIhS1YBk';
const host = '188.226.141.127';
const port = '3128';
const proxy = `http://${host}:${port}`;

request({ url, proxy }, (err, res) => {
  if (err) throw err;
  console.log('got res', res.statusCode);
});

Just tried again and it works! thanks!! you made my evening!!!

ah, so I tried using https-proxy-agent instead, since ytdl-core makes https requests, and it worked.

const ytdl = require('..');
const Agent = require('https-proxy-agent');

const proxy = 'http://xxx.xxx.xxx.xxx:xxxx';
const agent = new Agent(proxy);
const stream = ytdl('https://www.youtube.com/watch?v=2UBFIhS1YBk', {
  requestOptions: { agent }
});

console.log('Starting Download');

stream.on('data', (chunk) => {
  console.log('downloaded', chunk.length);
});

stream.on('end', () => {
  console.log('Finished');
});

I can update the examples to show usage with https-proxy-agent instead of using requestOptions.transform since handling proxies can be complicated, and there are many types. so better to leave it up to another optional module to handle it.