Git Product home page Git Product logo

libspotify-php's Introduction

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.

libspotify-php's People

Contributors

hexxeh avatar marklkelly avatar ptylr avatar vilhelmk avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.