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); }
PHP_METHOD(Spotify, getPlaylists) { zval *thisptr = getThis(), tempretval; int i, timeout = 0, num_playlists; spotify_object *p = (spotify_object*)zend_object_store_get_object(thisptr TSRMLS_CC); SPOTIFY_METHOD(Spotify, initPlaylistContainer, &tempretval, thisptr); array_init(return_value); num_playlists = sp_playlistcontainer_num_playlists(p->playlistcontainer); for (i=0; i<num_playlists; i++) { sp_playlist *playlist = sp_playlistcontainer_playlist(p->playlistcontainer, i); zval *z_playlist; ALLOC_INIT_ZVAL(z_playlist); object_init_ex(z_playlist, spotifyplaylist_ce); SPOTIFY_METHOD2(SpotifyPlaylist, __construct, &tempretval, z_playlist, thisptr, playlist); add_next_index_zval(return_value, z_playlist); } }
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); }