node-ytdl-core icon indicating copy to clipboard operation
node-ytdl-core copied to clipboard

Proxy

Open earningpoints opened this issue 1 year ago • 6 comments

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

earningpoints avatar Sep 06 '23 03:09 earningpoints

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

You can pass a custom http agent in request options.

WaqasIbrahim avatar Sep 06 '23 05:09 WaqasIbrahim

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

earningpoints avatar Sep 06 '23 05:09 earningpoints

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

Look at this example.

WaqasIbrahim avatar Sep 06 '23 05:09 WaqasIbrahim

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:[email protected]: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));
      });

itsaqib96 avatar Mar 06 '24 17:03 itsaqib96

@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.

rogerpadilla avatar Apr 01 '24 13:04 rogerpadilla

hello every please does any one got solution to this i try using the format above my code // Proxy URL format const proxyUrl = http://${username}:${password}@ddc.oxylabs.io:8000;

// Create proxy agent const agent = new HttpsProxyAgent(proxyUrl );

const options = process.env.NODE_ENV === 'production' ? { agent } : {};

    const info = await ytdl.getInfo(videoId, {  agent: options.agent  });

the error am getting "Type 'HttpsProxyAgent<"http://:@ddc.oxylabs.io:8000"> | undefined' is not assignable to type 'Agent | undefined'. Type 'HttpsProxyAgent<"http://:@ddc.oxylabs.io:8000">' is missing the following properties from type 'Agent': dispatcher, jarts(2322)".

& is where i put my username and password

TechLateef avatar May 28 '24 08:05 TechLateef