Exemplo n.º 1
0
PHP_METHOD(SpotifyAlbumIterator, __construct)
{
	zval *thisptr = getThis(), *parent;
	spotifyartist_object *artistobj;
	int timeout = 0;
	
	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &parent, spotifyartist_ce) == FAILURE) {
		return;
	}

	zval *spotifyobject = GET_PROPERTY(spotifyartist_ce, parent, "spotify");
	spotify_object *p = (spotify_object*)zend_object_store_get_object(spotifyobject TSRMLS_CC);

	artistobj = (spotifyartist_object*)zend_object_store_get_object(parent TSRMLS_CC);

	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, SP_ARTISTBROWSE_FULL, spotify_artistbrowse_complete, obj);

	while (!sp_artistbrowse_is_loaded(obj->artistbrowse)) {
		sp_session_process_events(p->session, &timeout);
	}

	obj->position = 0;
	obj->length = sp_artistbrowse_num_albums(obj->artistbrowse);

	zend_update_property(spotifyalbumiterator_ce, getThis(), "spotify", strlen("spotify"), spotifyobject TSRMLS_CC);

	sp_artistbrowse_add_ref(obj->artistbrowse);
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
jobject createJArtistInstance(JNIEnv *env, sp_artist *artist)
{
    jclass jClass;
    jobject artistInstance = createInstance(env,"jahspotify/media/Artist");
    sp_link *artistLink = sp_link_create_from_artist(artist);

    jClass = (*env)->FindClass(env, "jahspotify/media/Artist");
    if (jClass == NULL)
    {
        fprintf(stderr,"jahspotify::createJArtistInstance: could not load jahnotify.media.Artist\n");
        return NULL;
    }

    if (artistLink)
    {
        sp_link_add_ref(artistLink);

        jobject artistJLink = createJLinkInstance(env, artistLink);

        setObjectObjectField(env,artistInstance,"id","Ljahspotify/media/Link;",artistJLink);

        sp_link_release(artistLink);

        setObjectStringField(env,artistInstance,"name",sp_artist_name(artist));
	
        sp_artistbrowse *artistBrowse = sp_artistbrowse_create(g_sess,artist,artistBrowseCompleteCallback,NULL);

        if (artistBrowse)
        {
            sp_artistbrowse_add_ref(artistBrowse);

            while (!sp_artistbrowse_is_loaded(artistBrowse))
            {
                usleep(100);
            }

            int numSimilarArtists = sp_artistbrowse_num_similar_artists(artistBrowse);

            if (numSimilarArtists > 0)
            {
                jmethodID jMethod = (*env)->GetMethodID(env,jClass,"addSimilarArtist","(Ljahspotify/media/Link;)V");

                if (jMethod == NULL)
                {
                    fprintf(stderr,"jahspotify::createJTrackInstance: could not load method setAlbum(link) on class Track\n");
                    return NULL;
                }

                // Load the artist links
                int count = 0;
                for (count = 0; count < numSimilarArtists; count++)
                {
                    sp_artist *similarArtist = sp_artistbrowse_similar_artist(artistBrowse,0);
                    if (similarArtist)
                    {
                        sp_artist_add_ref(similarArtist);

                        sp_link *similarArtistLink = sp_link_create_from_artist(similarArtist);

                        if (similarArtistLink)
                        {
                            sp_link_add_ref(similarArtistLink);

                            jobject similarArtistJLink = createJLinkInstance(env,similarArtistLink);

                            // set it on the track
                            (*env)->CallVoidMethod(env,artistInstance,jMethod,similarArtistJLink);

                            sp_link_release(similarArtistLink);
                        }

                        sp_artist_release(similarArtist);
                    }
                }
            }

            int numPortraits = sp_artistbrowse_num_portraits(artistBrowse);

            if (numPortraits > 0)
            {
                // Load portrait url
                const byte *portraitURI = sp_artistbrowse_portrait(artistBrowse,0);

                if (portraitURI)
                {
                    char *portraitURIStr = toHexString((byte*)portraitURI);
                    const char spotifyURI[] = "spotify:image:";
                    int len = strlen(spotifyURI) + strlen(portraitURIStr);
                    char *dest = malloc(len+1);
                    dest[0] = 0;
                    strcat(dest,spotifyURI);
                    strcat(dest,portraitURIStr);

                    sp_link *portraitLink = sp_link_create_from_string(dest);

		    sp_image *portrait = sp_image_create_from_link(g_sess,portraitLink);
		    if (portrait)
		    {
		      sp_image_add_ref(portrait);
		      sp_image_add_load_callback(portrait,imageLoadedCallback,NULL);
		    }
		    
                    free(dest);
                    free(portraitURIStr);

                    if (portraitLink)
                    {
                        sp_link_add_ref(portraitLink);

                        jobject portraitJLlink = createJLinkInstance(env,portraitLink);
                        setObjectObjectField(env,artistInstance,"portrait","Ljahspotify/media/Link;",portraitJLlink);

                        sp_link_release(portraitLink);
                    }
                }
            }

            // sp_artistbrowse_num_albums()
            // sp_artistbrowse_album()

            const char *bios = sp_artistbrowse_biography(artistBrowse);
	    if (bios)
	    {
	      setObjectStringField(env,artistInstance,"bios",bios);
	    }

            // sp_artistbrowse_num_tracks()
            // sp_artistbrowse_track()

            sp_artistbrowse_release(artistBrowse);
        }
    }
    return artistInstance;

}
Exemplo n.º 4
0
static PyObject *
ArtistBrowser_is_loaded(ArtistBrowser * self)
{
    return Py_BuildValue("i", sp_artistbrowse_is_loaded(self->_browser));
}