Skip to content
This repository has been archived by the owner on Nov 15, 2024. It is now read-only.

Commit

Permalink
fix genius not return artwork url
Browse files Browse the repository at this point in the history
  • Loading branch information
LewdHuTao committed May 28, 2024
1 parent 3b27c31 commit 070fd35
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -20,7 +20,9 @@
"lyrics",
"discord bot",
"discord.js",
"genius api"
"genius api",
"musixmatch",
"youtube lyrics"
],
"bugs": {
"url": "https://github.com/shittybot/llyrics/issues"
Expand Down
35 changes: 22 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 070fd35

Please sign in to comment.