Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy #1249

Open
earningpoints opened this issue Sep 6, 2023 · 5 comments
Open

Proxy #1249

earningpoints opened this issue Sep 6, 2023 · 5 comments

Comments

@earningpoints
Copy link

Anyone can tell me how I can use proxy ? Please give some examples code

@WaqasIbrahim
Copy link
Contributor

https://github.com/fent/node-ytdl-core/blob/master/example/proxy.js

You can pass a custom http agent in request options.

@earningpoints
Copy link
Author

Sir how i can create a custom http agent ? please Help
I am new in nodejs sir

@WaqasIbrahim
Copy link
Contributor

@itsaqib96
Copy link

https://github.com/fent/node-ytdl-core/blob/master/example/proxy.js

Look at this example.

I am trying to use proxy agent but somehow it is not using the proxy server. ytdl-core is still using the local network to download videos. Please see the code below.

import { HttpsProxyAgent } from "https-proxy-agent";

const agent = new HttpsProxyAgent('https://MY_USERNAME:MY_PASSWORD@premium-residential.geonode.com:9000');
  const requestOptions = {agent};
const videoInfo = await ytdl.getInfo(url, requestOptions);

return new Promise((resolve, reject) => {
        ytdl(url, { ...requestOptions, format: videoFormat })
          .pipe(fs.createWriteStream(videOutputPath))
          .on("finish", () =>
            resolve({
              videOutputPath,
              filename,
            })
          )
          .on("error", (error) => reject(error));
      });

@rogerpadilla
Copy link

@itsaqib96 i think it is because the structure differs from what you are using.

Correct:

const videoInfo = await ytdl.getInfo(url, {  requestOptions: { agent } });

Yours:

const videoInfo = await ytdl.getInfo(url, { agent });

Notice the agent property must be wrapped into a requestOptions property and your current usage lacks it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants