lyricist
lyricist copied to clipboard
Fix with Genius UI update
The lyrics are now shown in two places in the html, once in the thing with the class .lyrics
and once for react preloading or something in a script tag. I would have used the one in the .lyrics
div but cheerio doesn't seem to have anything similar to html .innerText
that gets the text content including <br />
tags as newlines. There might be an easier way to do this than what I've done.
Hi I haven't had any issue using the package to fetch lyrics (last used it ~2 months ago). Could you clarify the issue this PR fixes?
Tested again - lyrics fetching is not working at all for me and just returning an empty string.
const {lyrics} = await lyricist.song(song_id, {fetchLyrics: true});
console.log(lyrics); // empty string
Applying this patch makes it work again.
If I go to a lyrics page on the genius website, document.querySelectorAll(".lyrics")
returns an empty array
It might be possible that this update is not completely rolled out or there's some difference on your system making it return the old version of the page?
This PR is much more complex than it needs to be to fix this issue, ideally it could just be document.querySelector("#lyrics-root").innerText
but cheerio doesn't support innerText and textContent can't be used because it doesn't include br tags. It could likely be significantly simplified by looping over the dom elements rather than trying to parse text out of the react preload script. Also, if some people are seeing a different page, it should support both .lyrics
and #lyrics-root
so this doesn't break anything for people.
Oh I'm sorry. I just checked the project repo where it worked fine and it was actually Nov 4-5, so a bit more than the 2 months I remembered. Running the code now returns an empty string for lyrics... it must have been a slow rollout(?).
Thank you for the PR, I'll take a look at the new layout and see if it can be done a simpler way.