mlg404 / whatsapp-music-bot

A whatsapp bot to send and search musics to your friends!
MIT License
124 stars 77 forks source link

Não consigo sair daqui #7

Closed Iuryaa closed 3 years ago

Iuryaa commented 3 years ago

Sempre depois de conectar ao qrcode aparece a seguinte mensagem:

(node:18788) UnhandledPromiseRejectionWarning: TimeoutError: waiting for selector canvas failed: timeout 45000ms exceeded at new WaitTask (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\puppeteer\lib\cjs\puppeteer\common\DOMWorld.js:411:34) at DOMWorld.waitForSelector (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\puppeteer\lib\cjs\puppeteer\common\DOMWorld.js:319:26) at Frame.waitForSelector (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\puppeteer\lib\cjs\puppeteer\common\FrameManager.js:842:51) at Page.waitForSelector (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\puppeteer\lib\cjs\puppeteer\common\Page.js:1322:33) at Timeout.getQrCode [as _onTimeout] (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\whatsapp-web.js\src\Client.js:125:28) at processTicksAndRejections (internal/process/task_queues.js:97:5) (node:18788) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:18788) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. (node:18788) UnhandledPromiseRejectionWarning: TimeoutError: waiting for selector canvas failed: timeout 45000ms exceeded at new WaitTask (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\puppeteer\lib\cjs\puppeteer\common\DOMWorld.js:411:34) at DOMWorld.waitForSelector (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\puppeteer\lib\cjs\puppeteer\common\DOMWorld.js:319:26) at Frame.waitForSelector (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\puppeteer\lib\cjs\puppeteer\common\FrameManager.js:842:51) at Page.waitForSelector (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\puppeteer\lib\cjs\puppeteer\common\Page.js:1322:33) at Timeout.getQrCode [as _onTimeout] (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\whatsapp-web.js\src\Client.js:125:28) at processTicksAndRejections (internal/process/task_queues.js:97:5) (node:18788) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) (node:18788) UnhandledPromiseRejectionWarning: TimeoutError: waiting for selector canvas failed: timeout 45000ms exceeded at new WaitTask (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\puppeteer\lib\cjs\puppeteer\common\DOMWorld.js:411:34) at DOMWorld.waitForSelector (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\puppeteer\lib\cjs\puppeteer\common\DOMWorld.js:319:26) at Frame.waitForSelector (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\puppeteer\lib\cjs\puppeteer\common\FrameManager.js:842:51) at Page.waitForSelector (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\puppeteer\lib\cjs\puppeteer\common\Page.js:1322:33) at Timeout.getQrCode [as _onTimeout] (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\whatsapp-web.js\src\Client.js:125:28) at processTicksAndRejections (internal/process/task_queues.js:97:5) (node:18788) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)

Já tentei com npm run dev e yarn

mlg404 commented 3 years ago

Olá! Isso pode ser devido sua conexão de internet (tenha em mente que tanto o computador quanto o celular devem ter uma conexão no mínimo "ok") Outros fatores que podem levar a esse erro são: firewall's bloqueando conexão ou algum proxy no meio.

Se o erro continuar, apague todo o diretório e faça o git clone novamente. Certifique também que você está utilizando uma versão do node LTS acima da 12 (qualquer 12.x.x serve). Se não souber como, basta utilizar o comando node -v

Iuryaa commented 3 years ago

Funcionou mas agora aparece isso: Conectado com sucesso! (node:7800) UnhandledPromiseRejectionWarning: Error: yt-search: no query given at a (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\yt-search\dist\yt-search.min.js:1:6587) at e.query (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\yt-search\dist\yt-search.min.js:1:1615) at new Promise () at a (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\yt-search\dist\yt-search.min.js:1:1589) at Client. (C:\Users\cunha\Downloads\whatsapp-music-bot-master\index.js:42:30) at Client.emit (events.js:315:20) at C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\whatsapp-web.js\src\Client.js:226:18 at Page._onBindingCalled (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\puppeteer\lib\cjs\puppeteer\common\Page.js:747:62) at C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\puppeteer\lib\cjs\puppeteer\common\Page.js:172:60 at C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\puppeteer\lib\cjs\vendor\mitt\src\index.js:51:62 (node:7800) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2) (node:7800) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. events.js:292 throw er; // Unhandled 'error' event ^

Error: spawn C: fmpeg-2020-10-14-git-6bdfea8d4b-full_builin ENOENT at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19) at onErrorNT (internal/child_process.js:469:16) at processTicksAndRejections (internal/process/task_queues.js:84:21) Emitted 'error' event on DownloadYTAudio instance at: at FfmpegCommand. (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\yt-dl-playlist\lib\download-audio.js:82:14) at FfmpegCommand.emit (events.js:315:20) at emitEnd (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\fluent-ffmpeg\lib\processor.js:424:16) at C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\fluent-ffmpeg\lib\processor.js:433:16 at wrapper (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\async\dist\async.js:268:20) at next (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\async\dist\async.js:4582:24) at C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\async\dist\async.js:321:20 at wrapper (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\async\dist\async.js:268:20) at next (C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\async\dist\async.js:4582:24) at C:\Users\cunha\Downloads\whatsapp-music-bot-master\node_modules\async\dist\async.js:321:20 { errno: 'ENOENT', code: 'ENOENT', syscall: 'spawn C:\ffmpeg-2020-10-14-git-6bdfea8d4b-full_build\bin', path: 'C:\ffmpeg-2020-10-14-git-6bdfea8d4b-full_build\bin', spawnargs: [ '-formats' ] } [nodemon] app crashed - waiting for file changes before starting...

mlg404 commented 3 years ago

Pode me mandar seu index,js?

O segundo error ele não consegue encontrar o seu path do ffmpeg

Iuryaa commented 3 years ago

Na pasta index ta isso const fs = require('fs'); const path = require('path'); const yts = require('yt-search'); const qrcode = require('qrcode-terminal'); const DownloadYTFile = require('yt-dl-playlist'); const { Client, MessageMedia } = require('whatsapp-web.js');

const downloadStatus = {}; const downloadedMusics = []; const client = new Client(); const downloadPath = path.resolve(__dirname, 'downloads');

client.on('qr', qr => { qrcode.generate(qr, {small: true}); });

client.on('ready', async () => { console.log('Conectado com sucesso!'); await fs.readdir(path.resolve(__dirname, 'downloads'), (err, itens) => { itens.map(item => downloadedMusics.push(item)); }); downloadStatus.baixando = false;

});

client.on('message_create', async message => { if(message.body.startsWith('!musicas') && message.fromMe){ console.log(downloadedMusics); }

if(message.body.startsWith('!info') && message.fromMe){ console.log(message); client.sendMessage(message.to, 'kkkkk') } if(message.body.startsWith('!play')){ const opts = { query: message.body.split('!play')[1], pageStart: 1, pageEnd: 3, }

const { videos } = await yts(opts);

if (videos.length == 0) {
  return message.reply("Não encontrado, tente novamente");   
}

const { videoId, title, duration } = videos[0];

if (downloadedMusics.includes(`${videoId}.mp3`)){
  media =  MessageMedia.fromFilePath(path.resolve(__dirname, 'downloads', `${videoId}.mp3`));
  return message.reply(media);   
} else if (duration.seconds >= 900) {
  return message.reply("Músicas com mais de *15 minutos* não são permitidas!");
}
if (downloadStatus.baixando == true) {
  return message.reply("Algúem em algum lugar do meu zipzopt já está baixando uma música no momento. Aguarde! (ou me pague um servidor pro bot)");
}

downloadStatus.baixando = true;
message.reply("*INICIANDO DOWNLOAD:* _Esta ação pode demorar um pouco!_");

const downloader = new DownloadYTFile({ 
  outputPath: downloadPath,
  ffmpegPath: 'C:\ffmpeg-2020-10-14-git-6bdfea8d4b-full_build\bin',
  maxParallelDownload: 1,
});

/* UNCOMMENT TO SHOW DOWNLOAD PROGRESS */
// downloader.on('progress', (fileInfo) => {
//   //console.log(fileInfo.progress)
//   const totalTime = fileInfo.ref.duration;
//   const atualTime = fileInfo.progress.timemark;
//   const atualSeconds = Number(atualTime.split(":")[1]*60) + Number(atualTime.split(":")[2]);
//   client.sendMessage(message.to, `Downloading: ${(atualSeconds*100/totalTime).toFixed(0)}%`)
// })

const download = await downloader.download(videoId, `${videoId}.mp3`);
if (!download){
  return message.reply("Erro, tente novamente.");
}

downloadStatus.baixando = false;

media =  MessageMedia.fromFilePath(path.resolve(__dirname, 'downloads', `${videoId}.mp3`));
return message.reply(media);

} });

client.initialize();

Iuryaa commented 3 years ago

Pelo jeito eu tinha que colocar yarn add yt-search, mas agora aparece esse (node:13520) UnhandledPromiseRejectionWarning: Error: Protocol error (Runtime.callFunctionOn): Target closed. at C:\Users\cunha\whatsapp-music-bot\node_modules\puppeteer\lib\cjs\puppeteer\common\Connection.js:208:63 at new Promise () at CDPSession.send (C:\Users\cunha\whatsapp-music-bot\node_modules\puppeteer\lib\cjs\puppeteer\common\Connection.js: 207:16) at ExecutionContext._evaluateInternal (C:\Users\cunha\whatsapp-music-bot\node_modules\puppeteer\lib\cjs\puppeteer\co mmon\ExecutionContext.js:200:50) at ExecutionContext.evaluateHandle (C:\Users\cunha\whatsapp-music-bot\node_modules\puppeteer\lib\cjs\puppeteer\commo n\ExecutionContext.js:151:21) at WaitTask.rerun (C:\Users\cunha\whatsapp-music-bot\node_modules\puppeteer\lib\cjs\puppeteer\common\DOMWorld.js:427 :71) at processTicksAndRejections (internal/process/task_queues.js:97:5) (node:13520) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing ins ide of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To termin ate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodej s.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:13520) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejection s that are not handled will terminate the Node.js process with a non-zero exit code. [nodemon] clean exit - waiting for changes before restart

Iuryaa commented 3 years ago

sai dos dois erros mas como a vida incrível veio mais um errno: 'ENOENT', code: 'ENOENT', syscall: 'spawn C:/Users/cunha\ffmpeg\bin', path: 'C:/Users/cunha\ffmpeg\bin', spawnargs: [ '-formats' ]

na pasta index, eu já tentei trocar por: path: 'C:/FFmpeg/bin', C:Users\cunha>ffmpeg C:Users/cunha/ffmpeg C:Users\cunha\ffmpeg C:/Users/cunha/ffmpeg C:Users\cunha\ffmpeg\bin C: Users cunha\ffmpeg\bin

e meu ffmpeg quando eu ponho no cmd: C:\Users\cunha>FFmpeg ffmpeg version 2020-10-14-git-6bdfea8d4b-full_build-www.gyan.dev Copyright (c) 2000-2020 the FFmpeg developers built with gcc 10.2.0 (Rev3, Built by MSYS2 project) configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libglslang --enable-vulkan --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint libavutil 56. 60.100 / 56. 60.100 libavcodec 58.111.100 / 58.111.100 libavformat 58. 62.100 / 58. 62.100 libavdevice 58. 11.102 / 58. 11.102 libavfilter 7. 87.100 / 7. 87.100 libswscale 5. 8.100 / 5. 8.100 libswresample 3. 8.100 / 3. 8.100 libpostproc 55. 8.100 / 55. 8.100 Hyper fast Audio and Video encoder usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Use -h to get full help or, even better, run 'man ffmpeg'

Iuryaa commented 3 years ago

Consegui, tinha que colocar pro ffmpeg.exe

mlg404 commented 3 years ago

Boa! Ia comentar isso, recebi no email mas estive fora esses dias. Vou fazer uma alteração no readme depois, explicando esses passos para windows. Obrigado pela contribuição!