Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

better readme, misc bug fixes, remove non-working getNumSubscribers

  • Loading branch information...
commit 84d394ddbf23556fd30dad59a8184382bedef651 1 parent 012f7d4
@vilhelmk authored
Showing with 48 additions and 16 deletions.
  1. +11 −7 README.md
  2. +26 −0 php_spotify.h
  3. +10 −4 playlist.c
  4. +1 −5 spotify.c
View
18 README.md
@@ -18,17 +18,21 @@
$spotify = new Spotify("/path/to/key.file", "username", "password");
- // All tracks in the starred playlist
- $starredPlaylist = $spotify->getStarredPlaylist(); // returns SpotifyPlaylist
- foreach ($starredPlaylist as $track) {
- printf("%s - %s\n", $track->getArtist(), $track);
- }
+ $coolTrack = $spotify->getTrackByURI('spotify:track:6JEK0CvvjDjjMUBFoXShNZ');
// List all playlists
$playlists = $spotify->getPlaylists(); // returns array of SpotifyPlaylist
foreach ($playlists as $playlist) {
- printf("%s\n", $playlist->getName());
- // print_r($playlist->getTracks());
+ 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*/);
}
## Credits
View
26 php_spotify.h
@@ -1,3 +1,28 @@
+/*
+Copyright (c) 2011 Vilhelm K. Vardøy, vilhelmkv@gmail.com
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
#ifndef PHP_SPOTIFY_H
#define PHP_SPOTIFY_H 1
@@ -28,6 +53,7 @@ typedef struct {
zend_object std;
sp_session *session;
sp_playlist *playlist;
+ int has_subscribers;
} spotifyplaylist_object;
typedef struct {
View
14 playlist.c
@@ -32,6 +32,7 @@ PHP_METHOD(SpotifyPlaylist, __construct)
zval *object = getThis();
zval *parent;
sp_playlist *playlist;
+ int timeout = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Oz", &parent, spotify_ce, &playlist) == FAILURE) {
return;
@@ -42,6 +43,10 @@ PHP_METHOD(SpotifyPlaylist, __construct)
obj->session = p->session;
obj->playlist = playlist;
+ while (!sp_playlist_is_loaded(playlist)) {
+ sp_session_process_events(p->session, &timeout);
+ }
+
sp_playlist_add_ref(obj->playlist);
}
@@ -103,10 +108,10 @@ PHP_METHOD(SpotifyPlaylist, getDescription)
RETURN_STRING(sp_playlist_get_description(p->playlist), 1);
}
-PHP_METHOD(SpotifyPlaylist, getNumSubscribers)
+PHP_METHOD(SpotifyPlaylist, getNumTracks)
{
spotifyplaylist_object *p = (spotifyplaylist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
- RETURN_LONG(sp_playlist_num_subscribers(p->playlist));
+ RETURN_LONG(sp_playlist_num_tracks(p->playlist));
}
PHP_METHOD(SpotifyPlaylist, getTrackCreateTime)
@@ -118,7 +123,6 @@ PHP_METHOD(SpotifyPlaylist, getTrackCreateTime)
return;
}
-
spotifyplaylist_object *p = (spotifyplaylist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
RETURN_LONG(sp_playlist_track_create_time(p->playlist, Z_LVAL_P(z_index)));
}
@@ -198,6 +202,8 @@ PHP_METHOD(SpotifyPlaylist, addTrack)
spotifytrack_object *track_obj = (spotifytrack_object*)zend_object_store_get_object(track TSRMLS_CC);
tracks[0] = track_obj->track;
+ sp_track_add_ref(track_obj->track);
+
int position;
if (Z_TYPE_P(z_position) == IS_NULL || Z_LVAL_P(z_position) < 0) {
@@ -264,7 +270,7 @@ function_entry spotifyplaylist_methods[] = {
PHP_ME(SpotifyPlaylist, getTracks, NULL, ZEND_ACC_PUBLIC)
PHP_ME(SpotifyPlaylist, getOwner, NULL, ZEND_ACC_PUBLIC)
PHP_ME(SpotifyPlaylist, getDescription, NULL, ZEND_ACC_PUBLIC)
- PHP_ME(SpotifyPlaylist, getNumSubscribers, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(SpotifyPlaylist, getNumTracks, NULL, ZEND_ACC_PUBLIC)
PHP_ME(SpotifyPlaylist, getTrackCreateTime, NULL, ZEND_ACC_PUBLIC)
PHP_ME(SpotifyPlaylist, getTrackCreator, NULL, ZEND_ACC_PUBLIC)
PHP_ME(SpotifyPlaylist, isCollaborative, NULL, ZEND_ACC_PUBLIC)
View
6 spotify.c
@@ -156,10 +156,6 @@ PHP_METHOD(Spotify, getPlaylists)
for (i=0; i<num_playlists; i++) {
sp_playlist *playlist = sp_playlistcontainer_playlist(p->playlistcontainer, i);
- while (!sp_playlist_is_loaded(playlist)) {
- sp_session_process_events(p->session, &timeout);
- }
-
zval *z_playlist;
ALLOC_INIT_ZVAL(z_playlist);
object_init_ex(z_playlist, spotifyplaylist_ce);
@@ -340,7 +336,7 @@ static void logged_out(sp_session *session)
static void log_message(sp_session *session, const char *data)
{
- //php_printf("SPOTIFY_ERR: %s\n", data);
+ //php_printf("SPOTIFY_DEBUG: %s", data);
}
function_entry spotify_methods[] = {
Please sign in to comment.
Something went wrong with that request. Please try again.