bagusskuy10 / lirik search PLUGINS ESM
Buat pencari lirik lagu di coba dulu gays
FrontendJavaScript
11 views
Buat pencari lirik lagu di coba dulu gays
import axios from 'axios'
export async function lyricsSearch(keyword) {
if (!keyword) throw new Error("Keyword pencarian wajib diisi.")
const TARGET_URL = 'https://lrclib.net/api/search'
const HEADERS = {
'User-Agent': 'LRCLIB Web Client (https://github.com/tranxuanthang/lrclib)',
'X-User-Agent': 'LRCLIB Web Client (https://github.com/tranxuanthang/lrclib)',
'Lrclib-Client': 'LRCLIB Web Client (https://github.com/tranxuanthang/lrclib)',
'Accept': 'application/json, text/plain, */*'
}
try {
const response = await axios.get(TARGET_URL, {
headers: HEADERS,
params: { q: keyword }
})
const data = response.data
if (Array.isArray(data) && data.length > 0) {
return data.map(item => ({
id: item.id,
track: item.trackName,
artist: item.artistName,
album: item.albumName,
duration: item.duration,
instrumental: item.instrumental,
plainLyrics: item.plainLyrics,
syncedLyrics: item.syncedLyrics
}))
} else {
return []
}
} catch (error) {
if (error.response) {
throw new Error(`Lyrics API Error: ${error.response.status} - ${JSON.stringify(error.response.data)}`)
}
throw new Error(`Lyrics Error: ${error.message}`)
}
}
// =========================
// HANDLER BOT
// =========================
const handler = async (m, { text }) => {
if (!text) return m.reply("Masukkan judul lagu yang ingin dicari.\nContoh: *lirik Hujan Gerimis Aje*")
let loadingMsg = await m.reply("⏳ Sedang mencari lirik... Mohon tunggu sebentar.")
try {
const result = await lyricsSearch(text)
if (result.length === 0) {
return m.reply("❌ Tidak ditemukan lirik untuk kata kunci tersebut.")
}
const song = result[0]
let message = `🎵 *Lirik Lagu Ditemukan!*\n\n`
message += `*Judul:* ${song.track}\n`
message += `*Artis:* ${song.artist}\n`
message += `*Album:* ${song.album || "-"}\n`
message += `*Durasi:* ${song.duration}s\n`
message += `*Instrumental:* ${song.instrumental ? "Ya" : "Tidak"}\n\n`
if (song.plainLyrics) {
message += `📄 *Lirik:*\n${song.plainLyrics}`
} else {
message += `⚠️ Lirik tidak tersedia.`
}
m.reply(message)
} catch (err) {
m.reply("❌ Terjadi kesalahan: " + err.message)
}
}
handler.help = ['lirik <judul>']
handler.tags = ['internet']
handler.command = /^(lirik|lyrics|lyric)$/i
export default handler