Ejemplo n.º 1
0
bool SpotifySong::updateMetadata()
{
    if(sp_track_is_loaded(this->track))
    {
        this->duration = sp_track_duration(this->track);
        this->title = sp_track_name(this->track);
        if(this->artist == nullptr)
        {
            this->artist = sp_track_artist(this->track,0);
            sp_artist_add_ref(this->artist);
        }
        if(this->album == nullptr)
        {
            this->album = sp_track_album(this->track);
            sp_album_add_ref(this->album);
        }
    } else
        return false;

    if(this->artist != nullptr && sp_artist_is_loaded(this->artist))
        this->artistName = sp_artist_name(this->artist);
    else
        return false;

    if(this->album != nullptr && sp_album_is_loaded(this->album))
        this->albumName = sp_album_name(this->album);
    else
        return false;

    return true;
}
Ejemplo n.º 2
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);
}
	bool Artist::IsLoading()
	{
		return !sp_artist_is_loaded( m_pArtist );
	}
Ejemplo n.º 4
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;
}