How to install

Look at some of the examples or read the FeatureList for help using MetaTune.

Features

Some features includes:

Search for Track/Artist/Album

Lookup detailed/basic info about Track/Artist/Album

Exceptions for error handling.

Caching metadata.

XML Import/Export for quick save/load.

Generate Play Buttons from searches/lookups or objects.

NEW: Now uses namespaces to be more pluggable.

Look at the Wiki for usage and full support.
The usage of the regular metatune class can be read below the new Play Button implementation.

New: Namespaces

Metatune now uses namespaces to be more pluggable and play better with other libraries. This means that you'll need PHP version 5.3 or later
to be able to use the comming versions of MetaTune. The old version is still available in it's own branch
(no-namespace), but will no longer be updated/maintained.

You use metatune as before, but you should update your autoload script and now use $metatune = MetaTune\MetaTune::getInstance() to get the
metatune instance variable.

Play Button implementation

The Metatune wrapper now supports the new Spotify Play Button. The play buttons can be generated from the history of your searches/lookups, from an album or track object, a playlist URI or just an array of tracks.
See the examples below the settings

Settings

Variable name

Description

playButtonHeight

Height of the player (int). To be large player, the height needs to be 80px more than the width. Default: 330.

Result

Play Button from album object.

<?php// Get the metatune instance. $spotify=MetaTune\MetaTune::getInstance();try {// Need to be detailed, to have all tracks. (second argument true)$album=$spotify->lookupAlbum("spotify:album:6MBuQugGuX7VMBX0uiBnAQ", true);echo$spotify->getPlayButtonFromAlbum($album); }catch (MetaTune\MetaTuneException$ex) {die("<pre>Error\n".$ex."</pre>"); }?>

Result

More examples in the examples directory.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

SPOTIFY Disclaimer
This product uses a SPOTIFY API but is not endorsed, certified or otherwise
approved in any way by Spotify. Spotify is the registered trade mark of the
Spotify Group.

Usage

You can pretty much do anything in the Spotify Metadata API with this library, and then some. Below you'll find all the features and some short example of how to use them.

In common for all the features, it requires a object of the MetaTune-class.

<?php$spotify=MetaTune\MetaTune::getInstance();?>

Search for Track/Artist/Album

You can search for everything in MetaTune. Not only tracks, but albums and artists aswell. In this example however, I will limit myself to just showing search for artists. The code would essentially be the same.

Method overview

Description

searchTrack()

Search for tracks. Will return an array of tracks

searchArtist()

Search for artists. Will return an array of artists

searchAlbum()

Search for albums. Will return an array of albums

<?php// We have the MetaTune-object; $spotify// First we take a search$trackResults=$spotify->searchTrack ("Superfamily");if(count($trackResults) >0) {$out=count($trackResults) ." results \n<ul>";foreach($trackResultsas$track) {// $track is now an object of the class Track. $out."\t<li>{$track}</li>\n"; }echo$out."</ul>";} else {echo"No results";}?>

Spotify advanced search syntax

Lookup detailed/basic info about Track/Artist/Album

Some times all you got is a Spotify URI, such as spotify:track:4CwcvWeCi2rFcLPIJCOwXw, and want to lookup detailed/basic information about a Track/Artist/Album.

Method overview

Description

lookupTrack()

Get all information about a track. Popularity, duration, artist, album, number and disc in album

lookupArtist()

Get basic information about an artist. This includes name and popularity

lookupArtistDetailed()

Get detailed information about an artist. This includes basic info + all the artist's albums

lookupAlbum()

Get basic info about an album. This includes release date, popularity, name.

lookupAlbumDetailed()

Get detailed information about an album. This includes basic info + all the album's tracks.

lookup()

Uses the Spotify URI to determine what to look up.

<?php// We have the MetaTune-object; $spotify// Get all information about a track!$track=$spotify->lookup("spotify:track:4CwcvWeCi2rFcLPIJCOwXw");// Print all resultsecho"<pre>".print_r($track, 1) ."</pre>";?>

Exceptions

But what if the Spotify URI is in a wrong format or is not found? Then we have exceptions to tell us. Lets try to use exceptions in the example from lookup.

<?php// We have the MetaTune-object; $spotifytry {// Get all information about a track!$track=$spotify->lookup("spotify:track:WRONG_URI");// all lookup-methods throws a MetaTuneException. We'll try to catch one. // Print all resultsecho"<pre>".print_r($track, 1) ."</pre>";} catch (MetaTuneException$ex) {echo"Could not retrive information: ".$ex->getMessage();}?>

Caching

All access to the Spotify-servers will be cached as long as certain constants are set in the MetaTune class. Caching is activated per default.

The caching works by saving files locally on your server with this format: path/to/dir/<YOUR_PREFIX>_<MD5("THE_SEARCH_QUERY")>.xml

Search query is stripped of some non-alphanumerical signs and trimmed.

The Spotify servers only send information on requests as long as If-Modified-Since header field doesn't kick in. If a cache exists of a search the header field would be appended to the file request, and Spotify won't send you any data. All this happens automaticly as long as you have caching activated.

To activate/deactivate or change cache settings in any way, you can do this at the top of MetaTune

XML Import/Export

With XML import and/or export you can easily create XML structure of your searches. All ready to be saved to files and/or database (XML-types).

Here's an example of usage:

<?php// ***Test for array of tracks***$trackList=$spotify->searchTrack("Superfamily");$tracksXML=$spotify->generateXML($trackList);// This should now be the same as $trackList$tracksImport=$spotify->parseXMLTracks($tracksXML);// Demo print to check correct contentecho"<pre>".print_r($tracksImport, 1) ."</pre>";?>