A simple static PHP wrapper for Spotify's Metadata API.
Your feedback is always welcome.
- PHP 5.2.x or higher
- cURL
<?php
require_once 'spotify.class.php';
// Search for an artist by its name
$artist = Spotify::searchArtist('Maroon 5');
// Take a look at the response
echo '<pre>';
print_r($artist);
echo '<pre>';
?>
<?php
// Look up for an artist by its Spotify URI
Spotify::lookup('spotify:artist:58lV9VcRSjABbAbfWS6skp', 'album');
?>
<?php
// Search for a track
$track = Spotify::searchTrack('Narcotic');
// Receive the Spotify URI for the first track
$uri = Spotify::getUri($track); // spotify:track:6MSPmHR15vgpa0A5L205Xv
// Display Spotify link (opens Spotify player)
echo "<a href="/{$uri}"/>Play Song with Spotify</a>";
?>
All methods return the API data json_decode()
- so you can directly access the data.
searchArtist($name, <$page>)
searchAlbum($title, <$page>)
searchTrack($title, <$page>)
All <$page>
parameters are optional. If the page number is undefined, the first one will be returned (default).
lookup($uri, <$detail>)
$uri
is a valid Spotify URI like:spotify:artist:58lV9VcRSjABbAbfWS6skp
,spotify:track:4I4BS0OeI7VZdo5WeEQHFP
- the URI type will be automatically detected
$detail
defines the detail level in the response. Possible options are:- Artist:
album
,albumdetail
- Album:
track
,trackdetail
- Track:
no detail level available
- Artist:
getUri($obj, <$count>)
$obj
is a JSON object returned by one of the search methods$count
[optional] number of result (first result = 0 [default])
If you need additional informations, take a look at Spotify's API docs.
Spotify 1.2 - 04/01/2013
bug
Fixed undeclared static property errorupdate
Updated Spotify API doc URLs
Spotify 1.1 - 12/12/2011
feature
Changed class to static methodsupdate
Adjusted documentationchange
Removed default constructor
Spotify 1.0 - 27/11/2011
release
First official released versionfeature
AddedgetUri()
methodupdate
Detailed documentation
Spotify 0.5 - 26/11/2011
release
Beta versionupdate
Small documentation
Copyright (c) 2011 - Programmed by Christian Metz
Released under the BSD License.