vilhelmk / libspotify-php

Bindings to libspotify (focus on manipulating playlists) wrapped in a PHP extension.
23 stars 7 forks source link

Experimental libspotify PHP lib

Important notes

Installation

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

Credits

Thanks to

Jeroen Flamman

TODO