farshed / genius-lyrics-api Goto Github PK
View Code? Open in Web Editor NEWA library for "fetching" song lyrics & album covers from genius.com 🎤 🎶
License: MIT License
A library for "fetching" song lyrics & album covers from genius.com 🎤 🎶
License: MIT License
Hey I'm recieving a very big error with status code 403. It was working fine on repl.it but the moment I hosted it on my Azure Vps it is throwing errors with status code 403
Hi, I'm wondering if you have an example of how this can be implemented entirely on the front end. I'm reasonably familiar with front end js but Node not so much. I'm not sure what needs to be done to the existing code to make that kind of implementation work. Thanks!
Hey there, I got a question about the way this tool is implemented: Why do I need an API token? From the looks of it, you're scraping the lyrics directly from the official webpage anyway. Wouldn't it make more sense to fetch lyrics through Genius' API?
The getLyrics() method returns an empty array instead of null for certain songs.
Set these as the options for search:
{ apiKey: 'APIKEY', title: 'DESPACITO', artist: 'LUIS%20FONSI%20FT.%20JUSTIN%20BIEBER', optimizeQuery: true }
getLyrics() works for many other songs that I try, including the example song shown in the readme. So far, this is the only song that has gone through the method to have returned an empty array instead of a string or a null value.
When trying to fetch the lyrics for the song "I Killed A Man (Live in Moscow)"
by the artist "Slaughter To Prevail"
,
somehow i get the contents of this page.
Code:
const options = {
apiKey: Bun.env.CLIENT_ACCESS_TOKEN,
title: "I Killed A Man (Live in Moscow)",
artist: "Slaughter To Prevail",
optimizeQuery: true,
};
const rawLyrics = await getLyrics(options);
console.log(rawLyrics);
It's very weird, any idea for how that's happening?
Hi, you work has really made life easier for me. Just wanted to let you know that there is a small error in the documentation.
Documentation states:
getSongById
Returns a promise that resolves to an array of type song.
In reality it returns a promise that resolves to an object of type song, not an array.
Axios issue: GHSA-4w2v-q235-vp99
Dependabot cannot automatically fix this issue in my repository. it says:
"The latest possible version that can be installed is 0.19.2 because of the following conflicting dependency:
[email protected] requires axios@^0.19.0
The earliest fixed version is 0.21.1."
Hi there
I tried implementing this solution. I am running my script locally and I keep running into a 401 error.
Here is the initial setup:
const geniusApi = require('genius-lyrics-api');
const apiConfig = {
apiKey: 'KkzEtd3JSxlUu1iy-XXXXXXXXXXXXXXXXXXXXXXXXX-PNpwuSc9ufTQByjZ8Nrq85A',
title: '',
artist: '',
optimizeQuery: true
};
And then I call it as follows:
function callLyricApi(songTitle, songArtist) {
return new Promise(function (resolve, reject) {
apiConfig.artist = songArtist;
apiConfig.title = songTitle;
//Call the remote API for lyrics
geniusApi.getLyrics(apiConfig)
.then((lyrics) => {
resolve(lyrics);
})
.catch((err) => {
console.error("Genius call failed", err);
reject(err);
})
});
}
Do you possibly know why I keep getting 401 error doing it like this?
I thought its just issue when I was developing the website using this library, so I used the addon to bypass the CORS rules. But I deployed it via firebase but I'm having the same issue. Is there any solution to that?
Please and thank you.
Hey hey,
Not able to scrap lyrics for following pages:
https://genius.com/Zfeelz-shame-lyrics
https://genius.com/Shinku-horou-niji-romanized-lyrics
Thanks,
Vitalii
getLyrics function works fine but it returns the lyrics in strings, official genius API docs has this responseFormat parameter, to plain, html, or dom, look into it.
genius-lyrics-api
npm module.For a little tiny bit of context, I'm making a Discord bot, and wanted to add a lyrics command to its music system. That's how I found your module.
It's working pretty good, but I noticed something.
When I call the getLyrics()
method, sometimes it'll return the entire lyrics, and sometimes just a chunk of it.
I made two pastebins with the two different outputs for a same song (K. Money - Come Outside).
Here is my code.
import * as Discord from "discord.js";
import { getLyrics } from "genius-lyrics-api";
import getArtistTitle from 'get-artist-title';
import * as dotenv from "dotenv";
dotenv.config();
// Music command
/**
* Skips actual guild music.
* @param {Discord.Client} Client the client
* @param {Discord.Message} Message the message that contains the command name
* @param {string[]} args the command args
* @param {any} options some options
*/
export async function run(Client: Discord.Client, message: Discord.Message, args: string[], ops: any) {
const accessToken = process.env.ACCESS_TOKEN;
const queue: any = await ops.queue.get(message.guild.id);
let songID;
let songArtist, songTitle;
async function retrieveArtistTitle() {
[songArtist, songTitle] = await getArtistTitle(queue.songs[0].title, {
defaultArtist: queue.songs[0].author.name
});
}
await retrieveArtistTitle();
const options = {
apiKey: accessToken,
title: songTitle,
artist: songArtist,
optimizeQuery: true
};
await gatherLyrics();
async function gatherLyrics() {
await getLyrics(options).then((lyrics) => {
if (lyrics == null) {
return message.channel.send(`No lyrics found for **${queue.songs[0].title}**.`);
} else {
const lyricsEmbedOne = new Discord.MessageEmbed()
.setAuthor(message.author.username, message.author.avatarURL())
.setDescription(lyrics.slice(0, lyrics.length / 2))
.setColor("#80F906")
.setFooter(`Lyrics (1) - ${Client.user.username}`, Client.user.avatarURL())
message.channel.send(lyricsEmbedOne);
const lyricsEmbedTwo = new Discord.MessageEmbed()
.setAuthor(message.author.username, message.author.avatarURL())
.setDescription(lyrics.slice(lyrics.length / 2, lyrics.length))
.setColor("#80F906")
.setFooter(`Lyrics (2) - ${Client.user.username}`, Client.user.avatarURL())
message.channel.send(lyricsEmbedTwo);
}
});
}
if (!queue) {
return message.channel.send("No song is currently playing.");
}
}
Music system works like a charm, so that doesn't cause the problem. Other modules used in this code are also working fine - same for my Genius Developer Token.
Thank you for reading this issue.
Get song by id gives me 401 response. I think it's because of this line ${url}${id}&access_token=${apiKey}
instead of ${url}${id}?access_token=${apiKey}
.
I have requested song lyrics "Amanhã talvez" and it returns song lyrics "Tentação".
title: 'Amanhã talvez',
artist: 'Joanna',
The artist found matches, but the song title does not.
I tried to search for Chinese, Japanese, Hebrew, and Arabic lyrics, but when doing so, I get a UnhandledPromiseRejectionWarning: TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters
.
Here's a log:
2020-06-28T06:47:53.331907+00:00 app[worker.1]: (node:23) UnhandledPromiseRejectionWarning: TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters
2020-06-28T06:47:53.331916+00:00 app[worker.1]: at new ClientRequest (_http_client.js:151:13)
2020-06-28T06:47:53.331917+00:00 app[worker.1]: at Object.request (https.js:310:10)
2020-06-28T06:47:53.331917+00:00 app[worker.1]: at RedirectableRequest._performRequest (/app/node_modules/follow-redirects/index.js:169:24)
2020-06-28T06:47:53.331918+00:00 app[worker.1]: at new RedirectableRequest (/app/node_modules/follow-redirects/index.js:66:8)
2020-06-28T06:47:53.331918+00:00 app[worker.1]: at Object.wrappedProtocol.request (/app/node_modules/follow-redirects/index.js:307:14)
2020-06-28T06:47:53.331919+00:00 app[worker.1]: at dispatchHttpRequest (/app/node_modules/genius-lyrics-api/node_modules/axios/lib/adapters/http.js:179:25)
2020-06-28T06:47:53.331919+00:00 app[worker.1]: at new Promise (<anonymous>)
2020-06-28T06:47:53.331919+00:00 app[worker.1]: at httpAdapter (/app/node_modules/genius-lyrics-api/node_modules/axios/lib/adapters/http.js:21:10)
2020-06-28T06:47:53.331920+00:00 app[worker.1]: at dispatchRequest (/app/node_modules/genius-lyrics-api/node_modules/axios/lib/core/dispatchRequest.js:52:10)
2020-06-28T06:47:53.331920+00:00 app[worker.1]: at runMicrotasks (<anonymous>)
2020-06-28T06:47:53.331920+00:00 app[worker.1]: (Use `node --trace-warnings ...` to show where the warning was created)
2020-06-28T06:47:53.331950+00:00 app[worker.1]: (node:23) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)
2020-06-28T06:47:53.331991+00:00 app[worker.1]: (node:23) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.```
I got the same problem as one of the closed (and never solved) issues. Its working on my computer but when I push it to the server it only returns 403. Maybe its the reverse proxy that causes the issue. It returns html that contains some sort of captcha.
Code is quite simple:
const genius = require('genius-lyrics-api')
function getLyrics(title) {
var searchOptions = {
title: title,
artist: " ",
apiKey: "XXX",
optimizeQuery: true
}
genius.getLyrics(searchOptions).then((lyrics) => {
console.log(lyrics);
});
}
Originally posted by @nicokimmel in #21 (comment)
Special characters present in a search query such as "&" are not properly encoded with the encodeURI() method present inside of the searchSong() method.
For example ;
the requested song : Safe & Sound by Taylor Swift
will return the song: It Ain't Safe by Skepta (Ft. A$AP Bari)
Possible fix:
Replace the method encoreURI() with encodeURIComponent(). This change will make the above example return the good song. However, I didn't do a large test sample to ensure the effectiveness of this change for different combinations of songs and special character like (&, ?, etc.)
Do I need to run any build npm or yarn command first?
Can this script run independently on a website?
or - Does it strictly depend of a Node.js server in order to run in production?
Thanks for your help and support!
Hey! Getting a Cross-Origin Request Blocked response from Genius on local host and on Netlify.
Is there an updated workaround for this?
Cheers!
as in the title, using the library works just fine on my desktop but once the code is ran on my server it just 403's.
.
Refs #3
I'm currently experience CORS issue on the app deployed to Heroku:
Access to XMLHttpRequest at 'https://api.genius.com/search?q=xxxx' from origin 'https://xxx.herokuapp.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
Code is working fine locally in the Chrome with --disable-web-security
flag.
genius-lyrics-api
version : 3.0.3
Hey, first of all thanks for this cool api 😄 , it's a shame we can't get the lyrics directly from genius 😒
I'm getting this Network Error while accessing the api in production :
XMLHttpRequest cannot load http://api.genius.com/songs/3977187 due to access control checks.
I tested on a browser with disabled web security, and it still doesn't work BUT there is another error :
Mixed Content: The page at 'https://myapp.com/lyrics' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://api.genius.com/songs/333387'. This request has been blocked; the content must be served over HTTPS.
So I don't really know how to fix this...
Any ideas ?
Dear,
I'm a novice in all this, but reading I'm doing things.
I have a js app that gets the artist name and song name that plays on an online radio and stores them in currentArtist
and currentSong
variables
I want to combine your app to get the lyric.
this.refreshLyric = function (currentSong, currentArtist) {
//testing API genius
......
}
Could you explain to me as a child what code should I put in my app so that it returns a lyrics
variable with the lyrics of the song?
Best regards,
Juan
I would like to use this library from browser.
In order to fight the CORS , improve performance and lower the load on actual API, I am setting up a CDN that will have the same domain name as my website but will redirect all calls to genius.com.
Current Behavior
I have a React toy project which fetches current playback on Spotify and uses the song info to be put into the options parameter for getLyrics. I forked and modified the library where the access token is sent to the Genius API within the URL so the CORS block error won't happen on API requests.
However, I'm now facing the CORS block error on my Netlify deployment when the request is sent to a song lyric's page so I'm wondering if there's a way to solve this problem. Also, as can be seen in the image I also had modified the baseUrl in GetLyricsFromPath.js so that thingproxy is at front of the genius url, so it looks like below;
const baseUrl = 'https://thingproxy.freeboard.io/fetch/https://www.genius.com';
Both the original baseUrl and modified baseUrl returns a CORS error on my deployed web app, however with the modified baseUrl it works well on localhost.
In a nutshell,
Steps to reproduce
Deploy build of React web app using the library with Netlify/Surge/etc.
Hello! It seems like the library has a hardcoded limit of 4000 characters for the lyrics, was that intentional?
Here's an example of a song I was trying to grab lyrics for
https://genius.com/Jay-z-and-linkin-park-points-of-authority-99-problems-one-step-closer-lyrics
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.