Git Product home page Git Product logo

sejeong-park / spotify-lyrics-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from akashrchandran/spotify-lyrics-api

0.0 0.0 0.0 63 KB

A Rest API for fetching lyrics from Spotify which is powered by Musixmatch. Commandline version is available at akashrchandran/syrics.

Home Page: http://github.akashrchandran.in/spotify-lyrics-api/

License: GNU General Public License v3.0

PHP 99.40% Procfile 0.60%

spotify-lyrics-api's Introduction

spotify-lyrics-api


A Rest API for fetching lyrics from Spotify which is powered by Musixmatch. Commandline version is available 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.

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. It has 2 options either id3 or lrc.

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

Examples

Using trackid

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

Using url

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

response:

{
    "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:

{
    "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

"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.

"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

{
    "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.

{
    "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:

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

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

error response:

{
    "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
require('./vendor/autoload.php');

$spotify = new SpotifyLyricsApi\Spotify("SP_DC here");
$spotify->checkTokenExpire();
$reponse = $spotify -> getLyrics(track_id: "1418IuVKQPTYqt7QNJ9RXN");
?>

image

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

Deploy

Vercel

Deploy with 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

cd spotify-lyrics-api

Set SP_DC token as environment variable temprorily

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

Start the server

php -S localhost:8000 api/index.php

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

Credits

โ€ข Me -> For everything.

spotify-lyrics-api's People

Contributors

akashrchandran avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.