Esempio n. 1
0
sp_image* track_get_image(sp_track* track) {
    sp_album* alb = NULL;
    sp_image* img = NULL;
    const void* img_id = NULL;

    /* Get album */
    alb = sp_track_album(track);
    if (!alb)
        g_error("Can't get track album.");
    sp_album_add_ref(alb);

    if (!sp_album_is_loaded(alb))
        g_error("Album not loaded.");

    /* Get image */
    img_id = sp_album_cover(alb, SP_IMAGE_SIZE_NORMAL);
    if (!img_id) {
        /* Since the album is loaded, a NULL here indicates that there is no
           cover for this album. */
        sp_album_release(alb);
        return NULL;
    }

    img = sp_image_create(g_session, img_id);
    sp_album_release(alb);

    if (!img)
        g_error("Can't create image.");
    return img;
}
Esempio n. 2
0
static void
Album_dealloc(Album * self)
{
    if (self->_album)
        sp_album_release(self->_album);
    self->ob_type->tp_free(self);
}
Esempio n. 3
0
JNIEXPORT jobject JNICALL Java_jahspotify_impl_JahSpotifyImpl_retrieveAlbum ( JNIEnv *env, jobject obj, jstring uri)
{
    jobject albumInstance;
    uint8_t *nativeUri = NULL;

    nativeUri = ( uint8_t * ) ( *env )->GetStringUTFChars ( env, uri, NULL );

    sp_link *link = sp_link_create_from_string(nativeUri);
    if (link)
    {
        sp_album *album= sp_link_as_album(link);

        if (album)
        {
            sp_album_add_ref(album);
            
            albumInstance = createJAlbumInstance(env, album);
	    
            sp_album_release(album);
        }
        sp_link_release(link);
    }

    if (nativeUri)
        (*env)->ReleaseStringUTFChars(env, uri,nativeUri);

    return albumInstance;
}
Esempio n. 4
0
SpotifySong::~SpotifySong()
{
    boost::lock_guard<boost::mutex> lock(this->spotify->spotifyApiMutex);
    sp_track_release(this->track);
    if(this->artist != nullptr)
        sp_artist_release(this->artist);
    if(this->album != nullptr)
        sp_album_release(this->album);
}
Esempio n. 5
0
SP_LIBEXPORT(void) sp_artistbrowse_release(sp_artistbrowse *arb) {
	int i;

	assert(arb->ref_count > 0);
	arb->ref_count--;

	if(arb->ref_count)
		return;


	if(arb->artist) {
		DSFYDEBUG("Unreferencing artist at %p\n", arb->artist);
		sp_artist_release(arb->artist);
	}


	for(i = 0; i < arb->num_tracks; i++)
		sp_track_release(arb->tracks[i]);

	if(arb->num_tracks)
		free(arb->tracks);


	for(i = 0; i < arb->num_portraits; i++)
		free(arb->portraits[i]);

	if(arb->num_portraits)
		free(arb->portraits);


	for(i = 0; i < arb->num_similar_artists; i++)
		sp_artist_release(arb->similar_artists[i]);

	if(arb->num_similar_artists)
		free(arb->similar_artists);


	for(i = 0; i < arb->num_albums; i++)
		sp_album_release(arb->albums[i]);

	if(arb->num_albums)
		free(arb->albums);


	DSFYDEBUG("Deallocating artistbrowse at %p\n", arb);
	free(arb);
}
Esempio n. 6
0
SP_LIBEXPORT(void) sp_search_release(sp_search *search) {
	int i;

	assert(search->ref_count > 0);
	search->ref_count--;

	if(search->ref_count)
		return;


	free(search->query);


	for(i = 0; i < search->num_albums; i++)
		sp_album_release(search->albums[i]);

	if(search->num_albums)
		free(search->albums);


	for(i = 0; i < search->num_artists; i++)
		sp_artist_release(search->artists[i]);

	if(search->num_artists)
		free(search->artists);


	for(i = 0; i < search->num_tracks; i++)
		sp_track_release(search->tracks[i]);

	if(search->num_tracks)
		free(search->tracks);


	if(search->did_you_mean)
		free(search->did_you_mean);


	free(search);
}
Esempio n. 7
0
void track_get_data(sp_track* track, gchar** name, gchar** artist, gchar** album, gchar** link,
                    guint* duration, int* popularity) {
    sp_artist** art = NULL;
    sp_album* alb = NULL;
    sp_link* lnk;
    int i;
    int nb_art = 0;
    const char* s;

    sp_track_add_ref(track);
    if (!sp_track_is_loaded(track)) {
        sp_track_release(track);
       return;
    }

    /* Begin loading everything */
    if (name) {
        *name = g_strdup(sp_track_name(track));
    }
    if (artist) {
        nb_art = sp_track_num_artists(track);
        art = (sp_artist**) malloc(nb_art * sizeof(sp_artist*));
        if (!art)
            g_error("Can't allocate memory.");

        for (i=0; i < nb_art; i++) {
            art[i] = sp_track_artist(track, i);
            sp_artist_add_ref(art[i]);
        }
    }
    if (album) {
        alb = sp_track_album(track);
        sp_album_add_ref(alb);
    }
    if (link) {
        GString* tmp;
        lnk = sp_link_create_from_track(track, 0);
        if (!lnk)
            g_error("Can't get URI from track.");

        tmp = g_string_sized_new(1024);
        if (sp_link_as_string(lnk, tmp->str, 1024) < 0)
            g_error("Can't render URI from link.");
        *link = tmp->str;
        g_string_free(tmp, FALSE);

        sp_link_release(lnk);
    }
    if (duration) {
        *duration = sp_track_duration(track);
    }
    if (popularity) {
        *popularity = sp_track_popularity(track);
    }

    /* Now create destination strings */
    if (artist) {
        GString* tmp = g_string_new("");
        for (i=0; i < nb_art; i++) {
            if (sp_artist_is_loaded(art[i]))
                s = sp_artist_name(art[i]);
            else
                s = "[artist not loaded]";

            if (i != 0)
                g_string_append(tmp, ", ");
            g_string_append(tmp, s);
            sp_artist_release(art[i]);
        }
        *artist = tmp->str;
        g_string_free(tmp, FALSE);
    }
    if (album) {
        if (sp_album_is_loaded(alb))
            *album = g_strdup(sp_album_name(alb));
        else
            *album = g_strdup("[album not loaded]");
        sp_album_release(alb);
    }

    sp_track_release(track);
}
Esempio n. 8
0
QSpotifyAlbum::~QSpotifyAlbum()
{
    sp_album_release(m_sp_album);
}
Esempio n. 9
0
jobject createJTrackInstance(JNIEnv *env, sp_track *track)
{
    jclass jClass;
    jobject trackInstance;

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

    trackInstance = (*env)->AllocObject(env,jClass);
    if (!trackInstance)
    {
        fprintf(stderr,"jahspotify::createJTrackInstance: could not create instance of jahspotify.media.Track\n");
        return NULL;
    }

    sp_link *trackLink = sp_link_create_from_track(track,0);

    if (trackLink)
    {
        sp_link_add_ref(trackLink);
        jobject trackJLink = createJLinkInstance(env,trackLink);
        setObjectObjectField(env,trackInstance,"id","Ljahspotify/media/Link;",trackJLink);

        setObjectStringField(env,trackInstance,"title",sp_track_name(track));
        setObjectIntField(env,trackInstance,"length",sp_track_duration(track));
        setObjectIntField(env,trackInstance,"popularity",sp_track_popularity(track));
        setObjectIntField(env,trackInstance,"trackNumber",sp_track_index(track));

        sp_album *album = sp_track_album(track);
        if (album)
        {
            sp_album_add_ref(album);
            sp_link *albumLink = sp_link_create_from_album(album);
            if (albumLink)
            {
                sp_link_add_ref(albumLink);

                jobject albumJLink = createJLinkInstance(env,albumLink);

                jmethodID jMethod = (*env)->GetMethodID(env,jClass,"setAlbum","(Ljahspotify/media/Link;)V");

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

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

                sp_link_release(albumLink);

            }

            int numArtists = sp_track_num_artists(track);
            if (numArtists > 0)
            {
                jmethodID jMethod = (*env)->GetMethodID(env,jClass,"addArtist","(Ljahspotify/media/Link;)V");

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

                int i = 0;
                for (i = 0; i < numArtists; i++)
                {
                    sp_artist *artist = sp_track_artist(track,i);
                    if (artist)
                    {
                        sp_artist_add_ref(artist);

                        sp_link *artistLink = sp_link_create_from_artist(artist);
                        if (artistLink)
                        {
                            sp_link_add_ref(artistLink);

                            jobject artistJLink = createJLinkInstance(env,artistLink);

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

                            sp_link_release(artistLink);

                        }
                        sp_artist_release(artist);
                    }
                }
            }

            sp_album_release(album);
        }
        sp_link_release(trackLink);
    }
    return trackInstance;
}
Esempio n. 10
0
static int osfy_artistbrowse_load_from_xml(sp_session *session, sp_artistbrowse *arb, ezxml_t root) {
	unsigned char id[20];
	int disc_number, i;
	sp_track *track;
	sp_album *album;
	ezxml_t node, album_node, loop_node, track_node;


	/* Load artist from XML if not yet loaded */
	if(sp_artist_is_loaded(arb->artist) == 0)
		osfy_artist_load_artist_from_xml(session, arb->artist, root);

	assert(sp_artist_is_loaded(arb->artist));


	/* Load portraits */
	for(loop_node = ezxml_get(root, "bios", 0, "bio", 0, "portraits", 0, "portrait", -1);
	    loop_node;
	    loop_node = loop_node->next) {

		if((node = ezxml_get(loop_node, "id", -1)) == NULL)
			continue;

		arb->portraits = realloc(arb->portraits, sizeof(unsigned char *) * (1 + arb->num_portraits));
		arb->portraits[arb->num_portraits] = malloc(20);

		hex_ascii_to_bytes(node->txt, arb->portraits[arb->num_portraits], 20);

		arb->num_portraits++;
	}		


	/* Load biography */
	if((node = ezxml_get(root, "bios", 0, "bio", 0, "text", -1)) != NULL)
		arb->biography = strdup(node->txt);
	else
		arb->biography = strdup("");


	/* Load similar artists */
	for(loop_node = ezxml_get(root, "similar-artists", 0, "artist", -1);
	    loop_node;
	    loop_node = loop_node->next) {

		if((node = ezxml_get(loop_node, "id", -1)) == NULL)
			continue;

		arb->similar_artists = realloc(arb->similar_artists, sizeof(sp_artist *) * (1 + arb->num_similar_artists));
		hex_ascii_to_bytes(node->txt, id, 16);

		arb->similar_artists[arb->num_similar_artists]
					= osfy_artist_add(session, id);
		sp_artist_add_ref(arb->similar_artists[arb->num_similar_artists]);

		if(sp_artist_is_loaded(arb->similar_artists[arb->num_similar_artists]) == 0) {
			DSFYDEBUG("Loading similar artist from artistbrowse XML\n");
			osfy_artist_load_artist_from_xml(session, 
						arb->similar_artists[arb->num_similar_artists],
							       loop_node);
		}
		assert(sp_artist_is_loaded(arb->similar_artists[arb->num_similar_artists]));

		arb->num_similar_artists++;
	}


	/* Loop over each album listed */
	for(album_node = ezxml_get(root, "albums", 0, "album", -1);
	    album_node;
	    album_node = album_node->next) {

		/* Extract album ID and add it */
		if((node = ezxml_get(album_node, "id", -1)) == NULL)
			continue;

		hex_ascii_to_bytes(node->txt, id, 16);
		album = sp_album_add(session, id);


		/* Load album if necessary */
		if(sp_album_is_loaded(album) == 0)
		   osfy_album_load_from_album_xml(session, album, album_node);

		assert(sp_album_is_loaded(album));


		/* Add album to artistbrowse's list of albums */
		arb->albums = realloc(arb->albums, sizeof(sp_album *) * (1 + arb->num_albums));
		arb->albums[arb->num_albums] = album;
		sp_album_add_ref(arb->albums[arb->num_albums]);
		arb->num_albums++;


		/* Loop over each disc in the album and add tracks */
		for(loop_node = ezxml_get(album_node, "discs", 0, "disc", -1);
		    loop_node;
		    loop_node = loop_node->next) {

			/* Cache disc number */
			if((node = ezxml_get(loop_node, "disc-number", -1)) == NULL) {
				DSFYDEBUG("BUG: Found no 'disc-numner' under discs -> disc\n");
				continue;
			}

			disc_number = atoi(node->txt);


			/* Loop over each track and add it to the artistbrowse tracks list */
			for(track_node = ezxml_get(loop_node, "track", -1), i = 1;
			    track_node;
			    track_node = track_node->next, i++) {

				/* Extract track ID and add it */
				if((node = ezxml_get(track_node, "id", -1)) == NULL)
					continue;

				hex_ascii_to_bytes(node->txt, id, 16);
				track = osfy_track_add(session, id);


				/* Add album to track */
				if(track->album)
					sp_album_release(track->album);

				track->album = album;
				sp_album_add_ref(track->album);


				/* Set disc number */
				track->disc = disc_number;


				/* Set track index on disc */
				if(track->index == 0)
					track->index = i;


				/* Load track details from XML if not already loaded */
				if(sp_track_is_loaded(track) == 0)
					osfy_track_load_from_xml(session, track, track_node);

				assert(sp_track_is_loaded(track));


				/* Mark track as available if the album is available and the album has a non-zero duration (i.e, associated files) */
				if(!track->is_available && track->duration) {
					DSFYDEBUG("Track '%s' marked as not available but has files, force-marking track as %savailable\n",
							node->txt, !album->is_available? "not ": "");
					track->is_available = album->is_available;
				}

				/* Add track to artistbrowse and increase the track's ref count */
				arb->tracks = realloc(arb->tracks, sizeof(sp_track *) * (1 + arb->num_tracks));
				arb->tracks[arb->num_tracks] = track;
				sp_track_add_ref(arb->tracks[arb->num_tracks]);

				arb->num_tracks++;
			}

		} /* for each disc in album */


	} /* for each album */


	return 0;
}
	Album::~Album()
	{
		sp_album_release( m_pAlbum );
	}