Permalink
Browse files

Add toplist support for tracks, artist and albums. Add track isAvaila…

…ble method. Add album getCover method. Add playlist getImage method. Add artist getPortrait method.
  • Loading branch information...
1 parent 13d06a0 commit 0318f0712c9aebd35cdc98bf6ddcefae8c8a940e @Hexxeh Hexxeh committed with Feb 19, 2012
Showing with 522 additions and 19 deletions.
  1. +2 −1 README.md
  2. +58 −0 album.c
  3. +1 −1 albumiterator.c
  4. +86 −0 artist.c
  5. +1 −1 config.m4
  6. +8 −0 php_spotify.h
  7. +85 −5 spotify.c
  8. +267 −0 toplist.c
  9. +14 −0 track.c
  10. +0 −11 user.c
View
@@ -45,7 +45,8 @@
## Credits
-Vilhelm K. Vardøy <vilhelmkv@gmail.com>
+ - Vilhelm K. Vardøy <vilhelmkv@gmail.com>
+ - Liam McLoughlin <hexxeh@hexxeh.net>
### Thanks to
View
58 album.c
@@ -27,6 +27,8 @@ OTHER DEALINGS IN THE SOFTWARE.
zend_class_entry *spotifyalbum_ce;
+PHP_METHOD(SpotifyAlbum, browse);
+
PHP_METHOD(SpotifyAlbum, __construct)
{
zval *object = getThis();
@@ -41,6 +43,7 @@ PHP_METHOD(SpotifyAlbum, __construct)
spotifyalbum_object *obj = (spotifyalbum_object*)zend_object_store_get_object(object TSRMLS_CC);
obj->session = p->session;
obj->album = album;
+ obj->albumbrowse = NULL;
zend_update_property(spotifyalbum_ce, getThis(), "spotify", strlen("spotify"), parent TSRMLS_CC);
@@ -50,6 +53,11 @@ PHP_METHOD(SpotifyAlbum, __construct)
PHP_METHOD(SpotifyAlbum, __destruct)
{
spotifyalbum_object *obj = (spotifyalbum_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (obj->albumbrowse != NULL) {
+ sp_albumbrowse_release(obj->albumbrowse);
+ }
+
sp_album_release(obj->album);
}
@@ -118,12 +126,60 @@ PHP_METHOD(SpotifyAlbum, getType)
RETURN_LONG(sp_album_type(p->album));
}
+PHP_METHOD(SpotifyAlbum, getCover)
+{
+ int timeout = 0;
+
+ spotifyalbum_object *p = (spotifyalbum_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ zval tempretval, *thisptr = getThis();
+ SPOTIFY_METHOD(SpotifyAlbum, browse, &tempretval, thisptr);
+
+ const byte* image_id = sp_album_cover(p->album);
+ sp_image *image = sp_image_create(p->session, image_id);
+
+ while(!sp_image_is_loaded(image))
+ {
+ sp_session_process_events(p->session, &timeout);
+ }
+
+ size_t size;
+ const byte* image_data = sp_image_data(image, &size);
+
+ RETURN_STRINGL(image_data, size, 1);
+
+ sp_image_release(image);
+}
+
PHP_METHOD(SpotifyAlbum, __toString)
{
spotifyalbum_object *p = (spotifyalbum_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
RETURN_STRING(sp_album_name(p->album), 1);
}
+static void albumbrowse_complete(sp_albumbrowse *result, void *userdata)
+{
+ spotifyalbum_object *p = (spotifyalbum_object*)userdata;
+ p->albumbrowse = result;
+}
+
+PHP_METHOD(SpotifyAlbum, browse)
+{
+ int timeout = 0;
+
+ spotifyalbum_object *p = (spotifyalbum_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (p->albumbrowse != NULL) {
+ RETURN_TRUE;
+ }
+
+ sp_albumbrowse *tmpbrowse = sp_albumbrowse_create(p->session, p->album, albumbrowse_complete, p);
+ while (!sp_albumbrowse_is_loaded(tmpbrowse)) {
+ sp_session_process_events(p->session, &timeout);
+ }
+
+ RETURN_TRUE;
+}
+
function_entry spotifyalbum_methods[] = {
PHP_ME(SpotifyAlbum, __construct, NULL, ZEND_ACC_PRIVATE|ZEND_ACC_CTOR)
PHP_ME(SpotifyAlbum, __destruct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_DTOR)
@@ -134,7 +190,9 @@ function_entry spotifyalbum_methods[] = {
PHP_ME(SpotifyAlbum, getNumTracks, NULL, ZEND_ACC_PUBLIC)
PHP_ME(SpotifyAlbum, getTracks, NULL, ZEND_ACC_PUBLIC)
PHP_ME(SpotifyAlbum, getType, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(SpotifyAlbum, getCover, NULL, ZEND_ACC_PUBLIC)
PHP_ME(SpotifyAlbum, __toString, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(SpotifyAlbum, browse, NULL, ZEND_ACC_PRIVATE)
{NULL, NULL, NULL}
};
View
@@ -50,7 +50,7 @@ PHP_METHOD(SpotifyAlbumIterator, __construct)
spotifyalbumiterator_object *obj = (spotifyalbumiterator_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
obj->session = p->session;
obj->artist = artistobj->artist;
- obj->artistbrowse = sp_artistbrowse_create(p->session, artistobj->artist, spotify_artistbrowse_complete, obj);
+ obj->artistbrowse = sp_artistbrowse_create(p->session, artistobj->artist, SP_ARTISTBROWSE_FULL, spotify_artistbrowse_complete, obj);
while (!sp_artistbrowse_is_loaded(obj->artistbrowse)) {
sp_session_process_events(p->session, &timeout);
View
@@ -27,6 +27,8 @@ OTHER DEALINGS IN THE SOFTWARE.
zend_class_entry *spotifyartist_ce;
+PHP_METHOD(SpotifyArtist, browse);
+
PHP_METHOD(SpotifyArtist, __construct)
{
zval *object = getThis();
@@ -41,6 +43,7 @@ PHP_METHOD(SpotifyArtist, __construct)
spotifyartist_object *obj = (spotifyartist_object*)zend_object_store_get_object(object TSRMLS_CC);
obj->session = p->session;
obj->artist = artist;
+ obj->artistbrowse = NULL;
zend_update_property(spotifyartist_ce, getThis(), "spotify", strlen("spotify"), parent TSRMLS_CC);
@@ -50,6 +53,11 @@ PHP_METHOD(SpotifyArtist, __construct)
PHP_METHOD(SpotifyArtist, __destruct)
{
spotifyartist_object *p = (spotifyartist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ if (p->artistbrowse != NULL) {
+ sp_artistbrowse_release(p->artistbrowse);
+ }
+
sp_artist_release(p->artist);
}
@@ -82,6 +90,81 @@ PHP_METHOD(SpotifyArtist, getAlbums)
SPOTIFY_METHOD1(SpotifyAlbumIterator, __construct, &tempretval, return_value, getThis());
}
+PHP_METHOD(SpotifyArtist, getPortrait)
+{
+ int timeout = 0;
+
+ zval *index, *object = getThis();
+ spotifyartist_object *p = (spotifyartist_object*)zend_object_store_get_object(object TSRMLS_CC);
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &index) == FAILURE) {
+ return;
+ }
+
+ zval tempretval, *thisptr = getThis();
+ SPOTIFY_METHOD(SpotifyArtist, browse, &tempretval, thisptr);
+
+ int numportraits = sp_artistbrowse_num_portraits(p->artistbrowse);
+
+ if(Z_LVAL_P(index) > numportraits)
+ {
+ RETURN_FALSE;
+ }
+
+ const byte* image_id = sp_artistbrowse_portrait(p->artistbrowse, Z_LVAL_P(index));
+ sp_image *image = sp_image_create(p->session, image_id);
+
+ while(!sp_image_is_loaded(image))
+ {
+ sp_session_process_events(p->session, &timeout);
+ }
+
+ size_t size;
+ const byte* image_data = sp_image_data(image, &size);
+
+ RETURN_STRINGL(image_data, size, 1);
+
+ sp_image_release(image);
+}
+
+PHP_METHOD(SpotifyArtist, getNumPortraits)
+{
+ int timeout = 0;
+
+ zval *object = getThis();
+ spotifyartist_object *p = (spotifyartist_object*)zend_object_store_get_object(object TSRMLS_CC);
+
+ zval tempretval, *thisptr = getThis();
+ SPOTIFY_METHOD(SpotifyArtist, browse, &tempretval, thisptr);
+
+ int numportraits = sp_artistbrowse_num_portraits(p->artistbrowse);
+
+ RETURN_LONG(numportraits);
+}
+
+static void artistbrowse_complete(sp_artistbrowse *result, void *userdata)
+{
+ spotifyartist_object *p = (spotifyartist_object*)userdata;
+ p->artistbrowse = result;
+}
+
+PHP_METHOD(SpotifyArtist, browse)
+{
+ int timeout = 0;
+
+ spotifyartist_object *p = (spotifyartist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+ if (p->artistbrowse != NULL) {
+ RETURN_TRUE;
+ }
+
+ sp_artistbrowse *tmpbrowse = sp_artistbrowse_create(p->session, p->artist, SP_ARTISTBROWSE_FULL, artistbrowse_complete, p);
+ while (!sp_artistbrowse_is_loaded(tmpbrowse)) {
+ sp_session_process_events(p->session, &timeout);
+ }
+
+ RETURN_TRUE;
+}
+
PHP_METHOD(SpotifyArtist, __toString)
{
spotifyartist_object *p = (spotifyartist_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
@@ -94,6 +177,9 @@ function_entry spotifyartist_methods[] = {
PHP_ME(SpotifyArtist, getName, NULL, ZEND_ACC_PUBLIC)
PHP_ME(SpotifyArtist, getURI, NULL, ZEND_ACC_PUBLIC)
PHP_ME(SpotifyArtist, getAlbums, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(SpotifyArtist, getPortrait, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(SpotifyArtist, getNumPortraits, NULL, ZEND_ACC_PUBLIC)
+ PHP_ME(SpotifyArtist, browse, NULL, ZEND_ACC_PRIVATE)
PHP_ME(SpotifyArtist, __toString, NULL, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
};
View
@@ -4,5 +4,5 @@ if test "$PHP_SPOTIFY" = "yes"; then
AC_DEFINE(HAVE_SPOTIFY, 1, [Whether you have Spotify])
LDFLAGS="$LDFLAGS -lspotify"
PHP_ADD_LIBRARY_WITH_PATH(spotify, "", SPOTIFY_SHARED_PATH)
- PHP_NEW_EXTENSION(spotify, spotify.c playlist.c track.c artist.c album.c user.c albumiterator.c trackiterator.c, $ext_shared)
+ PHP_NEW_EXTENSION(spotify, spotify.c playlist.c track.c artist.c album.c user.c toplist.c albumiterator.c trackiterator.c, $ext_shared)
fi
View
@@ -66,6 +66,7 @@ typedef struct {
zend_object std;
sp_session *session;
sp_artist *artist;
+ sp_artistbrowse *artistbrowse;
} spotifyartist_object;
typedef struct {
@@ -91,6 +92,12 @@ typedef struct {
} spotifyuser_object;
typedef struct {
+ zend_object std;
+ sp_session *session;
+ sp_toplistbrowse *toplistbrowse;
+} spotifytoplist_object;
+
+typedef struct {
zend_object std;
sp_session *session;
int type;
@@ -118,6 +125,7 @@ extern zend_class_entry *spotifytrack_ce;
extern zend_class_entry *spotifyartist_ce;
extern zend_class_entry *spotifyalbum_ce;
extern zend_class_entry *spotifyuser_ce;
+extern zend_class_entry *spotifytoplist_ce;
extern zend_class_entry *spotifyalbumiterator_ce;
extern zend_class_entry *spotifytrackiterator_ce;
Oops, something went wrong.

0 comments on commit 0318f07

Please sign in to comment.