static void User_dealloc(User * self) { if (self->_user) sp_user_release(self->_user); self->ob_type->tp_free(self); }
QSpotifyUser::~QSpotifyUser() { if (m_playlistContainer) { // This is deleted directly as we have to make sure that its // gone as soon as this destructor is done. delete m_playlistContainer; } if (m_starredList) m_starredList->deleteLater(); if (m_inbox) m_inbox->deleteLater(); if (m_sp_user) sp_user_release(m_sp_user); }
json_t *playlist_to_json(sp_playlist *playlist, json_t *object) { assert(sp_playlist_is_loaded(playlist)); // Owner sp_user *owner = sp_playlist_owner(playlist); const char *username = sp_user_display_name(owner); sp_user_release(owner); json_object_set_new_nocheck(object, "creator", json_string_nocheck(username)); // URI size_t playlist_uri_len = strlen("spotify:user:"******":playlist:") + strlen("284on3DVWeAxWkgVuzZKGt"); char *playlist_uri = malloc(playlist_uri_len); if (playlist_uri == NULL) { return NULL; } sp_link *playlist_link = sp_link_create_from_playlist(playlist); sp_link_as_string(playlist_link, playlist_uri, playlist_uri_len); sp_link_release(playlist_link); json_object_set_new(object, "uri", json_string_nocheck(playlist_uri)); free(playlist_uri); // Title const char *title = sp_playlist_name(playlist); json_object_set_new(object, "title", json_string_nocheck(title)); // Collaborative playlist_to_json_set_collaborative(playlist, object); // Description const char *description = sp_playlist_get_description(playlist); if (description != NULL) { json_object_set_new(object, "description", json_string_nocheck(description)); } // Number of subscribers int num_subscribers = sp_playlist_num_subscribers(playlist); json_object_set_new(object, "subscriberCount", json_integer(num_subscribers)); // Tracks json_t *tracks = json_array(); json_object_set_new(object, "tracks", tracks); char track_uri[kTrackLinkLength]; for (int i = 0; i < sp_playlist_num_tracks(playlist); i++) { sp_track *track = sp_playlist_track(playlist, i); sp_link *track_link = sp_link_create_from_track(track, 0); sp_link_as_string(track_link, track_uri, kTrackLinkLength); json_array_append(tracks, json_string_nocheck(track_uri)); sp_link_release(track_link); } return object; }
SpotifyUser::~SpotifyUser() { sp_user_release(m_spUser); }
jobject createJPlaylist(JNIEnv *env, sp_playlist *playlist) { jclass jClass; jobject playlistInstance; jmethodID jMethod; jClass = (*env)->FindClass(env, "jahspotify/media/Playlist"); if (jClass == NULL) { fprintf(stderr,"jahspotify::createJPlaylist: could not load jahnotify.media.Playlist\n"); return NULL; } playlistInstance = (*env)->AllocObject(env,jClass); if (!playlistInstance) { fprintf(stderr,"jahspotify::createJPlaylist: could not create instance of jahspotify.media.Playlistt\n"); return NULL; } sp_link *playlistLink = sp_link_create_from_playlist(playlist); if (playlistLink) { jobject playlistJLink = createJLinkInstance(env,playlistLink); setObjectObjectField(env,playlistInstance,"id","Ljahspotify/media/Link;",playlistJLink); sp_link_release(playlistLink); } setObjectStringField(env,playlistInstance,"name",sp_playlist_name(playlist)); sp_user *owner = sp_playlist_owner(playlist); if (owner) { setObjectStringField(env,playlistInstance,"author",sp_user_display_name(owner)); sp_user_release(owner); } // Lookup the method now - saves us looking it up for each iteration of the loop jMethod = (*env)->GetMethodID(env,jClass,"addTrack","(Ljahspotify/media/Link;)V"); if (jMethod == NULL) { fprintf(stderr,"jahspotify::createJPlaylist: could not load method addTrack(track) on class Playlist\n"); return NULL; } int numTracks = sp_playlist_num_tracks(playlist); int trackCounter = 0; for (trackCounter = 0 ; trackCounter < numTracks; trackCounter++) { sp_track *track = sp_playlist_track(playlist,trackCounter); if (track) { sp_track_add_ref(track); sp_link *trackLink = sp_link_create_from_track(track, 0); if (trackLink) { sp_link_add_ref(trackLink); jobject trackJLink = createJLinkInstance(env,trackLink); // Add it to the playlist (*env)->CallVoidMethod(env,playlistInstance,jMethod,trackJLink); sp_link_release(trackLink); } sp_track_release(track); } } return playlistInstance; }