From 070fd351514521b5a2cea4184314a269ac42d934 Mon Sep 17 00:00:00 2001 From: LewdHuTao Date: Tue, 28 May 2024 12:05:01 +0800 Subject: [PATCH] fix genius not return artwork url --- package-lock.json | 4 ++-- package.json | 6 ++++-- src/index.js | 35 ++++++++++++++++++++++------------- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/package-lock.json b/package-lock.json index f8124a3..d6a9b12 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "llyrics", - "version": "1.0.8", + "version": "1.0.9", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "llyrics", - "version": "1.0.8", + "version": "1.0.9", "license": "ISC", "dependencies": { "node-fetch": "^3.3.2" diff --git a/package.json b/package.json index d12996f..33034e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "llyrics", - "version": "1.0.8", + "version": "1.0.9", "description": "A simple package to fetch lyrics from Genius API", "main": "src/index.js", "scripts": { @@ -20,7 +20,9 @@ "lyrics", "discord bot", "discord.js", - "genius api" + "genius api", + "musixmatch", + "youtube lyrics" ], "bugs": { "url": "https://github.com/shittybot/llyrics/issues" diff --git a/src/index.js b/src/index.js index 6e64a24..6442683 100644 --- a/src/index.js +++ b/src/index.js @@ -1,10 +1,12 @@ async function findLyrics({ - search_engine: { musixmatch, genius, youtube }, - song_title, - genius_api, + search_engine: { musixmatch, genius, youtube }, // search engine + song_title, // required + artist_name, // optional + genius_api, // optional if genius is set to false }) { - let apiBaseUrl = "https://lyrics.lewdhutao.my.eu.org"; + let apiBaseUrl = "https://lyrics.lewdhutao.my.eu.org"; // api url let songTitle = song_title; + let artistName = artist_name; let lyrics; let trackName; @@ -16,9 +18,21 @@ async function findLyrics({ try { if (musixmatch === true) { - const musixmatchResponse = await fetch( - `${apiBaseUrl}/musixmatch/lyrics?title=${encodeURIComponent(songTitle)}` - ); + let musixmatchResponse; + + if (artistName) { + musixmatchResponse = await fetch( + `${apiBaseUrl}/musixmatch/lyrics-search?title=${encodeURIComponent( + songTitle + )}&artist=${artistName}` + ); + } else { + musixmatchResponse = await fetch( + `${apiBaseUrl}/musixmatch/lyrics?title=${encodeURIComponent( + songTitle + )}` + ); + } const musixmatchData = await musixmatchResponse.json(); trackArtist = musixmatchData.artist_name; @@ -56,13 +70,8 @@ async function findLyrics({ artworkUrl = youtubeData.artwork_url; lyrics = youtubeData.lyrics; } - - if (!lyrics) { - throw new Error("No lyrics found."); - } } catch (error) { - console.error("Error:", error.message); - throw error; + return; } return {