distubejs / ytdl-core

YouTube video downloader in javascript.
MIT License
206 stars 43 forks source link

Não consegui resolver o problema que fica pedindo loguin, alguém pode me ajudar? #75

Closed tonykx closed 1 month ago

tonykx commented 1 month ago

Está é a minha Case, por favor, se alguém puder adaptar ela ficarei feliz:

case 'playk': { const { Agent } = require('undici'); const ytdl = require('@distube/ytdl-core');

// Lista de proxies const proxies = [ '152.26.229.66:9443', '152.26.229.42:9443', '152.26.229.88:9443', '152.26.231.42:9443', '152.26.231.77:9443', '152.26.231.86:9443', '177.234.241.25:999', '177.234.241.26:999', '177.234.241.27:999', '177.234.241.30:999' ];

// Seleciona um proxy aleatoriamente const randomProxy = proxies[Math.floor(Math.random() * proxies.length)];

// Defina os cookies const cookies = [ { name: "__Secure-1PAPISID", value: "WDoUT2f_8AICiVQI/A-iEfJ0mTF7FCH0nu" }, { name: "__Secure-1PSID", value: "g.a000mggOIZ8xzdxahoWXrpepBb_gH969jElekSmn7yGZWogoAYFCloaqYWivWHhGpQA1lTKCZQACgYKAXgSARYSFQHGX2MiDo95c3swqPu-DnxBhUWhLxoVAUF8yKrxmHfyW-vKrCh9diS8XOTx0076" } ];

// Configuração do agente com cookies const agentOptions = { pipelining: 5, maxRedirections: 0, localAddress: "127.0.0.1" };

// Crie um cliente com cookies e opções const proxyAgent = new Agent({ uri: http://${randomProxy} }); const client = ytdl.createAgent(cookies, agentOptions);

try { if (args.length < 1) return reply("Insira o comando e um nome para a pesquisa!");

const { videoId, ...details } = (await yts(args.join(" "))).all.filter(result => Boolean(result?.videoId)).find(result => Boolean(result?.videoId)) || {};
const { title, timestamp, name, thumbnail } = details;

// Stream do download com proxy e cliente
const stream = await ytdl(`https://youtube.com/watch?v=${videoId}`, { 
  filter: "audioonly", 
  quality: 'lowestaudio',
  requestOptions: {
    client: proxyAgent, // Use client em vez de agent
    headers: {
      'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
      'Accept-Language': 'en-US,en;q=0.9'
    }
  }
});

const pathh = `./${await getRandom('.mp3')}`;
const writer = await fs.createWriteStream(pathh);

stream.pipe(writer).on("finish", async () => {
  writer.close();
  const contextInfo = {
    externalAdReply: {
      title: title,
      body: `⌛ Duração: ${timestamp}`,
      mediaUrl: `file://${pathh}`,
      thumbnailUrl: thumbnail,
    }
  };

  await conn.sendMessage(from, { 
    audio: { url: pathh }, 
    mimetype: "audio/aac", 
    contextInfo: contextInfo 
  }, { quoted: info }).then(async e => {
    await sleep(2000);
    await fs.unlinkSync(pathh);
  });

});

} catch (error) { console.error("Error:", error); reply("Ocorreu um erro ao processar sua solicitação."); } break; }

sl1taz commented 1 month ago

Eu estou com o mesmo problema aqui. Localmente funciona, mas quando subo para produção, recebo esse mesmo erro. Está afim de tentarmos corrgir juntos?

tonykx commented 1 month ago

Eu estou com o mesmo problema aqui. Localmente funciona, mas quando subo para produção, recebo esse mesmo erro. Está afim de tentarmos corrgir juntos?

Como podemos resolver isso?

ybd-project commented 1 month ago

Como podemos resolver isso?

I think it will work if I modify it as follows. But I don't know because my environment is not downloading but getting information (getInfo function)...

const ytdl = require("@distube/ytdl-core");

const proxies = [
    "152.26.229.66:9443",
    "152.26.229.42:9443",
    "152.26.229.88:9443",
    "152.26.231.42:9443",
    "152.26.231.77:9443",
    "152.26.231.86:9443",
    "177.234.241.25:999",
    "177.234.241.26:999",
    "177.234.241.27:999",
    "177.234.241.30:999",
];

const randomProxy = proxies[Math.floor(Math.random() * proxies.length)];

const proxyAgent = ytdl.createProxyAgent({
    uri: `http://${randomProxy}`,
});

try {
    /* Same process... */

    const stream = await ytdl(`https://youtube.com/watch?v=${videoId}`, {
        filter: "audioonly",
        quality: "lowestaudio",
        agent: proxyAgent,
        requestOptions: {
            headers: {
                "User-Agent":
                    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
                "Accept-Language": "en-US,en;q=0.9",
            },
        },
    });

    /* Same process... */
} catch (error) { /* Same process... */ }
tonykx commented 1 month ago

Alguém ainda não conseguiu? Só falar