Untitled
š§© Syntax:
const axios = require("axios");
const fs = require("fs-extra");
const path = require("path");
const ytdl = require("@neoxr/ytdl-core");
const yts = require("yt-search");
module.exports = {
config: {
name: "lyrics",
version: "1.0",
author: "Aryan Chauhan",
countDown: 0,
role: 0,
shortDescription: {
en: "Get lyrics for a song",
},
longDescription: {
en: "This command allows you to get the lyrics for a song. Usage: !lyrics <song name>",
},
category: "music",
guide: {
en: "{prefix}lyrics <song name>",
},
},
onStart: async function ({ api, event, args }) {
const songName = args.join(" ");
if (!songName) {
// Add reaction here
api.setMessageReaction("ā", event.messageID);
api.sendMessage(
"ā šš”š©šššš š§šš§šš\n\nā Please provide a song name!",
event.threadID,
event.messageID
);
return;
}
try {
// Add reaction here
api.setMessageReaction("š", event.messageID);
// Fetch lyrics
const lyricsResponse = await axios.get(
`https://lyrics-api.replit.app/aryan?songName=${encodeURIComponent(songName)}`
);
const { lyrics, title, artist, image } = lyricsResponse.data;
// Fetch song
const searchResults = await yts(songName);
if (!searchResults.videos.length) {
api.sendMessage("ā š¦š¢š”š š”š¢š§ šš¢šØš”š\n\nā Sorry, song not found!", event.threadID, event.messageID);
return;
}
const video = searchResults.videos[0];
const videoUrl = video.url;
const stream = ytdl(videoUrl, { filter: "audioonly" });
const fileName = `music.mp3`;
const filePath = path.join(__dirname, "cache", fileName);
stream.pipe(fs.createWriteStream(filePath));
stream.on("response", () => {
console.info("[DOWNLOADER]", "Starting download now!");
});
stream.on("info", (info) => {
console.info("[DOWNLOADER]", `Downloading ${info.videoDetails.title} by ${info.videoDetails.author.name}`);
});
stream.on("end", async () => {
const audioStream = fs.createReadStream(filePath);
let message = `š ššš„š šš¦ šš¬š„ššš¦\n\nš§ š§šš§šš\nāŖ ${title}\nš šš„š§šš¦š§ \nāŖ ${artist} \n\nš¶ šš¬š„ššš¦\nāŖ ${lyrics}`;
let attachment = await global.utils.getStreamFromURL(image);
api.setMessageReaction("ā
", id, () => {}, true);
api.sendMessage({ body: message, attachment }, event.threadID, (err, info) => {
let id = info.messageID;
api.sendMessage({ attachment: audioStream }, event.threadID, () => {
});
});
});
} catch (error) {
console.error(error);
api.sendMessage("Sorry, there was an error getting the lyrics and song!", event.threadID, event.messageID);
}
},
};