char *search_str_list() { size_t tracks = sp_search_num_tracks(search); size_t albums = sp_search_num_albums(search); size_t playlists = sp_search_num_playlists(search); size_t size = API_MESSAGE_LEN*(albums+tracks); char *ret = malloc(size); ret[0] = '\0'; int i; for(i=0; i<tracks; ++i) { num_pre(ret + strlen(ret), size, i, track_to_str, sp_search_track(search, i)); strncat(ret + strlen(ret), "\n", size); } for(; i<(tracks+albums); ++i) { num_pre(ret + strlen(ret), size, i, album_to_str, sp_search_album(search, i-tracks)); strncat(ret + strlen(ret), "\n", size); } for(; i<(tracks+albums+playlists); ++i) { num_pre(ret + strlen(ret), size, i, playlist_to_str, sp_search_playlist(search, i-tracks-albums)); strncat(ret + strlen(ret), "\n", size); } return ret; }
void search_for_tracks_at(sp_session *session, char *buf, size_t len, size_t i, bool (*f)(sp_track *)) { if(search == NULL) { return; } buf[0] = '\0'; if(search_is_track(i) && sp_track_is_loaded(sp_search_track(search, i))) { f(sp_search_track(search, i)); if(buf != NULL) { track_to_str(buf, len, sp_search_track(search, i)); } } if(search_is_album(i) && sp_album_is_loaded(sp_search_album(search, i-sp_search_num_tracks(search)))) { sp_albumbrowse_create(session, sp_search_album(search, i-sp_search_num_tracks(search)) ,on_albumbrowse_complete, f); if(buf != NULL) { album_to_str(buf, len, sp_search_album(search, i-sp_search_num_tracks(search))); } } if(search_is_playlist(i)) { sp_playlist *pl = sp_search_playlist(search, i-sp_search_num_tracks(search)-sp_search_num_albums(search)); if(sp_playlist_is_loaded(pl)) { int j; for(j = 0; j < sp_playlist_num_tracks(pl); ++j) { f(sp_playlist_track(pl, j)); } if(buf != NULL) { playlist_to_str(buf, len, pl); } } } }
static PyObject *Results_albums(Results *self) { int count = sp_search_num_albums(self->_search); PyObject *l = PyList_New(count); int i; for(i=0;i<count;++i) { Album *a = (Album *)PyObject_CallObject((PyObject *)&AlbumType, NULL); a->_album = sp_search_album(self->_search, i); PyList_SetItem(l, i, (PyObject *)a); } Py_INCREF(l); return l; }
void QSpotifySearch::populateAlbums(sp_search *search) { m_albumResults->clear(); if (m_enablePreview) m_albumResultsPreview->clear(); if (search) { int c = sp_search_num_albums(search); for (int i = 0; i < c; ++i) { sp_album *a = sp_search_album(search, i); if (!sp_album_is_available(a)) continue; std::shared_ptr<QSpotifyAlbum> album = QSpotifyCacheManager::instance().getAlbum(a); m_albumResults->appendRow(album); if(m_enablePreview && i < m_numPreviewItems) m_albumResultsPreview->appendRow(album); } } }
void SpotifyClient::SearchCompleteCallback(sp_search* result, void* userdata) { SpotifyClient* me = reinterpret_cast<SpotifyClient*>(userdata); if (!me->pending_searches_.contains(result)) { qLog(Warning) << "SearchComplete called with unknown search"; return; } // If there were any album results then we need to resolve those before // we can send our response. const int count = sp_search_num_albums(result); if (count != 0) { for (int i=0 ; i<count ; ++i) { sp_album* album = sp_search_album(result, i); sp_albumbrowse* browse = sp_albumbrowse_create(me->session_, album, &SearchAlbumBrowseComplete, me); me->pending_search_album_browse_responses_[browse] = result; } return; } me->SendSearchResponse(result); }
/** * Print the given search result with as much information as possible * * @param search The search result */ static void print_search(sp_search *search) { int i; printf("Query : %s\n", sp_search_query(search)); printf("Did you mean : %s\n", sp_search_did_you_mean(search)); printf("Tracks in total: %d\n", sp_search_total_tracks(search)); puts(""); for (i = 0; i < sp_search_num_tracks(search); ++i) print_track(sp_search_track(search, i)); puts(""); for (i = 0; i < sp_search_num_albums(search); ++i) print_album(sp_search_album(search, i)); puts(""); for (i = 0; i < sp_search_num_artists(search); ++i) print_artist(sp_search_artist(search, i)); puts(""); }
Album Search::albumAt(int index) const { return isValid() ? Album(sp_search_album(handle(), index)) : Album(); }