예제 #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);
}
예제 #2
0
static PyObject *
ArtistBrowser_FromSpotify(sp_artistbrowse * browse)
{
    ArtistBrowser *b = (ArtistBrowser *)ArtistBrowserType.tp_alloc(&ArtistBrowserType, 0);

    b->_browser = browse;
    sp_artistbrowse_add_ref(browse);

    return b;
}
예제 #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;

}
예제 #4
0
SP_LIBEXPORT(sp_artistbrowse *) sp_artistbrowse_create(sp_session *session, sp_artist *artist, artistbrowse_complete_cb *callback, void *userdata) {
	sp_artistbrowse *arb;
	void **container;
	struct browse_callback_ctx *brctx;


	arb = malloc(sizeof(sp_artistbrowse));
	DSFYDEBUG("Allocated artistbrowse at %p\n", arb);
	if(arb == NULL)
		return NULL;


	arb->artist = artist;
	sp_artist_add_ref(artist);
	DSFYDEBUG("Referenced artist at %p\n", arb->artist);

	arb->num_tracks = 0;
	arb->tracks = NULL;

	arb->num_portraits = 0;
	arb->portraits = 0;

	arb->num_similar_artists = 0;
	arb->similar_artists = NULL;

	arb->num_albums = 0;
	arb->albums = NULL;

	arb->biography = NULL;

	arb->callback = callback;
	arb->userdata = userdata;

	arb->error = SP_ERROR_IS_LOADING;

	arb->is_loaded = 0;
	arb->ref_count = 1;

	/*
	 * Temporarily increase ref count for the albumbrowse so it's not free'd
	 * accidentily. It will be decreaed by the chanel callback.
	 *
	 */
	sp_artistbrowse_add_ref(arb);


	/* The album callback context */
	brctx = (struct browse_callback_ctx *)malloc(sizeof(struct browse_callback_ctx));


	brctx->session = session;
	brctx->req = NULL; /* Filled in by the request processor */
	brctx->buf = NULL; /* Filled in by the request processor */

	brctx->type = REQ_TYPE_ARTISTBROWSE;
	brctx->data.artistbrowses = (sp_artistbrowse **)malloc(sizeof(sp_artistbrowse *));
	brctx->data.artistbrowses[0] = arb;
	brctx->num_total = 1;
	brctx->num_browsed = 0;
	brctx->num_in_request = 0;

	/* Our gzip'd XML parser */
	brctx->browse_parser = osfy_artistbrowse_browse_callback;

	/* Request input container. Will be free'd when the request is finished. */
	container = (void **)malloc(sizeof(void *));
	*container = brctx;


	request_post(session, REQ_TYPE_ARTISTBROWSE, container);	

	return arb;
}