百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

spotify-lyrics-api

> 编程语言
开源

一个用于从 Spotify 获取歌词的 REST API,由 Musixmatch 提供支持。命令行版本可在 akashrchandran/syrics 中找到。

629 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

一个用于从 Spotify 获取歌词的 REST API,由 Musixmatch 提供支持。命令行版本可在 akashrchandran/syrics 中找到。


[!WARNING] This project is probably against Spotify TOS. Use at your own risks.

[!NOTE] Changed this project into a template repository, deploy your own version. If you need help, don't hesitate to open an issue.

Quick Start with Docker

The easiest way to run the API is using Docker:

bash
docker run -d -p 8080:8080 -e SP_DC=your_sp_dc_cookie akashrchandran/spotify-lyrics-api

Then access the API at http://localhost:8080/?trackid=YOUR_TRACK_ID

Docker Compose

yaml
services:
  spotify-lyrics-api:
    image: akashrchandran/spotify-lyrics-api:latest
    ports:
      - "8080:8080"
    environment:
      - SP_DC=your_sp_dc_cookie
    restart: unless-stopped

View on Docker Hub

Install using Composer

composer require akashrchandran/spotify-lyrics-api

Fetching Lyrics

For now it only supports track id or link.

Using GET Requests

You have to use query paramters to send data

Available Parameters:

Parameter Default value Type Description
trackid None String The trackid from spotify.
url None String The url of the track from spotify.
format "id3" String The format of lyrics required. Options: id3, lrc, srt, raw.

You must specify either trackid or url, otherwise it will return error.

Examples

Using trackid

http://localhost:8080/?trackid=5f8eCNwTlr0RJopE9vQ6mB

Using url

http://localhost:8080/?url=https://open.spotify.com/track/5f8eCNwTlr0RJopE9vQ6mB?autoplay=true

response:

json
{
    "error": false,
    "syncType": "LINE_SYNCED",
    "lines": [
        {
            "startTimeMs": "960",
            "words": "One, two, three, four",
            "syllables": [],
            "endTimeMs": "0"
        },
        {
            "startTimeMs": "4020",
            "words": "Ooh-ooh, ooh-ooh-ooh",
            "syllables": [],
            "endTimeMs": "0"
        }
    ]
}

Changing format to lrc

http://localhost:8080/?trackid=5f8eCNwTlr0RJopE9vQ6mB&format=lrc

response:

json
{
    "error": false,
    "syncType": "LINE_SYNCED",
    "lines": [
        {
            "timeTag": "00:00.96",
            "words": "One, two, three, four"
        },
        {
            "timeTag": "00:04.02",
            "words": "Ooh-ooh, ooh-ooh-ooh"
        }
    ]
}

Responses

Different Responses given out by the API, are listed here.

If any error occurs the value of the error key will be set to true else false

json
"error": false //no error occured

Most of the lyrics are time synced or have timetags and some aren't time synced or have timetags. To differentiate between synced and unsynced we have key syncType.

json
"syncType": "LINE_SYNCED"

Musixmatch supports Line synced and Word synced type of timed lyrics. Line Synced is the timetag is given till which the line is sang and the word synced lyrics time specifed when the word comes up in the song. For now Spotify only supports line synced. Maybe they would support word synced in the future :/.

LINE Synced

json
{
    "error": false,
    "syncType": "LINE_SYNCED",
    "lines": [
        {
            "timeTag": "00:00.96",
            "words": "One, two, three, four"
        },
        {
            "timeTag": "00:04.02",
            "words": "Ooh-ooh, ooh-ooh-ooh"
        }
    ]
}

NOT Synced or Unsynced

Note the timeTags is set to 00:00.00.

json
{
    "error": false,
    "syncType": "UNSYNCED",
    "lines": [
        {
            "timeTag": "00:00.00",
            "words": "jaane nahin denge tuje"
        },
        {
            "timeTag": "00:00.00",
            "words": "chaahe tujh ko rab bulaa le, hum naa rab se darane waale"
        }
    ]
}

Error Messages

When trackid and url both are not given (400 Bad Request)

error response:

json
{
    "error": true,
    "message": "url or trackid parameter is required!"
}

When no lyrics found on spotify for given track (404 Not Found)

error response:

json
{
    "error": true,
    "message": "lyrics for this track is not available on spotify!"
}

Using as package

Install using composer require akashrchandran/spotify-lyrics-api.

Include the package's autoloader file in your PHP code and call class Spotify().

php
checkTokenExpire();
    $lyrics = $spotify->getLyrics(track_id: "1418IuVKQPTYqt7QNJ9RXN");
    
    // $lyrics contains the parsed lyrics data
    echo "Sync Type: " . $lyrics['lyrics']['syncType'] . "\n";
    
    foreach ($lyrics['lyrics']['lines'] as $line) {
        echo "[" . $line['startTimeMs'] . "] " . $line['words'] . "\n";
    }
} catch (SpotifyException $e) {
    // Handle errors (rate limiting, not found, etc.)
    echo "Error: " . $e->getMessage() . "\n";
    echo "Status Code: " . $e->getCode() . "\n";
}

Formatting Lyrics

php
// Get lyrics in LRC format
$lrcLines = $spotify->getLrcLyrics($lyrics['lyrics']['lines']);

// Get lyrics in SRT format
$srtLines = $spotify->getSrtLyrics($lyrics['lyrics']['lines']);

// Get raw lyrics (plain text)
$rawLines = $spotify->getRawLyrics($lyrics['lyrics']['lines']);

Deployment

Want to host your own version of this API, But first you need SP_DC cookie from spotify

Finding SP_DC

You will find the detailed guide here.

Heroku Vercel Run locally

use git to clone the repo to your local machine or you can download the latest zip file and extract it.

You need to have PHP installed on you machine to run this program.

Enter into the folder via terminal

bash
cd spotify-lyrics-api

Set SP_DC token as environment variable temprorily

bash
export SP_DC=[token here and remove the square brackets]

Start the server

php -S localhost:8080 api/index.php

now open your browser and type localhost:8080 and you should see the program running.

Credits

• Me -> For everything.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPhacktoberfestlyricsmusixmatchspotify

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言