0

Not sure the proper handling of searching playlists, have no problem with artists, tracks , albums. The developer resources seem to not include this and of course that's the part I seem to be struggling with.

https://developer.spotify.com/technologies/libspotify/docs/12.1.45/search_8c-example.html Does search but doesn't process playlists results.

spshell in search.c has this reference, but the name alone isn't going to help, I see sp_search_playlist commented out, but it's undocumented. I assumed it would returned something I can pass to sp_playlist_num_tracks, sp_playlist_name etc.. but that doesn't seem to work.

for (i = 0; i < sp_search_num_playlists(search); ++i) {
    // print some readily available metadata, the rest will
    // be available from the sp_playlist object loaded through
    // sp_search_playlist().
    printf("  Playlist \"%s\"\n", sp_search_playlist_name(search, i));
}

So how does one properly turn a search for playlists into some metadata and tracks ?

Any help or advice would be awesome !!

Evan
  • 157
  • 11

2 Answers2

0

I'm not sure why it's not in the online docs, but sp_search_playlist is documented in api.h:

/**
 * Load the playlist at the given index in the given search object
 *
 * @param[in]  search     Search object
 * @param[in]  index      Index of the wanted playlist. Should be in the interval [0, sp_search_num_playlists() - 1]
 *
 * @return                A playlist object. This reference is owned by the caller and should be released with sp_playlist_release()
 */
SP_LIBEXPORT(sp_playlist *) sp_search_playlist(sp_search *search, int index);

Note that unlike many similar parts of the API it says that the caller owns the reference.

Alternatively, if you're uncomfortable using this because it's poorly documented, you could instead get the playlist URI from the search, create a link from it then create a playlist from the link.

Weeble
  • 17,058
  • 3
  • 60
  • 75
  • I've tried both methods and I can get the playlist name via sp_search_playlist_name, the playlist link via sp_search_playlist_uri. Using sp_link_create_from_string with the result I assume should allow me to call sp_playlist_create. From there api calls like sp_playlist_num_tracks return 0, sp_playlist_get_description return nothing. Using sp_search_playlist and then directly calling sp_playlist_num_tracks and sp_playlist_get_description still don't return meaningful results. Seems like I'm missing something here. – Evan Feb 27 '13 at 15:13
  • If you modify search.c in spshell to add sp_search_playlist as follows... for (i = 0; i < sp_search_num_playlists(search); ++i) { sp_playlist * pl = sp_search_playlist(search, i); int count = sp_playlist_num_tracks(pl); const char *desc = sp_playlist_get_description(pl); printf(" Playlist \"%s\" Count(%d) Dsc(%s) \n", sp_search_playlist_name(search, i), count, desc); sp_playlist_release(pl); } and execute a search reggae many lists come up , all count 0 and no description. – Evan Feb 27 '13 at 15:32
  • The same happens if I add this to the loop, const char *uri = sp_search_playlist_uri(search, i); sp_link *link =sp_link_create_from_string(uri ); sp_playlist * list = sp_playlist_create(g_session, link); int count = sp_playlist_num_tracks(list); const char *desc = sp_playlist_get_description(list); – Evan Feb 27 '13 at 15:43
  • Did you wait for the playlist to load? Do you have an event loop that calls sp_session_process_events when necessary? – Weeble Feb 27 '13 at 15:53
0

OK I seemed to have solved the issue. I need to wait until playlist_update_in_progress and the done flag is true before I can get the data. Hope this helps someone else out there.

Evan
  • 157
  • 11