import {youtubedl, youtubedlv2} from '@bochilteam/scraper';
import fetch from 'node-fetch';
const handler = async (m, {conn, args}) => {
  if (!args[0]) throw '*[ğŸ›¡ï¸�]Past a Youtube link...*';
  await m.reply(wait);
    m.react(rwait);
  try {
    const qu = args[1] || '720';
    const q = qu + 'p';
    const v = args[0];
    const yt = await youtubedl(v).catch(async (_) => await youtubedlv2(v));
    const dl_url = await yt.video[q].download();
    const ttl = await yt.title;
    const size = await yt.video[q].fileSizeH;
    const cap = `*â—‰â•­â”�âŠ±âŒˆğŸ“¥ ğ��˜ğ���ğ��”ğ��“ğ��”ğ���ğ��„ ğ��ƒğ��‹ ğŸ“¥âŒ‹âŠ±â”�â•®â—‰*\nğŸª©*Title:* ${ttl}\nğŸª©*Size:* ${size}`.trim();
    await await conn.sendMessage(m.chat, {document: {url: dl_url}, caption: cap, mimetype: 'video/mp4', fileName: ttl + `.mp4`}, {quoted: m});
  } catch {
    m.react(done)
    try {
      const lolhuman = await fetch(`https://api.lolhuman.xyz/api/ytvideo2?apikey=${lolkeysapi}&url=${args[0]}`);
      const lolh = await lolhuman.json();
      const n = lolh.result.title || 'error';
      const n2 = lolh.result.link;
      const n3 = lolh.result.size;
      const cap2 = `*â—‰â•­â”�âŠ±âŒˆğŸ“¥ ğ��˜ğ���ğ��”ğ��“ğ��”ğ���ğ��„ ğ��ƒğ��‹ ğŸ“¥âŒ‹âŠ±â”�â•®â—‰*\nğŸª©*Title:* ${n}\nğŸª©*Size:* ${n3}`.trim();
      await conn.sendMessage(m.chat, {document: {url: n2}, caption: cap2, mimetype: 'video/mp4', fileName: n + `.mp4`}, {quoted: m});
    } catch {
      m.react(done)
      await conn.reply(m.chat, '*[â›”]error couldnt download the video*', m);
    }
  }
};
handler.command = /^ytmp4doc|ytvdoc|ytmp4.2|ytv.2|ytdl$/i;
handler.tags = ['downloader'];
export default handler;
