/** * Callback for libspotify * * @param result The toplist result object that is now done * @param userdata The opaque pointer given to sp_toplistbrowse_create() */ static void got_toplist(sp_toplistbrowse *result, void *userdata) { int i; // We print from all types. Only one of the loops will acually yield anything. for(i = 0; i < sp_toplistbrowse_num_artists(result); i++) print_artist(i + 1, sp_toplistbrowse_artist(result, i)); for(i = 0; i < sp_toplistbrowse_num_albums(result); i++) print_album(i + 1, sp_toplistbrowse_album(result, i)); for(i = 0; i < sp_toplistbrowse_num_tracks(result); i++) { printf("%3d: ", i + 1); print_track(sp_toplistbrowse_track(result, i)); } sp_toplistbrowse_release(result); cmd_done(); }
/** * Callback for libspotify * * @param result The toplist result object that is now done * @param userdata The opaque pointer given to sp_toplistbrowse_create() */ static void got_toplist(sp_toplistbrowse *result, void *userdata) { int i; json_t *json = json_object(); json_t *toplist = json_object(); json_object_set_new(json, "toplist", toplist); json_t *results = json_array(); json_object_set_new(toplist, "result", results); // We print from all types. Only one of the loops will acually yield anything. for(i = 0; i < sp_toplistbrowse_num_artists(result); i++) json_array_append_new(results, get_artist(sp_toplistbrowse_artist(result, i))); for(i = 0; i < sp_toplistbrowse_num_albums(result); i++) json_array_append_new(results, get_album(sp_toplistbrowse_album(result, i))); for(i = 0; i < sp_toplistbrowse_num_tracks(result); i++) json_array_append_new(results, get_track(sp_toplistbrowse_track(result, i))); cmd_sendresponse(json, 200); sp_toplistbrowse_release(result); cmd_done(); }