Get lyrics data from Spotify
Asked Answered
P

2

6

I already figured out the URL is https://spclient.wg.spotify.com/color-lyrics/v2/track/${TRACK_ID}?format=json&vocalRemoval=false

And it requires two headers. app-platform: WebPlayer and authorization: Bearer TOKEN.

So using curl I am able to get the lyrics information like that:

$ TRACK_ID=3z8h0TU7ReDPLIbEnYhWZb
$ BEARER_TOKEN=xxxxxxxxxxxxxx
$ curl "https://spclient.wg.spotify.com/color-lyrics/v2/track/${TRACK_ID}?format=json&vocalRemoval=false" -H "app-platform: WebPlayer" -H "authorization: Bearer ${BEARER_TOKEN}"
{
  "lyrics": {
    "syncType": "LINE_SYNCED",
    "lines": [
      {
        "startTimeMs": "110",
        "words": "Is this the real life? Is this just fantasy?",
        "syllables": [],
        "endTimeMs": "0"
      },
      {
        "startTimeMs": "6990",
        "words": "Caught in a landslide, no escape from reality",
        "syllables": [],
        "endTimeMs": "0"
      },
      ...

The actual question is how do I programmatically get the required bearer token? I've tried a token requested using Get Token button on this site: https://developer.spotify.com/console/get-track/

But that token only appears to work for the official API. For the lyrics API I always get the following response for that token:

{
  "error": {
    "status": 403,
    "message": "Client not allowed"
  }
}

Also, the bearer tokens from the link above are way shorter and contain no dashes.

I know I can just copy the Bearer Token that is used by the web client on https://open.spotify.com but the token always expires after a very short amount of time.

So I'm either looking for a manual way to get a permanent token or for a way to programmatically get short-lived tokens.

I'm not looking for a solution in a specific programming language. Any language will do or an abstract explanation.

Pasteboard answered 13/9, 2022 at 14:11 Comment(4)
According to this news article, the lyrics comes from Musixmatch. Musixmatch has it's own API and documentation.Kary
I'm wondering the exact same thing. I really want to avoid going to the open.spotify.com website and programmatically stealing a bearer token from there. I already have the entire "legit" OAuth flow set up in my application, and it sucks Spotify won't accept a bearer token from there.Untimely
@Kary I do mean getting the lyrics of a track, and I did read your comment. However, the Musixmatch API is useless for free users (it only provides 30% of the lyrics per song), and I am not in the position to request and pay for a paid license. There should be a better middle ground for hobbyists. Hence why I am trying to get the lyrics from Spotify (which, I am aware, is just being forwarded from Musixmatch).Untimely
I think Selenium seems like the obvious choice here. It is quite frustrating that musixmatch don't even tell you how much they charge for the premium API ... I emailed a while back but I still haven't heard from them.Superorganic
M
3

You can use the token from here: https://open.spotify.com/get_access_token

The only downside is, that it's not documented, but so is spclient.wg.spotify.com

Metropolis answered 17/11, 2022 at 13:15 Comment(0)
T
2

This API is not designed nor documented for public use, and is additionally not licensed (see Musixmatch's API, where Spotify gets their lyrics from anyway), so using it (or bragging about finding it on StackOverflow) will likely only have Spotify further lockdown their API, and you (unlikely but possibly) getting into legal trouble (IANAL).

That being said, these Bearer xxx tokens are different to the ones created from Spotify's official API, and the easiest way to find these tokens is just by automating the process of logging in (probably in a browser), and making the request (these tokens may need to be refreshed either every few minutes/hours/days, so automation is key here). I'd suggest to start looking into Puppeteer or MS Playwright on a headless browser, and just retrieving Bearer tokens from there. If the API seems to break with those Bearer tokens, it may be best to perform the request from Puppeteer itself in the browser, by replicating the original request, and amending the song ID.

I am aware btw of how annoying Musixmatch can be, so I completely understand if the 2nd paragraph is the way you're going to go.

Tradelast answered 26/9, 2022 at 12:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.