Skip to content

Instantly share code, notes, and snippets.

@mifyow
Created November 6, 2025 18:01
Show Gist options
  • Select an option

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

Select an option

Save mifyow/ec7b28ad009b9a3001e837def90b6903 to your computer and use it in GitHub Desktop.
Uploaded via Mifinfinity-!! || Lhoyaaaaa🤭
import axios from "axios";
import yts from "yt-search";
import fs from "fs";
import path from "path";
import ffmpeg from "fluent-ffmpeg";
import ffmpegInstaller from "@ffmpeg-installer/ffmpeg";
import fetch from "node-fetch";
ffmpeg.setFfmpegPath(ffmpegInstaller.path);
export default {
name: "playch",
category: "music",
command: ["playch", "songch"],
settings: { owner: false },
run: async (conn, m) => {
const idCh = "120363422031036859@newsletter"; // Ganti ID channel kamu
try {
const fullText =
m.text ||
m.body ||
m.message?.conversation ||
m.message?.extendedTextMessage?.text ||
m.quoted?.text ||
"";
const query = fullText.replace(/^(\.playch|\.songch)\s*/i, "").trim();
if (!query) return m.reply("🎧 Masukkan judul lagu!\nContoh: *.playch jalan kenangan*");
await m.reply("🔍 Mencari lagu...");
const s = await yts(query);
const v = s.videos[0];
if (!v) return m.reply("❌ Lagu tidak ditemukan di YouTube.");
const cmd = encodeURIComponent(`-x --audio-format mp3 ${v.url}`);
const r = await axios.get(`https://ytdlp.online/stream?command=${cmd}`, { responseType: "stream" });
let dl = null;
await new Promise((res, rej) => {
r.data.on("data", chunk => {
const match = chunk.toString().match(/href="([^"]+\.(mp3|m4a|webm))"/);
if (match) dl = `https://ytdlp.online${match[1]}`;
});
r.data.on("end", () => (dl ? res() : rej("Gagal ambil URL")));
r.data.on("error", rej);
});
if (!dl) return m.reply("⚠️ Tidak bisa mengambil audio.");
const dir = "./Tmp";
if (!fs.existsSync(dir)) fs.mkdirSync(dir);
const inPath = path.join(dir, "in.mp3");
const outPath = path.join(dir, "out.ogg");
const resp = await fetch(dl);
fs.writeFileSync(inPath, Buffer.from(await resp.arrayBuffer()));
await new Promise((res, rej) => {
ffmpeg(inPath)
.toFormat("ogg")
.audioCodec("libopus")
.on("end", res)
.on("error", rej)
.save(outPath);
});
const opus = fs.readFileSync(outPath);
await conn.sendMessage(
idCh,
{
audio: opus,
mimetype: "audio/ogg; codecs=opus",
ptt: true,
contextInfo: {
externalAdReply: {
title: v.title,
body: `Creator - ${v.author.name}`,
thumbnailUrl: v.thumbnail,
sourceUrl: v.url,
mediaType: 1,
renderLargerThumbnail: true,
},
},
},
{ quoted: m }
);
fs.unlinkSync(inPath);
fs.unlinkSync(outPath);
await m.reply(`✅ *${v.title}* berhasil dikirim ke channel 🎶`);
} catch (e) {
console.error("Playch2 Error:", e);
await m.reply("❌ Terjadi kesalahan, coba lagi nanti.");
}
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment