X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fsfdb_freesound_mootcher.cc;h=ed1e2abfebbe7b0496bf106188b73486c1501c0a;hb=4c42a77441e74356cd909d994e270d1e1314aad4;hp=7e13c4f68b285818ec90b23ae13e95898d1654d6;hpb=d23a97a6acd0c12c0694accaf6c875a13d5fcb1b;p=ardour.git diff --git a/gtk2_ardour/sfdb_freesound_mootcher.cc b/gtk2_ardour/sfdb_freesound_mootcher.cc index 7e13c4f68b..ed1e2abfeb 100644 --- a/gtk2_ardour/sfdb_freesound_mootcher.cc +++ b/gtk2_ardour/sfdb_freesound_mootcher.cc @@ -41,7 +41,7 @@ #include "sfdb_freesound_mootcher.h" #include "pbd/xml++.h" -#include "pbd/filesystem.h" +#include "pbd/error.h" #include #include @@ -54,10 +54,11 @@ #include "ardour/audio_library.h" +using namespace PBD; + static const std::string base_url = "http://www.freesound.org/api"; static const std::string api_key = "9d77cb8d841b4bcfa960e1aae62224eb"; // ardour3 - //------------------------------------------------------------------------ Mootcher::Mootcher() : curl(curl_easy_init()) @@ -91,10 +92,12 @@ void Mootcher::changeWorkingDir(const char *saveLocation) void Mootcher::ensureWorkingDir () { - PBD::sys::path p = basePath; - p /= "snd"; - if (!PBD::sys::is_directory (p)) { - PBD::sys::create_directories (p); + std::string p = Glib::build_filename (basePath, "snd"); + + if (!Glib::file_test (p, Glib::FILE_TEST_IS_DIR)) { + if (g_mkdir_with_parents (p.c_str(), 0775) != 0) { + PBD::error << "Unable to create Mootcher working dir" << endmsg; + } } } @@ -178,12 +181,11 @@ std::string Mootcher::doRequest(std::string uri, std::string params) } curl_easy_setopt(curl, CURLOPT_URL, url.c_str() ); - std::cerr << "doRequest: " << url << std::endl; // perform online request CURLcode res = curl_easy_perform(curl); if( res != 0 ) { - std::cerr << "curl error " << res << " (" << curl_easy_strerror(res) << ")" << std::endl; + error << string_compose (_("curl error %1 (%2)"), res, curl_easy_strerror(res)) << endmsg; return ""; } @@ -209,16 +211,21 @@ std::string Mootcher::searchText(std::string query, int page, std::string filter snprintf(buf, 23, "p=%d&", page); params += buf; } - - params += "q=" + query; - if (filter != "") - params += "&f=" + filter; + char *eq = curl_easy_escape(curl, query.c_str(), query.length()); + params += "q=\"" + std::string(eq) + "\""; + free(eq); + + if (filter != "") { + char *ef = curl_easy_escape(curl, filter.c_str(), filter.length()); + params += "&f=" + std::string(ef); + free(ef); + } if (sort) params += "&s=" + sortMethodString(sort); - params += "&fields=id,original_filename,duration,serve"; + params += "&fields=id,original_filename,duration,filesize,samplerate,license,serve"; return doRequest("/sounds/search", params); } @@ -233,8 +240,6 @@ std::string Mootcher::getSoundResourceFile(std::string ID) std::string xml; - std::cerr << "getSoundResourceFile(" << ID << ")" << std::endl; - // download the xmlfile into xml_page xml = doRequest("/sounds/" + ID, ""); @@ -244,12 +249,12 @@ std::string Mootcher::getSoundResourceFile(std::string ID) // if the page is not a valid xml document with a 'freesound' root if (freesound == NULL) { - std::cerr << "getSoundResourceFile: There is no valid root in the xml file" << std::endl; + error << _("getSoundResourceFile: There is no valid root in the xml file") << endmsg; return ""; } if (strcmp(doc.root()->name().c_str(), "response") != 0) { - std::cerr << "getSoundResourceFile: root =" << doc.root()->name() << ", != response" << std::endl; + error << string_compose (_("getSoundResourceFile: root = %1, != response"), doc.root()->name()) << endmsg; return ""; } @@ -300,7 +305,6 @@ std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID, if (testFile) { fseek (testFile , 0 , SEEK_END); if (ftell (testFile) > 256) { - std::cerr << "audio file " << audioFileName << " already exists" << std::endl; fclose (testFile); return audioFileName; } @@ -335,13 +339,12 @@ std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID, curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, audioFileWrite); curl_easy_setopt(curl, CURLOPT_WRITEDATA, theFile); - std::cerr << "downloading " << audioFileName << " from " << audioURL << "..." << std::endl; /* hack to get rid of the barber-pole stripes */ caller->freesound_progress_bar.hide(); caller->freesound_progress_bar.show(); std::string prog; - prog = string_compose (_("%1: [Stop]->"), originalFileName); + prog = string_compose (_("%1"), originalFileName); caller->freesound_progress_bar.set_text(prog); curl_easy_setopt (curl, CURLOPT_NOPROGRESS, 0); // turn on the progress bar @@ -356,11 +359,10 @@ std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID, caller->freesound_progress_bar.set_text(""); if( res != 0 ) { - std::cerr << "curl error " << res << " (" << curl_easy_strerror(res) << ")" << std::endl; + error << string_compose (_("curl error %1 (%2)"), res, curl_easy_strerror(res)) << endmsg; remove( audioFileName.c_str() ); return ""; } else { - std::cerr << "done!" << std::endl; // now download the tags &c. getSoundResourceFile(ID); } @@ -369,7 +371,7 @@ std::string Mootcher::getAudioFile(std::string originalFileName, std::string ID, } //--------- -int Mootcher::progress_callback(void *caller, double dltotal, double dlnow, double ultotal, double ulnow) +int Mootcher::progress_callback(void *caller, double dltotal, double dlnow, double /*ultotal*/, double /*ulnow*/) { SoundFileBrowser *sfb = (SoundFileBrowser *) caller; @@ -385,7 +387,6 @@ SoundFileBrowser *sfb = (SoundFileBrowser *) caller; while (Glib::MainContext::get_default()->iteration (false)) { /* do nothing */ } - std::cerr << "progress: " << dlnow << " of " << dltotal << " \r"; return 0; }