Skip to content

Commit

Permalink
Update buscador-lyrics.js
Browse files Browse the repository at this point in the history
  • Loading branch information
darlyn1234 authored Oct 26, 2024
1 parent 05b282d commit 07cefaa
Showing 1 changed file with 74 additions and 49 deletions.
123 changes: 74 additions & 49 deletions plugins/buscador-lyrics.js
Original file line number Diff line number Diff line change
@@ -1,71 +1,96 @@
import { getTracks } from '@green-code/music-track-data';
import { googleImage } from '@bochilteam/scraper';
import got from 'got';
import cheerio from 'cheerio';
import fs from 'fs';
import { getTracks } from "@green-code/music-track-data";
import { googleImage } from "@bochilteam/scraper";
import got from "got";
import cheerio from "cheerio";
import fs from "fs";

const handler = async (m, { conn, text, usedPrefix, command }) => {
const datas = global;
const idioma = datas.db.data.users[m.sender].language || global.defaultLenguaje;
const _translate = JSON.parse(fs.readFileSync(`./src/languages/${idioma}.json`));
const tradutor = _translate.plugins.buscador_lyrics;
const teks = text ? text : m.quoted && m.quoted.text ? m.quoted.text : '';
if (!teks) throw `*${tradutor.texto1} ${usedPrefix + command} beret ojala*`;
const datas = global;
const idioma =
datas.db.data.users[m.sender].language || global.defaultLenguaje;
const _translate = JSON.parse(
fs.readFileSync(`./src/languages/${idioma}.json`),
);
const tradutor = _translate.plugins.buscador_lyrics;
const teks = text ? text : m.quoted && m.quoted.text ? m.quoted.text : "";
if (!teks) throw `*${tradutor.texto1} ${usedPrefix + command} beret ojala*`;
try {
const result = await getTracks(teks);
let lyrics;
if (result) {
lyrics = await searchLyrics(`${result[0]?.artist} ${result[0]?.title}`);
} else {
lyrics = await searchLyrics(`${teks}`);
}
const tituloL = result[0].title ? result[0].title : lyrics.title;
const artistaL = result[0].artist ? result[0].artist : lyrics.artist;
const res = await fetch(
global.API("https://some-random-api.com", "/lyrics", {
title: artistaL + tituloL,
}),
);
const json = await res.json();
let img;
try {
const result = await getTracks(teks);
let lyrics;
if (result) {
lyrics = await searchLyrics(`${result[0]?.artist} ${result[0]?.title}`);
} else {
lyrics = await searchLyrics(`${teks}`);
}
const tituloL = result[0].title ? result[0].title : lyrics.title
const artistaL = result[0].artist ? result[0].artist : lyrics.artist
const res = await fetch(global.API('https://some-random-api.com', '/lyrics', { title: artistaL + tituloL }));
const json = await res.json();
let img;
img = result.album.artwork;
} catch {
try {
img = json.thumbnail.genius;
} catch {
try {
img = result.album.artwork;
const bochil = await googleImage(`${artistaL} ${tituloL}`);
img = await bochil.getRandom();
} catch {
try {
img = json.thumbnail.genius;
} catch {
try {
const bochil = await googleImage(`${artistaL} ${tituloL}`);
img = await bochil.getRandom();
} catch {
img = lyrics.image;
}
}
img = lyrics.image;
}
}
}

const previewUrl = result[0]?.preview.replace('http://cdn-preview-', 'https://cdns-preview-').replace('.deezer.com', '.dzcdn.net');
const previewUrl = result[0]?.preview
.replace("http://cdn-preview-", "https://cdns-preview-")
.replace(".deezer.com", ".dzcdn.net");

const textoLetra = `${tradutor.texto2[0]} *${tituloL || ''}*\n${tradutor.texto2[1]} *${artistaL || ''}*\n\n${tradutor.texto2[2]} \n${lyrics.lyrics || 'Lyrics not found.'}`;
await conn.sendMessage(m.chat, { image: { url: img }, caption: textoLetra }, { quoted: m });
await conn.sendMessage(m.chat, { audio: { url: previewUrl }, fileName: `${artistaL || '-'} - ${tituloL || '-'}.mp3`, mimetype: 'audio/mp4' }, { quoted: m });
} catch (e) {
console.log(`Error: ${e.message}`)
throw `*${tradutor.texto2[3]}*`;
}
const textoLetra = `${tradutor.texto2[0]} *${tituloL || ""}*\n${tradutor.texto2[1]} *${artistaL || ""}*\n\n${tradutor.texto2[2]} \n${lyrics.lyrics || "Lyrics not found."}`;
await conn.sendMessage(
m.chat,
{ image: { url: img }, caption: textoLetra },
{ quoted: m },
);
await conn.sendMessage(
m.chat,
{
audio: { url: previewUrl },
fileName: `${artistaL || "-"} - ${tituloL || "-"}.mp3`,
mimetype: "audio/mp4",
},
{ quoted: m },
);
} catch (e) {
console.log(`Error: ${e.message}`);
throw `*${tradutor.texto2[3]}*`;
}
};
handler.help = ['lirik', 'letra'].map((v) => v + ' <Apa>');
handler.tags = ['internet'];
handler.help = ["lirik", "letra"].map((v) => v + " <Apa>");
handler.tags = ["internet"];
handler.command = /^(lirik|lyrics|lyric|letra)$/i;
export default handler;

/* Creditos: https://github.com/darlyn1234 */
async function searchLyrics(term) {
try {
if (!term) return "πŸŸ₯ Provide the name of the song to search the lyrics";
const geniusResponse = await axios.get(`https://apilyrics.vercel.app/genius?query=${term}`);
const geniusResponse = await axios.get(
`https://deliriussapi-oficial.vercel.app/search/genius?q=${term}`,
);
const geniusData = geniusResponse.data;
if (!geniusData.length) return `🟨 Couldn't find any lyrics for "${term}"`;
const lyricsUrl = geniusData[0].url;
const lyricsResponse = await axios.get(`https://apilyrics.vercel.app/lyrics?url=${lyricsUrl}`);
const lyricsResponse = await axios.get(
`https://deliriussapi-oficial.vercel.app/search/lyrics?url=${lyricsUrl}&parse=false`,
);
const result = {
status: '200',
creador: 'Sareth',
status: true,
creador: "Sareth",
title: geniusData[0].title || "",
fullTitle: geniusData[0].fullTitle || "",
artist: geniusData[0].artist.name || "",
Expand All @@ -82,7 +107,7 @@ async function searchLyrics(term) {
console.error(error.message);
return {
creador: "Sareth",
status: "error",
status: false,
message: new Error(error).message,
};
}
Expand Down

0 comments on commit 07cefaa

Please sign in to comment.