PHP_METHOD(Spotify, getAlbumByURI) { zval *uri, temp, *object = getThis(); int timeout = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &uri) == FAILURE) { return; } spotify_object *p = (spotify_object*)zend_object_store_get_object(object TSRMLS_CC); sp_link *link = sp_link_create_from_string(Z_STRVAL_P(uri)); if (NULL == link) { RETURN_FALSE; } if (SP_LINKTYPE_ALBUM != sp_link_type(link)) { RETURN_FALSE; } sp_album *album = sp_link_as_album(link); while (!sp_album_is_loaded(album)) { sp_session_process_events(p->session, &timeout); } object_init_ex(return_value, spotifyalbum_ce); SPOTIFY_METHOD2(SpotifyAlbum, __construct, &temp, return_value, object, album); sp_link_release(link); }
PHP_METHOD(Spotify, getArtistByURI) { zval *uri, temp, *object = getThis(); int timeout = 0; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &uri) == FAILURE) { return; } spotify_object *p = (spotify_object*)zend_object_store_get_object(object TSRMLS_CC); sp_link *link = sp_link_create_from_string(Z_STRVAL_P(uri)); if (NULL == link) { RETURN_FALSE; } if (SP_LINKTYPE_ARTIST != sp_link_type(link)) { RETURN_FALSE; } sp_artist *artist = sp_link_as_artist(link); object_init_ex(return_value, spotifyartist_ce); SPOTIFY_METHOD2(SpotifyArtist, __construct, &temp, return_value, object, artist); sp_link_release(link); }
PHP_METHOD(Spotify, getUser) { sp_user *user; zval temp; spotifyplaylist_object *p = (spotifyplaylist_object*)zend_object_store_get_object(getThis() TSRMLS_CC); user = sp_session_user(p->session); object_init_ex(return_value, spotifyuser_ce); SPOTIFY_METHOD2(SpotifyUser, __construct, &temp, return_value, getThis(), user); }
PHP_METHOD(SpotifyPlaylist, getOwner) { sp_user *user; zval temp, *spotifyobject; spotifyplaylist_object *p = (spotifyplaylist_object*)zend_object_store_get_object(getThis() TSRMLS_CC); spotifyobject = zend_read_property(spotifyplaylist_ce, getThis(), "spotify", strlen("spotify"), NOISY TSRMLS_CC); user = sp_playlist_owner(p->playlist); object_init_ex(return_value, spotifyuser_ce); SPOTIFY_METHOD2(SpotifyUser, __construct, &temp, return_value, spotifyobject, user); }
PHP_METHOD(Spotify, getStarredPlaylist) { zval *object = getThis(); zval temp; spotify_object *obj = (spotify_object*)zend_object_store_get_object(object TSRMLS_CC); do { sp_session_process_events(obj->session, &obj->timeout); } while (obj->timeout == 0); sp_playlist *playlist = sp_session_starred_create(obj->session); object_init_ex(return_value, spotifyplaylist_ce); SPOTIFY_METHOD2(SpotifyPlaylist, __construct, &temp, return_value, object, playlist); }
PHP_METHOD(SpotifyAlbumIterator, offsetGet) { zval *index, temp, *spotifyobject; sp_album *album; spotifyalbumiterator_object *p; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &index) == FAILURE) { return; } p = (spotifyalbumiterator_object*)zend_object_store_get_object(getThis() TSRMLS_CC); album = sp_artistbrowse_album(p->artistbrowse, Z_LVAL_P(index)); spotifyobject = GET_THIS_PROPERTY(spotifyalbumiterator_ce, "spotify"); object_init_ex(return_value, spotifyalbum_ce); SPOTIFY_METHOD2(SpotifyAlbum, __construct, &temp, return_value, spotifyobject, album); }
PHP_METHOD(SpotifyAlbumIterator, current) { spotifyalbumiterator_object *p; sp_album *album; zval temp, *spotifyobject; int timeout; p = (spotifyalbumiterator_object*)zend_object_store_get_object(getThis() TSRMLS_CC); album = sp_artistbrowse_album(p->artistbrowse, p->position); while (!sp_album_is_loaded(album)) { sp_session_process_events(p->session, &timeout); } spotifyobject = GET_THIS_PROPERTY(spotifyalbumiterator_ce, "spotify"); object_init_ex(return_value, spotifyalbum_ce); SPOTIFY_METHOD2(SpotifyAlbum, __construct, &temp, return_value, spotifyobject, album); }
PHP_METHOD(SpotifyPlaylist, getTrackCreator) { int index; zval *thisptr = getThis(), tempretval, *spotifyobject; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &index) == FAILURE) { return; } spotifyobject = zend_read_property(spotifyplaylist_ce, thisptr, "spotify", strlen("spotify"), NOISY TSRMLS_CC); spotifyplaylist_object *p = (spotifyplaylist_object*)zend_object_store_get_object(thisptr TSRMLS_CC); sp_user *user = sp_playlist_track_creator(p->playlist, index); if (!user) { RETURN_FALSE; } object_init_ex(return_value, spotifyuser_ce); SPOTIFY_METHOD2(SpotifyUser, __construct, &tempretval, return_value, spotifyobject, user); }
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); } }