summaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorColin Fletcher <colin.m.fletcher@googlemail.com>2014-05-19 20:54:36 +0100
committerColin Fletcher <colin.m.fletcher@googlemail.com>2014-05-19 20:54:36 +0100
commit5399425f534e2d96d07cf29f427bfa0f39d904b7 (patch)
treeb2134c0b8e624b9df89904b942909ea3a688c563 /libs
parent529a31bde7d17cade6c942e11e098f2c37d984a3 (diff)
parentc464feb6aa96226856305531fedb8fba2e06689e (diff)
Merge branch 'export-dialog' into cairocanvas
Fix merge conflicts in: gtk2_ardour/export_range_markers_dialog.cc gtk2_ardour/wscript libs/ardour/ardour/export_handler.h libs/ardour/system_exec.cc libs/pbd/pbd/system_exec.h libs/pbd/system_exec.cc
Diffstat (limited to 'libs')
-rw-r--r--libs/ardour/ardour/export_format_manager.h2
-rw-r--r--libs/ardour/ardour/export_format_specification.h6
-rw-r--r--libs/ardour/ardour/export_handler.h16
-rw-r--r--libs/ardour/ardour/soundcloud_upload.h55
-rw-r--r--libs/ardour/ardour/system_exec.h1
-rw-r--r--libs/ardour/export_format_manager.cc14
-rw-r--r--libs/ardour/export_format_specification.cc24
-rw-r--r--libs/ardour/export_handler.cc77
-rw-r--r--libs/ardour/soundcloud_upload.cc349
-rw-r--r--libs/ardour/system_exec.cc10
-rw-r--r--libs/ardour/wscript1
-rw-r--r--libs/pbd/pbd/system_exec.h21
-rw-r--r--libs/pbd/system_exec.cc114
13 files changed, 674 insertions, 16 deletions
diff --git a/libs/ardour/ardour/export_format_manager.h b/libs/ardour/ardour/export_format_manager.h
index 9a95111509..dad7d84b72 100644
--- a/libs/ardour/ardour/export_format_manager.h
+++ b/libs/ardour/ardour/export_format_manager.h
@@ -100,6 +100,8 @@ class LIBARDOUR_API ExportFormatManager : public PBD::ScopedConnectionList
void select_with_cue (bool);
void select_with_toc (bool);
+ void select_upload (bool);
+ void set_command (std::string);
void select_src_quality (ExportFormatBase::SRCQuality value);
void select_trim_beginning (bool value);
void select_silence_beginning (AnyTime const & time);
diff --git a/libs/ardour/ardour/export_format_specification.h b/libs/ardour/ardour/export_format_specification.h
index 1593990d35..d41fe3e97a 100644
--- a/libs/ardour/ardour/export_format_specification.h
+++ b/libs/ardour/ardour/export_format_specification.h
@@ -96,6 +96,8 @@ class LIBARDOUR_API ExportFormatSpecification : public ExportFormatBase {
void set_tag (bool tag_it) { _tag = tag_it; }
void set_with_cue (bool yn) { _with_cue = yn; }
void set_with_toc (bool yn) { _with_toc = yn; }
+ void set_upload (bool yn) { _upload = yn; }
+ void set_command (std::string command) { _command = command; }
void set_silence_beginning (AnyTime const & value) { _silence_beginning = value; }
void set_silence_end (AnyTime const & value) { _silence_end = value; }
@@ -125,6 +127,8 @@ class LIBARDOUR_API ExportFormatSpecification : public ExportFormatBase {
float normalize_target () const { return _normalize_target; }
bool with_toc() const { return _with_toc; }
bool with_cue() const { return _with_cue; }
+ bool upload() const { return _upload; }
+ std::string command() const { return _command; }
bool tag () const { return _tag && supports_tagging; }
@@ -174,6 +178,8 @@ class LIBARDOUR_API ExportFormatSpecification : public ExportFormatBase {
float _normalize_target;
bool _with_toc;
bool _with_cue;
+ bool _upload;
+ std::string _command;
/* serialization helpers */
diff --git a/libs/ardour/ardour/export_handler.h b/libs/ardour/ardour/export_handler.h
index 1bc80a80e9..25a87045a8 100644
--- a/libs/ardour/ardour/export_handler.h
+++ b/libs/ardour/ardour/export_handler.h
@@ -31,6 +31,7 @@
#include "ardour/session.h"
#include "ardour/libardour_visibility.h"
#include "ardour/types.h"
+#include "pbd/signals.h"
namespace AudioGrapher {
class BroadcastInfo;
@@ -68,7 +69,7 @@ class LIBARDOUR_API ExportElementFactory
Session & session;
};
-class LIBARDOUR_API ExportHandler : public ExportElementFactory
+class LIBARDOUR_API ExportHandler : public ExportElementFactory, public sigc::trackable
{
public:
struct FileSpec {
@@ -95,6 +96,8 @@ class LIBARDOUR_API ExportHandler : public ExportElementFactory
friend boost::shared_ptr<ExportHandler> Session::get_export_handler();
ExportHandler (Session & session);
+ void command_output(std::string output, size_t size);
+
public:
~ExportHandler ();
@@ -105,6 +108,17 @@ class LIBARDOUR_API ExportHandler : public ExportElementFactory
std::string get_cd_marker_filename(std::string filename, CDMarkerFormat format);
+ /** signal emitted when soundcloud export reports progress updates during upload.
+ * The parameters are total and current bytes downloaded, and the current filename
+ */
+ PBD::Signal3<void, double, double, std::string> SoundcloudProgress;
+
+ /* upload credentials & preferences */
+ std::string upload_username;
+ std::string upload_password;
+ bool upload_public;
+ bool upload_open;
+
private:
void handle_duplicate_format_extensions();
diff --git a/libs/ardour/ardour/soundcloud_upload.h b/libs/ardour/ardour/soundcloud_upload.h
new file mode 100644
index 0000000000..6b8700e784
--- /dev/null
+++ b/libs/ardour/ardour/soundcloud_upload.h
@@ -0,0 +1,55 @@
+/* soundcloud_upload.h ******************************************************
+
+ Adapted for Ardour by Ben Loftis, March 2012
+
+*****************************************************************************/
+
+#ifndef __ardour_soundcloud_upload_h__
+#define __ardour_soundcloud_upload_h__
+
+#include <string>
+#include <fstream>
+#include <iostream>
+#include <stdio.h>
+#include <cstring>
+#include <string>
+#include <sstream>
+#include <vector>
+
+#include "curl/curl.h"
+#include "ardour/session_handle.h"
+#include "ardour/export_handler.h"
+#include "pbd/signals.h"
+
+//--- struct to store XML file
+struct MemoryStruct {
+ char *memory;
+ size_t size;
+};
+
+
+class SoundcloudUploader
+{
+public:
+ SoundcloudUploader();
+ ~SoundcloudUploader();
+
+ std::string Get_Auth_Token(std::string username, std::string password);
+ std::string Upload (std::string file_path, std::string title, std::string token, bool ispublic, ARDOUR::ExportHandler *caller);
+ static int progress_callback(void *caller, double dltotal, double dlnow, double ultotal, double ulnow);
+
+
+private:
+
+ void setcUrlOptions();
+
+ CURL *curl_handle;
+ CURLM *multi_handle;
+ char errorBuffer[CURL_ERROR_SIZE]; // storage for cUrl error message
+
+ std::string title;
+ ARDOUR::ExportHandler *caller;
+
+};
+
+#endif /* __ardour_soundcloud_upload_h__ */
diff --git a/libs/ardour/ardour/system_exec.h b/libs/ardour/ardour/system_exec.h
index 40e429720e..ae865c7bff 100644
--- a/libs/ardour/ardour/system_exec.h
+++ b/libs/ardour/ardour/system_exec.h
@@ -32,6 +32,7 @@ class LIBARDOUR_API SystemExec
public:
SystemExec (std::string c, std::string a = "");
SystemExec (std::string c, char ** a);
+ SystemExec (std::string c, const std::map<char, std::string> subs);
~SystemExec ();
int start (int stderr_mode = 1) {
diff --git a/libs/ardour/export_format_manager.cc b/libs/ardour/export_format_manager.cc
index 890623c114..3ee940ffb6 100644
--- a/libs/ardour/export_format_manager.cc
+++ b/libs/ardour/export_format_manager.cc
@@ -294,6 +294,20 @@ ExportFormatManager::select_with_toc (bool value)
}
void
+ExportFormatManager::select_upload (bool value)
+{
+ current_selection->set_upload (value);
+ check_for_description_change ();
+}
+
+void
+ExportFormatManager::set_command (std::string command)
+{
+ current_selection->set_command (command);
+ check_for_description_change ();
+}
+
+void
ExportFormatManager::select_trim_beginning (bool value)
{
current_selection->set_trim_beginning (value);
diff --git a/libs/ardour/export_format_specification.cc b/libs/ardour/export_format_specification.cc
index b139faeee2..8b921519f7 100644
--- a/libs/ardour/export_format_specification.cc
+++ b/libs/ardour/export_format_specification.cc
@@ -170,6 +170,8 @@ ExportFormatSpecification::ExportFormatSpecification (Session & s)
, _normalize_target (1.0)
, _with_toc (false)
, _with_cue (false)
+ , _upload (false)
+ , _command ("")
{
format_ids.insert (F_None);
endiannesses.insert (E_FileDefault);
@@ -244,6 +246,8 @@ ExportFormatSpecification::get_state ()
root->add_property ("id", _id.to_s());
root->add_property ("with-cue", _with_cue ? "true" : "false");
root->add_property ("with-toc", _with_toc ? "true" : "false");
+ root->add_property ("upload", _upload ? "true" : "false");
+ root->add_property ("command", _command);
node = root->add_child ("Encoding");
node->add_property ("id", enum_2_string (format_id()));
@@ -321,6 +325,18 @@ ExportFormatSpecification::set_state (const XMLNode & root)
_with_toc = false;
}
+ if ((prop = root.property ("upload"))) {
+ _upload = string_is_affirmative (prop->value());
+ } else {
+ _upload = false;
+ }
+
+ if ((prop = root.property ("command"))) {
+ _command = prop->value();
+ } else {
+ _command = "";
+ }
+
/* Encoding and SRC */
if ((child = root.child ("Encoding"))) {
@@ -590,6 +606,14 @@ ExportFormatSpecification::description (bool include_name)
components.push_back ("CUE");
}
+ if (_upload) {
+ components.push_back ("Upload");
+ }
+
+ if (!_command.empty()) {
+ components.push_back ("+");
+ }
+
string desc;
if (include_name) {
desc = _name + ": ";
diff --git a/libs/ardour/export_handler.cc b/libs/ardour/export_handler.cc
index 20abc80de1..c9f20d182e 100644
--- a/libs/ardour/export_handler.cc
+++ b/libs/ardour/export_handler.cc
@@ -33,6 +33,10 @@
#include "ardour/export_status.h"
#include "ardour/export_format_specification.h"
#include "ardour/export_filename.h"
+#include "ardour/soundcloud_upload.h"
+#include "ardour/system_exec.h"
+#include "pbd/openuri.h"
+#include "pbd/basename.h"
#include "ardour/session_metadata.h"
#include "i18n.h"
@@ -278,6 +282,13 @@ ExportHandler::process_normalize ()
}
void
+ExportHandler::command_output(std::string output, size_t size)
+{
+ std::cerr << "command: " << size << ", " << output << std::endl;
+ info << output << endmsg;
+}
+
+void
ExportHandler::finish_timespan ()
{
while (config_map.begin() != timespan_bounds.second) {
@@ -297,13 +308,77 @@ ExportHandler::finish_timespan ()
AudiofileTagger::tag_file(filename, *SessionMetadata::Metadata());
}
+ if (!fmt->command().empty()) {
+
+#if 0 // would be nicer with C++11 initialiser...
+ std::map<char, std::string> subs {
+ { 'f', filename },
+ { 'd', Glib::path_get_dirname(filename) },
+ { 'b', PBD::basename_nosuffix(filename) },
+ { 'u', upload_username },
+ { 'p', upload_password}
+ };
+#endif
+
+ PBD::ScopedConnection command_connection;
+ std::map<char, std::string> subs;
+ subs.insert (std::pair<char, std::string> ('f', filename));
+ subs.insert (std::pair<char, std::string> ('d', Glib::path_get_dirname(filename)));
+ subs.insert (std::pair<char, std::string> ('b', PBD::basename_nosuffix(filename)));
+ subs.insert (std::pair<char, std::string> ('u', upload_username));
+ subs.insert (std::pair<char, std::string> ('p', upload_password));
+
+
+ std::cerr << "running command: " << fmt->command() << "..." << std::endl;
+ ARDOUR::SystemExec *se = new ARDOUR::SystemExec(fmt->command(), subs);
+ se->ReadStdout.connect_same_thread(command_connection, boost::bind(&ExportHandler::command_output, this, _1, _2));
+ if (se->start (2) == 0) {
+ // successfully started
+ std::cerr << "started!" << std::endl;
+ while (se->is_running ()) {
+ // wait for system exec to terminate
+ // std::cerr << "waiting..." << std::endl;
+ usleep (1000);
+ }
+ }
+ std::cerr << "done! deleting..." << std::endl;
+ delete (se);
+ }
+
+ if (fmt->upload()) {
+ SoundcloudUploader *soundcloud_uploader = new SoundcloudUploader;
+ std::string token = soundcloud_uploader->Get_Auth_Token(upload_username, upload_password);
+ std::cerr
+ << "uploading "
+ << filename << std::endl
+ << "username = " << upload_username
+ << ", password = " << upload_password
+ << " - token = " << token << " ..."
+ << std::endl;
+ std::string path = soundcloud_uploader->Upload (
+ filename,
+ PBD::basename_nosuffix(filename), // title
+ token,
+ upload_public,
+ this);
+
+ if (path.length() != 0) {
+ if (upload_open) {
+ std::cerr << "opening " << path << " ..." << std::endl;
+ open_uri(path.c_str()); // open the soundcloud website to the new file
+ }
+ } else {
+ error << _("upload to Soundcloud failed. Perhaps your email or password are incorrect?\n") << endmsg;
+ }
+ delete soundcloud_uploader;
+ }
config_map.erase (config_map.begin());
}
start_timespan ();
}
-/*** CD Marker sutff ***/
+/*** CD Marker stuff ***/
struct LocationSortByStart {
bool operator() (Location *a, Location *b) {
diff --git a/libs/ardour/soundcloud_upload.cc b/libs/ardour/soundcloud_upload.cc
new file mode 100644
index 0000000000..f003d5ab65
--- /dev/null
+++ b/libs/ardour/soundcloud_upload.cc
@@ -0,0 +1,349 @@
+/* soundcloud_export.cpp **********************************************************************
+
+ Adapted for Ardour by Ben Loftis, March 2012
+
+ Licence GPL:
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+
+*************************************************************************************/
+#include "ardour/soundcloud_upload.h"
+
+#include "pbd/xml++.h"
+#include <pbd/error.h>
+//#include "pbd/filesystem.h"
+
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <iostream>
+#include <glib/gstdio.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)
+{
+ register int realsize = (int)(size * nmemb);
+ struct MemoryStruct *mem = (struct MemoryStruct *)data;
+
+ mem->memory = (char *)realloc(mem->memory, mem->size + realsize + 1);
+
+ if (mem->memory) {
+ memcpy(&(mem->memory[mem->size]), ptr, realsize);
+ mem->size += realsize;
+ mem->memory[mem->size] = 0;
+ }
+ return realsize;
+}
+
+SoundcloudUploader::SoundcloudUploader()
+{
+ curl_handle = curl_easy_init();
+ multi_handle = curl_multi_init();
+}
+
+std::string
+SoundcloudUploader::Get_Auth_Token( std::string username, std::string password )
+{
+ struct MemoryStruct xml_page;
+ xml_page.memory = NULL;
+ xml_page.size = 0;
+
+ setcUrlOptions();
+
+ curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
+ curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) &xml_page);
+
+ struct curl_httppost *formpost=NULL;
+ struct curl_httppost *lastptr=NULL;
+
+ /* Fill in the filename field */
+ curl_formadd(&formpost,
+ &lastptr,
+ CURLFORM_COPYNAME, "client_id",
+ CURLFORM_COPYCONTENTS, "e7ac891eef866f139773cf8102b7a719",
+ CURLFORM_END);
+
+ curl_formadd(&formpost,
+ &lastptr,
+ CURLFORM_COPYNAME, "client_secret",
+ CURLFORM_COPYCONTENTS, "d78f34d19f09d26731801a0cb0f382c4",
+ CURLFORM_END);
+
+ curl_formadd(&formpost,
+ &lastptr,
+ CURLFORM_COPYNAME, "grant_type",
+ CURLFORM_COPYCONTENTS, "password",
+ CURLFORM_END);
+
+ curl_formadd(&formpost,
+ &lastptr,
+ CURLFORM_COPYNAME, "username",
+ CURLFORM_COPYCONTENTS, username.c_str(),
+ CURLFORM_END);
+
+ curl_formadd(&formpost,
+ &lastptr,
+ CURLFORM_COPYNAME, "password",
+ CURLFORM_COPYCONTENTS, password.c_str(),
+ CURLFORM_END);
+
+ struct curl_slist *headerlist=NULL;
+ headerlist = curl_slist_append(headerlist, "Expect:");
+ headerlist = curl_slist_append(headerlist, "Accept: application/xml");
+ curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headerlist);
+
+ /* 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);
+
+ // curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L);
+
+ // perform online request
+ CURLcode res = curl_easy_perform(curl_handle);
+ if( res != 0 ) {
+ std::cerr << "curl error " << res << " (" << curl_easy_strerror(res) << ")" << std::endl;
+ return "";
+ }
+
+ 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;
+ return "";
+ }
+
+ std::string token = strtok( xml_page.memory, "access_token" );
+ token = strtok( NULL, "\"" );
+ token = strtok( NULL, "\"" );
+ token = strtok( NULL, "\"" );
+
+ free( xml_page.memory );
+ return token;
+ }
+
+ return "";
+}
+
+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;
+ 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)
+{
+ int still_running;
+
+ struct MemoryStruct xml_page;
+ xml_page.memory = NULL;
+ xml_page.size = 0;
+
+ setcUrlOptions();
+
+ curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
+ curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *) &xml_page);
+
+ struct curl_httppost *formpost=NULL;
+ 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. */
+ curl_formadd(&formpost,
+ &lastptr,
+ CURLFORM_COPYNAME, "track[asset_data]",
+ CURLFORM_FILE, file_path.c_str(),
+ CURLFORM_END);
+
+ /* Fill in the filename field */
+ curl_formadd(&formpost,
+ &lastptr,
+ CURLFORM_COPYNAME, "oauth_token",
+ CURLFORM_COPYCONTENTS, token.c_str(),
+ CURLFORM_END);
+
+ curl_formadd(&formpost,
+ &lastptr,
+ CURLFORM_COPYNAME, "track[title]",
+ CURLFORM_COPYCONTENTS, title.c_str(),
+ CURLFORM_END);
+
+ curl_formadd(&formpost,
+ &lastptr,
+ CURLFORM_COPYNAME, "track[sharing]",
+ CURLFORM_COPYCONTENTS, ispublic ? "public" : "private",
+ CURLFORM_END);
+
+ /* initalize custom header list (stating that Expect: 100-continue is not
+ wanted */
+ struct curl_slist *headerlist=NULL;
+ static const char buf[] = "Expect:";
+ headerlist = curl_slist_append(headerlist, buf);
+
+
+ if (curl_handle && multi_handle) {
+
+ /* 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);
+
+ curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, headerlist);
+ curl_easy_setopt(curl_handle, CURLOPT_HTTPPOST, formpost);
+
+ this->title = title; // save title to show in progress bar
+ this->caller = caller;
+
+ curl_easy_setopt (curl_handle, CURLOPT_NOPROGRESS, 0); // turn on the progress bar
+ curl_easy_setopt (curl_handle, CURLOPT_PROGRESSFUNCTION, &SoundcloudUploader::progress_callback);
+ curl_easy_setopt (curl_handle, CURLOPT_PROGRESSDATA, this);
+
+ curl_multi_add_handle(multi_handle, curl_handle);
+
+ curl_multi_perform(multi_handle, &still_running);
+
+
+ while(still_running) {
+ struct timeval timeout;
+ int rc; /* select() return code */
+
+ fd_set fdread;
+ fd_set fdwrite;
+ fd_set fdexcep;
+ int maxfd = -1;
+
+ long curl_timeo = -1;
+
+ FD_ZERO(&fdread);
+ FD_ZERO(&fdwrite);
+ FD_ZERO(&fdexcep);
+
+ /* set a suitable timeout to play around with */
+ timeout.tv_sec = 1;
+ timeout.tv_usec = 0;
+
+ curl_multi_timeout(multi_handle, &curl_timeo);
+ if(curl_timeo >= 0) {
+ timeout.tv_sec = curl_timeo / 1000;
+ if(timeout.tv_sec > 1)
+ timeout.tv_sec = 1;
+ else
+ timeout.tv_usec = (curl_timeo % 1000) * 1000;
+ }
+
+ /* 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. */
+
+ rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);
+
+ switch(rc) {
+ case -1:
+ /* select error */
+ break;
+ case 0:
+ default:
+ /* timeout or readable/writable sockets */
+ curl_multi_perform(multi_handle, &still_running);
+ break;
+ }
+ }
+
+ /* then cleanup the formpost chain */
+ curl_formfree(formpost);
+
+ /* free slist */
+ curl_slist_free_all (headerlist);
+ }
+
+ curl_easy_setopt (curl_handle, CURLOPT_NOPROGRESS, 1); // turn off the progress bar
+
+ if(xml_page.memory){
+
+ std::cout << xml_page.memory << std::endl;
+
+ XMLTree doc;
+ doc.read_buffer( xml_page.memory );
+ XMLNode *root = doc.root();
+
+ if (!root) {
+ std::cout << "no root XML node!" << std::endl;
+ return "";
+ }
+
+ XMLNode *url_node = root->child("permalink-url");
+ if (!url_node) {
+ std::cout << "no child node \"permalink-url\" found!" << std::endl;
+ return "";
+ }
+
+ XMLNode *text_node = url_node->child("text");
+ if (!text_node) {
+ std::cout << "no text node found!" << std::endl;
+ return "";
+ }
+
+ free( xml_page.memory );
+ return text_node->content();
+ }
+
+ return "";
+};
+
+
+SoundcloudUploader:: ~SoundcloudUploader()
+{
+ curl_easy_cleanup(curl_handle);
+ curl_multi_cleanup(multi_handle);
+}
+
+
+void
+SoundcloudUploader::setcUrlOptions()
+{
+ // basic init for curl
+ curl_global_init(CURL_GLOBAL_ALL);
+ // some servers don't like requests that are made without a user-agent field, so we provide one
+ curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");
+ // setup curl error buffer
+ 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);
+
+ curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
+ curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
+}
+
diff --git a/libs/ardour/system_exec.cc b/libs/ardour/system_exec.cc
index 90e729a7f6..760a9b7878 100644
--- a/libs/ardour/system_exec.cc
+++ b/libs/ardour/system_exec.cc
@@ -65,4 +65,14 @@ SystemExec::SystemExec (std::string c, std::string a)
#endif
}
+SystemExec::SystemExec (std::string c, const std::map<char, std::string> subs)
+ : PBD::SystemExec(c, subs)
+{
+#ifndef PLATFORM_WINDOWS
+ if (!_vfork_exec_wrapper) {
+ _vfork_exec_wrapper = vfork_exec_wrapper_path();
+ }
+#endif
+}
+
SystemExec::~SystemExec() { }
diff --git a/libs/ardour/wscript b/libs/ardour/wscript
index 4a50064545..85326e98f8 100644
--- a/libs/ardour/wscript
+++ b/libs/ardour/wscript
@@ -194,6 +194,7 @@ libardour_sources = [
'sndfile_helpers.cc',
'sndfileimportable.cc',
'sndfilesource.cc',
+ 'soundcloud_upload.cc',
'source.cc',
'source_factory.cc',
'speakers.cc',
diff --git a/libs/pbd/pbd/system_exec.h b/libs/pbd/pbd/system_exec.h
index 1232175fec..ce6e5a9c4f 100644
--- a/libs/pbd/pbd/system_exec.h
+++ b/libs/pbd/pbd/system_exec.h
@@ -42,6 +42,8 @@
#include <string>
#include <pthread.h>
#include <signal.h>
+#include <map>
+
#ifdef NOPBD /* unit-test outside ardour */
#include <sigc++/bind.h>
#include <sigc++/signal.h>
@@ -94,6 +96,23 @@ class LIBPBD_API SystemExec
*
*/
SystemExec (std::string c, char ** a);
+
+ /** similar to \ref SystemExec but expects a whole command line, and
+ * handles some simple escape sequences.
+ *
+ * @param command complete command-line to be executed
+ * @param subs a map of <char, std::string> listing the % substitutions to
+ * be made.
+ *
+ * creates an argv array from the given command string, splitting into
+ * parameters at spaces.
+ * "\ " is non-splitting space, "\\" (and "\" at end of command) as "\",
+ * for "%<char>", <char> is looked up in subs and the corresponding string
+ * substituted. "%%" (and "%" at end of command)
+ * returns an argv array suitable for creating a new SystemExec with
+ */
+ SystemExec (std::string command, const std::map<char, std::string> subs);
+
virtual ~SystemExec ();
/** fork and execute the given program
@@ -182,6 +201,7 @@ class LIBPBD_API SystemExec
int nicelevel; ///< process nice level - defaults to 0
void make_argp(std::string);
+ void make_argp_escaped(std::string command, const std::map<char, std::string> subs);
void make_envp();
char **argp;
@@ -198,6 +218,7 @@ class LIBPBD_API SystemExec
#else
pid_t pid;
#endif
+ void init ();
pthread_mutex_t write_lock;
int fdin; ///< file-descriptor for writing to child's STDIN. This variable is identical to pin[1] but also used as status check if the stdin pipe is open: <0 means closed.
diff --git a/libs/pbd/system_exec.cc b/libs/pbd/system_exec.cc
index 0102323505..82398af0c8 100644
--- a/libs/pbd/system_exec.cc
+++ b/libs/pbd/system_exec.cc
@@ -151,9 +151,8 @@ static int close_allv(const int except_fds[]) {
}
#endif /* not on windows, nor vfork */
-
-SystemExec::SystemExec (std::string c, std::string a)
- : cmd(c)
+void
+SystemExec::init ()
{
pthread_mutex_init(&write_lock, NULL);
thread_active=false;
@@ -161,12 +160,19 @@ SystemExec::SystemExec (std::string c, std::string a)
pin[1] = -1;
nicelevel = 0;
envp = NULL;
- argp = NULL;
#ifdef PLATFORM_WINDOWS
stdinP[0] = stdinP[1] = INVALID_HANDLE_VALUE;
stdoutP[0] = stdoutP[1] = INVALID_HANDLE_VALUE;
stderrP[0] = stderrP[1] = INVALID_HANDLE_VALUE;
#endif
+}
+
+SystemExec::SystemExec (std::string c, std::string a)
+ : cmd(c)
+{
+ init ();
+
+ argp = NULL;
make_envp();
make_argp(a);
}
@@ -174,21 +180,101 @@ SystemExec::SystemExec (std::string c, std::string a)
SystemExec::SystemExec (std::string c, char **a)
: cmd(c) , argp(a)
{
- pthread_mutex_init(&write_lock, NULL);
- thread_active=false;
- pid = 0;
- pin[1] = -1;
- nicelevel = 0;
- envp = NULL;
+ init ();
+
#ifdef PLATFORM_WINDOWS
- stdinP[0] = stdinP[1] = INVALID_HANDLE_VALUE;
- stdoutP[0] = stdoutP[1] = INVALID_HANDLE_VALUE;
- stderrP[0] = stderrP[1] = INVALID_HANDLE_VALUE;
make_wargs(a);
#endif
make_envp();
}
+SystemExec::SystemExec (std::string command, const std::map<char, std::string> subs)
+{
+ init ();
+ make_argp_escaped(command, subs);
+ cmd = argp[0];
+ // cmd = strdup(argp[0]);
+ make_envp();
+}
+
+void
+SystemExec::make_argp_escaped(std::string command, const std::map<char, std::string> subs)
+{
+
+ int inquotes = 0;
+ int n = 0;
+ size_t i = 0;
+ std::string arg = "";
+
+ argp = (char **) malloc(sizeof(char *));
+
+ for (i = 0; i <= command.length(); i++) { // include terminating '\0'
+ char c = command.c_str()[i];
+ if (inquotes) {
+ if (c == '"') {
+ inquotes = 0;
+ } else {
+ // still in quotes - just copy
+ arg += c;
+ }
+ } else switch (c) {
+ case '%' :
+ c = command.c_str()[++i];
+ if (c == '%' || c == '\0') {
+ // "%%", "%" at end-of-string => "%"
+ arg += '%';
+ } else {
+ // search subs for string to substitute for char
+ std::map<char, std::string>::const_iterator s = subs.find(c);
+ if (s != subs.end()) {
+ // found substitution
+ arg += s->second;
+ } else {
+ // not a valid substitution, just copy
+ arg += '%';
+ arg += c;
+ }
+ }
+ break;
+ case '\\':
+ c = command.c_str()[++i];
+ switch (c) {
+ case ' ' :
+ case '"' : arg += c; break; // "\\", "\" at end-of-string => "\"
+ case '\0':
+ case '\\': arg += '\\'; break;
+ default : arg += '\\'; arg += c; break;
+ }
+ break;
+ case '"' :
+ inquotes = 1;
+ break;
+ case ' ' :
+ case '\t':
+ case '\0':
+ if (arg.length() > 0) {
+ // if there wasn't already a space or tab, start a new parameter
+ argp = (char **) realloc(argp, (n + 2) * sizeof(char *));
+ argp[n++] = strdup (arg.c_str());
+ arg = "";
+ }
+ break;
+ default :
+ arg += c;
+ break;
+ }
+ }
+ argp[n] = NULL;
+
+ char *p = argp[0];
+ n = 0;
+ do {
+ std::cerr << "argv[" << n << "] == \"" << p << "\"" << std::endl;
+ p = argp[n++];
+ } while (p);
+
+}
+
SystemExec::~SystemExec ()
{
terminate ();
@@ -522,7 +608,7 @@ SystemExec::make_argp(std::string args) {
*cp2 = '\0';
argp[argn++] = strdup(cp1);
cp1 = cp2 + 1;
- argp = (char **) realloc(argp, (argn + 1) * sizeof(char *));
+ argp = (char **) realloc(argp, (argn + 1) * sizeof(char *));
}
}
if (cp2 != cp1) {