This repository has been archived by the owner on Nov 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
215 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,72 @@ | ||
const axios = require("axios"); | ||
async function findLyrics({ | ||
search_engine: { musixmatch, genius }, | ||
song_title, | ||
genius_api, | ||
}) { | ||
let apiBaseUrl = "https://lyrics.lewdhutao.my.eu.org"; | ||
let songTitle = song_title; | ||
|
||
async function findLyrics(apiKey, songName) { | ||
|
||
let api_key = apiKey; | ||
let song_Name = songName; | ||
let lyrics; | ||
let trackName; | ||
let trackName; | ||
let trackArtist; | ||
let artworkUrl; | ||
let searchEngine; | ||
|
||
try { | ||
const searchResponse = await axios.get(`https://llyrics-api.vercel.app//lyrics?title=${song_Name}&geniusAPI=${api_key}`) | ||
if (searchResponse.status === 200) { | ||
const searchData = searchResponse.data; | ||
lyrics = searchData.lyrics; | ||
trackName = searchData.trackName; | ||
trackArtist = searchData.trackArtist; | ||
if (!lyrics) throw new Error("No lyrics found."); | ||
findLyrics.lyrics = lyrics; | ||
findLyrics.trackName = trackName; | ||
findLyrics.trackArtist = trackArtist; | ||
} | ||
if (musixmatch === true) { | ||
const musixmatchResponse = await fetch( | ||
`${apiBaseUrl}/musixmatch/lyrics?title=${encodeURIComponent(songTitle)}` | ||
); | ||
const musixmatchData = await musixmatchResponse.json(); | ||
|
||
trackArtist = musixmatchData.artist_name; | ||
trackName = musixmatchData.track_name; | ||
searchEngine = musixmatchData.search_engine; | ||
artworkUrl = musixmatchData.artwork_url; | ||
lyrics = musixmatchData.lyrics; | ||
|
||
if (!lyrics && genius === true) { | ||
const geniusResponse = await fetch( | ||
`${apiBaseUrl}/genius/lyrics?title=${encodeURIComponent(songTitle)}&api_key=${genius_api}` | ||
); | ||
const geniusData = await geniusResponse.json(); | ||
|
||
trackArtist = geniusData.artist_name; | ||
trackName = geniusData.track_name; | ||
searchEngine = geniusData.search_engine; | ||
artworkUrl = geniusData.artworkUrl; | ||
lyrics = geniusData.lyrics; | ||
} | ||
} else if (genius === true) { | ||
const geniusResponse = await fetch( | ||
`${apiBaseUrl}/genius/lyrics?title=${encodeURIComponent(songTitle)}&api_key=${genius_api}` | ||
); | ||
const geniusData = await geniusResponse.json(); | ||
|
||
trackArtist = geniusData.artist_name; | ||
trackName = geniusData.track_name; | ||
searchEngine = geniusData.search_engine; | ||
artworkUrl = geniusData.artworkUrl; | ||
lyrics = geniusData.lyrics; | ||
} else { | ||
throw new Error("Both Musixmatch and Genius are disabled."); | ||
} | ||
|
||
if (!lyrics) { | ||
throw new Error("No lyrics found."); | ||
} | ||
} catch (error) { | ||
throw new Error(error); | ||
console.error("Error:", error.message); | ||
throw error; | ||
} | ||
|
||
return { | ||
trackArtist, | ||
trackName, | ||
searchEngine, | ||
artworkUrl, | ||
lyrics | ||
}; | ||
} | ||
|
||
module.exports = findLyrics; | ||
module.exports = { findLyrics }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const { findLyrics } = require("../index"); | ||
require("dotenv").config(); | ||
|
||
async function testFindLyrics() { | ||
try { | ||
console.log("Testing with Musixmatch enabled:"); | ||
const musixmatch = await findLyrics({ | ||
search_engine: { musixmatch: true, genius: false }, | ||
song_title: "fly high", | ||
}); | ||
|
||
const musixmatch_artist = musixmatch.trackArtist; | ||
const musixmatch_track = musixmatch.trackName; | ||
const musixmatch_lyrics = musixmatch.lyrics; | ||
const musixmatch_data = { | ||
musixmatch_artist, | ||
musixmatch_track, | ||
musixmatch_lyrics, | ||
}; | ||
|
||
console.log("\nTesting with Genius enabled:"); | ||
const genius = await findLyrics({ | ||
search_engine: { musixmatch: false, genius: true }, | ||
song_title: "fly high", | ||
genius_api: process.env.GENIUS_API, | ||
}); | ||
|
||
const genius_artist = genius.trackArtist; | ||
const genius_track = genius.trackName; | ||
const genius_lyrics = genius.lyrics; | ||
const genius_data = { genius_artist, genius_track, genius_lyrics }; | ||
|
||
if (musixmatch_data && genius_data) { | ||
console.log("Test Passed"); | ||
} | ||
} catch (error) { | ||
console.error("Error:", error.message); | ||
} | ||
} | ||
|
||
testFindLyrics(); |