X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fsoundcloud_upload.cc;h=68ab2fa2f6600db6051019a56e9ec20761dfb4dc;hb=6d343ba3c607f5210ae03edb17ba51d662c7f79b;hp=f003d5ab654d06b7ed41155fb77f6abdce941a5e;hpb=a643c9fdc08f98c7750a2474004a75e143077be9;p=ardour.git diff --git a/libs/ardour/soundcloud_upload.cc b/libs/ardour/soundcloud_upload.cc index f003d5ab65..68ab2fa2f6 100644 --- a/libs/ardour/soundcloud_upload.cc +++ b/libs/ardour/soundcloud_upload.cc @@ -20,23 +20,21 @@ *************************************************************************************/ +#include "ardour/debug.h" #include "ardour/soundcloud_upload.h" #include "pbd/xml++.h" #include -//#include "pbd/filesystem.h" #include #include #include -#include +#include "pbd/gstdio_compat.h" #include "i18n.h" using namespace PBD; -// static const std::string base_url = "http://api.soundcloud.com/tracks/13158665?client_id="; - size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data) { @@ -74,17 +72,17 @@ SoundcloudUploader::Get_Auth_Token( std::string username, std::string password ) struct curl_httppost *formpost=NULL; struct curl_httppost *lastptr=NULL; - /* Fill in the filename field */ + /* Fill in the filename field */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "client_id", - CURLFORM_COPYCONTENTS, "e7ac891eef866f139773cf8102b7a719", + CURLFORM_COPYCONTENTS, "6dd9cf0ad281aa57e07745082cec580b", CURLFORM_END); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "client_secret", - CURLFORM_COPYCONTENTS, "d78f34d19f09d26731801a0cb0f382c4", + CURLFORM_COPYCONTENTS, "53f5b0113fb338800f8a7a9904fc3569", CURLFORM_END); curl_formadd(&formpost, @@ -110,7 +108,7 @@ SoundcloudUploader::Get_Auth_Token( std::string username, std::string password ) headerlist = curl_slist_append(headerlist, "Accept: application/xml"); curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headerlist); - /* what URL that receives this POST */ + /* what URL that receives this POST */ std::string url = "https://api.soundcloud.com/oauth2/token"; curl_easy_setopt(curl_handle, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl_handle, CURLOPT_HTTPPOST, formpost); @@ -119,13 +117,13 @@ SoundcloudUploader::Get_Auth_Token( std::string username, std::string password ) // perform online request CURLcode res = curl_easy_perform(curl_handle); - if( res != 0 ) { - std::cerr << "curl error " << res << " (" << curl_easy_strerror(res) << ")" << std::endl; + if (res != 0) { + DEBUG_TRACE (DEBUG::Soundcloud, string_compose ("curl error %1 (%2)", res, curl_easy_strerror(res) ) ); return ""; } - if(xml_page.memory){ - //cheesy way to parse the json return value. find access_token, then advance 3 quotes + if (xml_page.memory){ + // cheesy way to parse the json return value. find access_token, then advance 3 quotes if ( strstr ( xml_page.memory , "access_token" ) == NULL) { error << _("Upload to Soundcloud failed. Perhaps your email or password are incorrect?\n") << endmsg; @@ -148,14 +146,14 @@ int SoundcloudUploader::progress_callback(void *caller, double dltotal, double dlnow, double ultotal, double ulnow) { SoundcloudUploader *scu = (SoundcloudUploader *) caller; - std::cerr << scu->title << ": uploaded " << ulnow << " of " << ultotal << std::endl; + DEBUG_TRACE (DEBUG::Soundcloud, string_compose ("%1: uploaded %2 of %3", scu->title, ulnow, ultotal) ); scu->caller->SoundcloudProgress(ultotal, ulnow, scu->title); /* EMIT SIGNAL */ return 0; } std::string -SoundcloudUploader::Upload(std::string file_path, std::string title, std::string token, bool ispublic, ARDOUR::ExportHandler *caller) +SoundcloudUploader::Upload(std::string file_path, std::string title, std::string token, bool ispublic, bool downloadable, ARDOUR::ExportHandler *caller) { int still_running; @@ -172,14 +170,14 @@ SoundcloudUploader::Upload(std::string file_path, std::string title, std::string struct curl_httppost *lastptr=NULL; /* Fill in the file upload field. This makes libcurl load data from - the given file name when curl_easy_perform() is called. */ + the given file name when curl_easy_perform() is called. */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "track[asset_data]", CURLFORM_FILE, file_path.c_str(), CURLFORM_END); - /* Fill in the filename field */ + /* Fill in the filename field */ curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "oauth_token", @@ -198,8 +196,16 @@ SoundcloudUploader::Upload(std::string file_path, std::string title, std::string CURLFORM_COPYCONTENTS, ispublic ? "public" : "private", CURLFORM_END); + curl_formadd(&formpost, + &lastptr, + CURLFORM_COPYNAME, "track[downloadable]", + CURLFORM_COPYCONTENTS, downloadable ? "true" : "false", + CURLFORM_END); + + + /* initalize custom header list (stating that Expect: 100-continue is not - wanted */ + wanted */ struct curl_slist *headerlist=NULL; static const char buf[] = "Expect:"; headerlist = curl_slist_append(headerlist, buf); @@ -207,7 +213,7 @@ SoundcloudUploader::Upload(std::string file_path, std::string title, std::string if (curl_handle && multi_handle) { - /* what URL that receives this POST */ + /* what URL that receives this POST */ std::string url = "https://api.soundcloud.com/tracks"; curl_easy_setopt(curl_handle, CURLOPT_URL, url.c_str()); // curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L); @@ -229,7 +235,7 @@ SoundcloudUploader::Upload(std::string file_path, std::string title, std::string while(still_running) { struct timeval timeout; - int rc; /* select() return code */ + int rc; /* select() return code */ fd_set fdread; fd_set fdwrite; @@ -242,7 +248,7 @@ SoundcloudUploader::Upload(std::string file_path, std::string title, std::string FD_ZERO(&fdwrite); FD_ZERO(&fdexcep); - /* set a suitable timeout to play around with */ + /* set a suitable timeout to play around with */ timeout.tv_sec = 1; timeout.tv_usec = 0; @@ -255,33 +261,33 @@ SoundcloudUploader::Upload(std::string file_path, std::string title, std::string timeout.tv_usec = (curl_timeo % 1000) * 1000; } - /* get file descriptors from the transfers */ + /* get file descriptors from the transfers */ curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); /* In a real-world program you OF COURSE check the return code of the function calls. On success, the value of maxfd is guaranteed to be greater or equal than -1. We call select(maxfd + 1, ...), specially in case of (maxfd == -1), we call select(0, ...), which is basically equal - to sleep. */ + to sleep. */ rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout); switch(rc) { case -1: - /* select error */ + /* select error */ break; case 0: default: - /* timeout or readable/writable sockets */ + /* timeout or readable/writable sockets */ curl_multi_perform(multi_handle, &still_running); break; } - } + } - /* then cleanup the formpost chain */ + /* then cleanup the formpost chain */ curl_formfree(formpost); - /* free slist */ + /* free slist */ curl_slist_free_all (headerlist); } @@ -289,26 +295,26 @@ SoundcloudUploader::Upload(std::string file_path, std::string title, std::string if(xml_page.memory){ - std::cout << xml_page.memory << std::endl; + DEBUG_TRACE (DEBUG::Soundcloud, xml_page.memory); XMLTree doc; doc.read_buffer( xml_page.memory ); XMLNode *root = doc.root(); if (!root) { - std::cout << "no root XML node!" << std::endl; + DEBUG_TRACE (DEBUG::Soundcloud, "no root XML node!"); return ""; } XMLNode *url_node = root->child("permalink-url"); if (!url_node) { - std::cout << "no child node \"permalink-url\" found!" << std::endl; + DEBUG_TRACE (DEBUG::Soundcloud, "no child node \"permalink-url\" found!"); return ""; } XMLNode *text_node = url_node->child("text"); if (!text_node) { - std::cout << "no text node found!" << std::endl; + DEBUG_TRACE (DEBUG::Soundcloud, "no text node found!"); return ""; } @@ -338,7 +344,7 @@ SoundcloudUploader::setcUrlOptions() curl_easy_setopt(curl_handle, CURLOPT_ERRORBUFFER, errorBuffer); // Allow redirection curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1); - + // Allow connections to time out (without using signals) curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 30);