Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Bindings to libspotify (focus on manipulating playlists) wrapped in a PHP extension.
C
branch: master

Merge pull request #3 from ptylr/master

Corrected incorrect method in latest version (Z_LVAL_P typo)
latest commit 7380ba6bf3
@vilhelmk authored
Failed to load latest commit information.
.gitignore
README.md Add toplist support for tracks, artist and albums. Add track isAvaila…
album.c Update album.c
albumiterator.c
artist.c Add toplist support for tracks, artist and albums. Add track isAvaila…
config.m4 Add toplist support for tracks, artist and albums. Add track isAvaila…
php_spotify.h Add toplist support for tracks, artist and albums. Add track isAvaila…
playlist.c implement track iterator
spotify.c Update spotify.c
toplist.c Add toplist support for tracks, artist and albums. Add track isAvaila…
track.c
trackiterator.c fix for not loaded tracks
user.c Add toplist support for tracks, artist and albums. Add track isAvaila…

README.md

Experimental libspotify PHP lib

Important notes

  • Read the libspotify license, there are some important things to note; for example you CAN NOT "attempt to embed or integrate the API into any website or otherwise allow access to the Service via the web rather than via the Application.".
  • The behaviour and API might change; this library is not production ready.

Installation

  • Install the libspotify dev files and binary that fits your system, get them from the Spotify developer website.
  • Run these commands: phpize; ./configure --enable-spotify; make && make install

Usage

// These two lines are only required if you want to use non-default paths.
ini_set("spotify.cache_location", "cache_location/");
ini_set("spotify.settings_location", "settings_location/");

$spotify = new Spotify("/path/to/key.file", "username", "password");

$coolTrack = $spotify->getTrackByURI('spotify:track:6JEK0CvvjDjjMUBFoXShNZ');

// List all playlists
$playlists = $spotify->getPlaylists(); // returns array of SpotifyPlaylist
foreach ($playlists as $playlist) {
    printf("%s (%d tracks, by %s)\n", $playlist, $playlist->getNumTracks(), $playlist->getOwner());

    foreach ($playlist->getTracks() as $track) {
        $duration = $track->getDuration();
        printf("  -> %s - %s [%02d:%02d]\n", $track->getArtist(), $track,
                $duration/60, $duration%60);
    }

    // and add a important piece of music
    $playlist->addTrack($coolTrack, 0 /*position*/);
}

Troubleshooting

  • Make sure that the process executing the PHP script has access to the cache- and settings-folders.

Credits

Thanks to

Jeroen Flamman

TODO

  • Instead of returning arrays of objects, change to iterators and/or arrayaccess.
  • Remove private functions and replace them with pure C functions.
  • Add possibility to receive tracks in inbox. Due to obvious reasons (spam) we SHOULD NOT implement a way to send tracks.
  • Add possibility to search for tracks.
Something went wrong with that request. Please try again.