import { createRequire } from 'module';
const require = createRequire(import.meta.url);

let { 
youtubedl,
youtubedlv2 
} = require('@bochilteam/scraper')

var handler = async (m, { conn, args }) => {
  if (!args[0]) throw 'Enter Link From YouTube!';
  conn.sendMessage(m.chat, { react: { text: '⏱️', key: m.key }})
  let q = '128kbps'
  let v = args[0]

  // Ambil info dari video
  try {
  const yt = await youtubedl(v).catch(async () => await  youtubedlv2(v))
  const dl_url = await yt.audio[q].download()
  const ttl = await yt.title
  const size = await yt.audio[q].fileSizeH

  // Tampilkan informasi file beserta thumbnail
  const info = `
• Judul: ${ttl}
• Ukuran: ${size}
• Link YouTube: ${v}`
  await conn.sendMessage(m.chat, { 
    audio: { url: dl_url }, 
    mimetype: 'audio/mpeg', 
    fileName: `${ttl}.mp3`,
    caption: info
  }, {quoted: m})
   } catch (e) {
    console.log(e);
    m.reply(`Failed :(`);
  }
}

// Jika ingin menambahkan tag, ubah code berikut:
handler.tags = ['downloader']
handler.help = ['ytmp3']
handler.command = /^yta|ytmp3|youtubemp3$/i
module.exports = handler

This code is a simple example of how to download a YouTube video and convert it to MP3 format. It utilizes the 'bochilteam/scraper' library to extract audio from a given YouTube video link. The code is designed for efficient conversion and provides the user with useful information about the downloaded file, including title, size, and the original YouTube link.

Here are some key features of this code:

  • Efficient Download: The code uses async/await to handle asynchronous operations, making the download process smoother and more efficient.
  • Information Display: The code provides the user with essential information about the downloaded MP3 file, including the title, size, and original YouTube link.
  • User-Friendly: The code is straightforward and easy to understand, allowing for customization and expansion.

To use this code, you will need to:

  1. Install the bochilteam/scraper library: npm install @bochilteam/scraper
  2. Replace conn with your desired method for sending messages.
  3. Update the handler.command line to match your desired command trigger.

This code provides a foundation for building a more robust YouTube to MP3 converter, offering a simple and efficient solution for converting YouTube videos to MP3 files. Feel free to adapt and extend this code to meet your specific needs.


原文地址: https://www.cveoy.top/t/topic/bQeR 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录