Skip to content

Instantly share code, notes, and snippets.

@mifyow
Created November 1, 2025 07:42
Show Gist options
  • Select an option

  • Save mifyow/0ec245c127714f808169da87826761b5 to your computer and use it in GitHub Desktop.

Select an option

Save mifyow/0ec245c127714f808169da87826761b5 to your computer and use it in GitHub Desktop.
Uploaded via Mifinfinity-!! | Yessir
import fs from "fs";
import path from "path";
import ffmpeg from "fluent-ffmpeg";
import ffmpegInstaller from "@ffmpeg-installer/ffmpeg";
import fetch from "node-fetch";
import ytdl from "@vreden/youtube_scraper";
import yts from "yt-search";
ffmpeg.setFfmpegPath(ffmpegInstaller.path);
export default {
name: "playch",
category: "music",
command: ["playch", "songch"],
settings: { owner: false },
run: async (conn, m) => {
try {
const fullText =
m.text ||
m.body ||
m.message?.conversation ||
m.message?.extendedTextMessage?.text ||
m.args?.join(" ") ||
m.input ||
m.quoted?.text ||
"";
const query = fullText.replace(m.cmd, "").trim();
if (!query)
return m.reply("🎡 Masukkan judul lagunya!\n\nContoh:\n> .playch jalan kenangan");
// react "loading"
await conn.sendMessage(m.chat, { react: { text: "⏳", key: m.key } });
const ytsSearch = await yts(query);
const result = ytsSearch.all[0];
if (!result) {
await conn.sendMessage(m.chat, { react: { text: "❌", key: m.key } });
return m.reply("❌ Lagu tidak ditemukan di YouTube.");
}
const data = await ytdl.ytmp3(result.url);
if (!data.status) {
await conn.sendMessage(m.chat, { react: { text: "❌", key: m.key } });
return m.reply("❌ Gagal mengambil audio, coba lagi nanti.");
}
const urlMp3 = data.download.url;
const tmpDir = path.join(process.cwd(), "Tmp");
if (!fs.existsSync(tmpDir)) fs.mkdirSync(tmpDir, { recursive: true });
const tmpInput = path.join(tmpDir, "yt_temp_input.mp3");
const tmpOutput = path.join(tmpDir, "yt_temp_output.ogg");
const res = await fetch(urlMp3);
const buffer = Buffer.from(await res.arrayBuffer());
fs.writeFileSync(tmpInput, buffer);
await new Promise((resolve, reject) => {
ffmpeg(tmpInput)
.toFormat("ogg")
.audioCodec("libopus")
.on("end", resolve)
.on("error", reject)
.save(tmpOutput);
});
const converted = fs.readFileSync(tmpOutput);
await conn.sendMessage(
global.idChannel,
{
audio: converted,
mimetype: "audio/ogg; codecs=opus",
ptt: true,
contextInfo: {
externalAdReply: {
title: result.title,
body: `By Mifinfinity-MD 🎧 - ${result.author.name}`,
thumbnailUrl: result.thumbnail,
sourceUrl: result.url,
mediaType: 1,
renderLargerThumbnail: true,
},
},
},
{ quoted: m }
);
await conn.sendMessage(m.chat, { react: { text: "βœ…", key: m.key } });
fs.unlinkSync(tmpInput);
fs.unlinkSync(tmpOutput);
} catch (err) {
console.error(err);
await conn.sendMessage(m.chat, { react: { text: "❌", key: m.key } });
await m.reply("❌ Terjadi kesalahan saat memproses lagu.");
}
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment