Important
Warning: Spotify doesn't provide any official lyrics API, this project is supposed to provide lyrics by requesting to spotify's WebPlayer lyrics API. So I can't host it for you. You can't use this API for any commercial use, this API is supposed to be self hosted and used in personal sites like your portfolio. I, BlankParticle or any other entity mentioned in the project will not responsible for anything.
I was creating my Portfolio when it occurred to me that I could add a Spotify Widget in my portfolio, I saw some examples but they all looked the same. So as a responsible developer, I tried to create a widget with lyrics, but spotify didn't have any lyrics API thus this Project was born.
Read more about How I created this project at my blog article.
Initially, this was a Svelte Kit Project, I used Svelte API routes with Vercel as a hosting. But later I thought that maybe I can create this as a Project with standalone serverless functions.
You can find code for different cloud providers in their respective folders.
- Cloudflare Workers (wrangler)
- Vercel
- Netlify
First clone this repo using git
git clone https://github.com/BlankParticle/spotapi.git
cd spotapi
Now you need Your Spotify User Cookie, You can make a new spotify account. You only need the sp_dc
cookie. Be sure not to leak this cookie because this can be used to login into your spotify account.
Note: This cookie may expire if you logout from your account or after 1 year of use, You must check for that and provide a new cookie when that happens.
Now save this cookie in a .env
file in project root
SPOTIFY_COOKIE=your-sp_dc-cookie
Then install NodeJs and npm
(or pnpm
/yarn
) if haven't already.
cp .env wrangler/.dev.vars
cd wrangler
npm install # or use "pnpm install" or "yarn"
npm run dev # or use "pnpm dev" or "yarn dev"
If all that works then you can go to http://localhost:8787/lyrics/4PTG3Z6ehGkBFwjybzWkR8 and test your worker.
If you don't have a cloudflare account, create one. Now type,
npm run add-secret # or use "pnpm add-secret" or "yarn add-secret"
then login (if prompted), and put your cookie.
Now you can run,
npm run deploy # or use "pnpm run deploy" or "yarn run deploy"
And, You have your self hosted Spotify Lyrics API.
I don't have time to figure out Vercel functions, I would be happy if someone makes a PR with Vercel function, same with Netlify
Copyright © 2023 BlankParticle.
This project is MIT licensed.