+ if (!root) {
+ error << "no root XML node!" << endmsg;
+ break;
+ }
+
+ if ( strcmp(root->name().c_str(), "response") != 0) {
+ error << string_compose ("root node name == %1 != \"response\"", root->name()) << endmsg;
+ break;
+ }
+
+ //find out how many pages are available to search
+ XMLNode *res = root->child("num_pages");
+ if (res) {
+ string result = res->child("text")->content();
+ freesound_n_pages = atoi(result.c_str());
+ }
+
+ XMLNode *sounds_root = root->child("sounds");
+
+ if (!sounds_root) {
+ error << "no child node \"sounds\" found!" << endmsg;
+ break;
+ }
+
+ XMLNodeList sounds = sounds_root->children();
+ if (sounds.size() == 0) {
+ /* nothing found */
+ break;
+ }
+
+ XMLNodeConstIterator niter;
+ XMLNode *node;
+ for (niter = sounds.begin(); niter != sounds.end(); ++niter) {
+ node = *niter;
+ if( strcmp( node->name().c_str(), "resource") != 0 ){
+ error << string_compose ("node->name()=%1 != \"resource\"", node->name()) << endmsg;
+ freesound_search_cancel = true;
+ break;
+ }
+
+ // node->dump(cerr, "node:");
+
+ XMLNode *id_node = node->child ("id");
+ XMLNode *uri_node = node->child ("serve");
+ XMLNode *ofn_node = node->child ("original_filename");
+ XMLNode *dur_node = node->child ("duration");
+ XMLNode *siz_node = node->child ("filesize");
+ XMLNode *srt_node = node->child ("samplerate");
+ XMLNode *lic_node = node->child ("license");
+
+ if (id_node && uri_node && ofn_node && dur_node && siz_node && srt_node) {
+
+ std::string id = id_node->child("text")->content();
+ std::string uri = uri_node->child("text")->content();
+ std::string ofn = ofn_node->child("text")->content();
+ std::string dur = dur_node->child("text")->content();
+ std::string siz = siz_node->child("text")->content();
+ std::string srt = srt_node->child("text")->content();
+ std::string lic = lic_node->child("text")->content();
+
+ std::string r;
+ // cerr << "id=" << id << ",uri=" << uri << ",ofn=" << ofn << ",dur=" << dur << endl;
+
+ double duration_seconds = atof(dur.c_str());
+ double h, m, s;
+ char duration_hhmmss[16];
+ if (duration_seconds >= 99 * 60 * 60) {
+ strcpy(duration_hhmmss, ">99h");
+ } else {
+ s = modf(duration_seconds/60, &m) * 60;
+ m = modf(m/60, &h) * 60;
+ sprintf(duration_hhmmss, "%02.fh:%02.fm:%04.1fs",
+ h, m, s
+ );
+ }
+
+ double size_bytes = atof(siz.c_str());
+ char bsize[32];
+ if (size_bytes < 1000) {
+ sprintf(bsize, "%.0f %s", size_bytes, _("B"));
+ } else if (size_bytes < 1000000 ) {
+ sprintf(bsize, "%.1f %s", size_bytes / 1000.0, _("kB"));
+ } else if (size_bytes < 10000000) {
+ sprintf(bsize, "%.1f %s", size_bytes / 1000000.0, _("MB"));
+ } else if (size_bytes < 1000000000) {
+ sprintf(bsize, "%.2f %s", size_bytes / 1000000.0, _("MB"));
+ } else {
+ sprintf(bsize, "%.2f %s", size_bytes / 1000000000.0, _("GB"));
+ }
+
+ /* see http://www.freesound.org/help/faq/#licenses */
+ char shortlicense[64];
+ if(!lic.compare(0, 42, "http://creativecommons.org/licenses/by-nc/")){
+ sprintf(shortlicense, "CC-BY-NC");
+ } else if(!lic.compare(0, 39, "http://creativecommons.org/licenses/by/")) {
+ sprintf(shortlicense, "CC-BY");
+ } else if(!lic.compare("http://creativecommons.org/licenses/sampling+/1.0/")) {
+ sprintf(shortlicense, "sampling+");
+ } else if(!lic.compare(0, 40, "http://creativecommons.org/publicdomain/")) {
+ sprintf(shortlicense, "PD");
+ } else {
+ snprintf(shortlicense, 64, "%s", lic.c_str());
+ shortlicense[63]= '\0';