PHP code example of akashrchandran / spotify-lyrics-api

1. Go to this page and download the library: Download akashrchandran/spotify-lyrics-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

akashrchandran / spotify-lyrics-api example snippets



SpotifyLyricsApi\Spotify;
use SpotifyLyricsApi\SpotifyException;

$spotify = new Spotify("SP_DC here");

try {
    $spotify->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";
}

// 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']);

php -S localhost:8080 api/index.php