23 #include "ardour/debug.h"
30 #include <sys/types.h>
32 #include <glib/gstdio.h>
41 register int realsize = (int)(size * nmemb);
47 memcpy(&(mem->
memory[mem->
size]), ptr, realsize);
48 mem->
size += realsize;
56 curl_handle = curl_easy_init();
57 multi_handle = curl_multi_init();
70 curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (
void *) &xml_page);
72 struct curl_httppost *formpost=NULL;
73 struct curl_httppost *lastptr=NULL;
76 curl_formadd(&formpost,
78 CURLFORM_COPYNAME,
"client_id",
79 CURLFORM_COPYCONTENTS,
"6dd9cf0ad281aa57e07745082cec580b",
82 curl_formadd(&formpost,
84 CURLFORM_COPYNAME,
"client_secret",
85 CURLFORM_COPYCONTENTS,
"53f5b0113fb338800f8a7a9904fc3569",
88 curl_formadd(&formpost,
90 CURLFORM_COPYNAME,
"grant_type",
91 CURLFORM_COPYCONTENTS,
"password",
94 curl_formadd(&formpost,
96 CURLFORM_COPYNAME,
"username",
97 CURLFORM_COPYCONTENTS, username.c_str(),
100 curl_formadd(&formpost,
102 CURLFORM_COPYNAME,
"password",
103 CURLFORM_COPYCONTENTS, password.c_str(),
106 struct curl_slist *headerlist=NULL;
107 headerlist = curl_slist_append(headerlist,
"Expect:");
108 headerlist = curl_slist_append(headerlist,
"Accept: application/xml");
109 curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headerlist);
112 std::string url =
"https://api.soundcloud.com/oauth2/token";
113 curl_easy_setopt(curl_handle, CURLOPT_URL, url.c_str());
114 curl_easy_setopt(curl_handle, CURLOPT_HTTPPOST, formpost);
119 CURLcode res = curl_easy_perform(curl_handle);
128 if ( strstr ( xml_page.
memory ,
"access_token" ) == NULL) {
129 error <<
_(
"Upload to Soundcloud failed. Perhaps your email or password are incorrect?\n") <<
endmsg;
133 std::string token = strtok( xml_page.
memory,
"access_token" );
134 token = strtok( NULL,
"\"" );
135 token = strtok( NULL,
"\"" );
136 token = strtok( NULL,
"\"" );
167 curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (
void *) &xml_page);
169 struct curl_httppost *formpost=NULL;
170 struct curl_httppost *lastptr=NULL;
174 curl_formadd(&formpost,
176 CURLFORM_COPYNAME,
"track[asset_data]",
177 CURLFORM_FILE, file_path.c_str(),
181 curl_formadd(&formpost,
183 CURLFORM_COPYNAME,
"oauth_token",
184 CURLFORM_COPYCONTENTS, token.c_str(),
187 curl_formadd(&formpost,
189 CURLFORM_COPYNAME,
"track[title]",
190 CURLFORM_COPYCONTENTS, title.c_str(),
193 curl_formadd(&formpost,
195 CURLFORM_COPYNAME,
"track[sharing]",
196 CURLFORM_COPYCONTENTS, ispublic ?
"public" :
"private",
199 curl_formadd(&formpost,
201 CURLFORM_COPYNAME,
"track[downloadable]",
202 CURLFORM_COPYCONTENTS, downloadable ?
"true" :
"false",
209 struct curl_slist *headerlist=NULL;
210 static const char buf[] =
"Expect:";
211 headerlist = curl_slist_append(headerlist, buf);
214 if (curl_handle && multi_handle) {
217 std::string url =
"https://api.soundcloud.com/tracks";
218 curl_easy_setopt(curl_handle, CURLOPT_URL, url.c_str());
221 curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headerlist);
222 curl_easy_setopt(curl_handle, CURLOPT_HTTPPOST, formpost);
225 this->caller = caller;
227 curl_easy_setopt (curl_handle, CURLOPT_NOPROGRESS, 0);
229 curl_easy_setopt (curl_handle, CURLOPT_PROGRESSDATA,
this);
231 curl_multi_add_handle(multi_handle, curl_handle);
233 curl_multi_perform(multi_handle, &still_running);
236 while(still_running) {
237 struct timeval timeout;
245 long curl_timeo = -1;
255 curl_multi_timeout(multi_handle, &curl_timeo);
256 if(curl_timeo >= 0) {
257 timeout.tv_sec = curl_timeo / 1000;
258 if(timeout.tv_sec > 1)
261 timeout.tv_usec = (curl_timeo % 1000) * 1000;
265 curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
273 rc =
select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
282 curl_multi_perform(multi_handle, &still_running);
288 curl_formfree(formpost);
291 curl_slist_free_all (headerlist);
294 curl_easy_setopt (curl_handle, CURLOPT_NOPROGRESS, 1);
331 curl_easy_cleanup(curl_handle);
332 curl_multi_cleanup(multi_handle);
340 curl_global_init(CURL_GLOBAL_ALL);
342 curl_easy_setopt(curl_handle, CURLOPT_USERAGENT,
"libcurl-agent/1.0");
344 curl_easy_setopt(curl_handle, CURLOPT_ERRORBUFFER, errorBuffer);
346 curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1);
349 curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL, 1);
350 curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 30);
352 curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
353 curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
const std::string & content() const
LIBPBD_API Transmitter error
std::ostream & endmsg(std::ostream &ostr)
bool read_buffer(const std::string &)
#define DEBUG_TRACE(bits, str)
ARDOUR::ExportHandler * caller
std::string Get_Auth_Token(std::string username, std::string password)
size_t WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
LIBARDOUR_API PBD::PropertyDescriptor< bool > select
XMLNode * child(const char *) const
std::string Upload(std::string file_path, std::string title, std::string token, bool ispublic, bool downloadable, ARDOUR::ExportHandler *caller)
LIBARDOUR_API uint64_t Soundcloud
static int progress_callback(void *caller, double dltotal, double dlnow, double ultotal, double ulnow)
std::string string_compose(const std::string &fmt, const T1 &o1)
PBD::Signal3< void, double, double, std::string > SoundcloudProgress