View Issue Details

IDProjectCategoryView StatusLast Update
0006197ardourfeaturespublic2022-05-20 22:25
Reporterx42 Assigned Tox42  
PrioritynormalSeverityminorReproducibilityN/A
Status resolvedResolutionfixed 
Summary0006197: freesound import needs to be updated to new FS API
Descriptionjust a TODO reminder.. see summary.
TagsNo tags attached.

Relationships

related to 0006493 resolvedx42 Freesound import broken 

Activities

colinf

2016-01-19 01:10

updater   ~0017809

I have the search part of this nearly working already, but the Freesound APIv2 now requires OAuth in order to download sound files, so we're going to have to provide a means for users to log into their own Freesound accounts in Ardour if they want to download anything.

Not necessarily a big deal, but it is a bit more hassle than I hoped for. On the bright side, once I understand OAuth I can maybe make Soundcloud upload use it as well. Hopefully I'll have time to carry on looking at this soon.

colinf

2016-01-19 12:02

updater   ~0017810

For the moment now, I've hacked it to download the high-quality OGG preview when clicking on an item in the search results. That's not ideal, but I reckon is (marginally) better than nothing for the moment

colinf

2016-01-19 12:04

updater  

0001-New-DebugBit-for-Freesound.patch (1,277 bytes)   
From 1b859be2735e09fb02903de8978c146fef3c04fe Mon Sep 17 00:00:00 2001
From: Colin Fletcher <colin.m.fletcher@googlemail.com>
Date: Mon, 18 Jan 2016 18:53:38 +0000
Subject: [PATCH 1/4] New DebugBit for Freesound

---
 libs/ardour/ardour/debug.h | 1 +
 libs/ardour/debug.cc       | 1 +
 2 files changed, 2 insertions(+)

diff --git a/libs/ardour/ardour/debug.h b/libs/ardour/ardour/debug.h
index 6ebf21a..c1654b2 100644
--- a/libs/ardour/ardour/debug.h
+++ b/libs/ardour/ardour/debug.h
@@ -77,6 +77,7 @@ namespace PBD {
 		LIBARDOUR_API extern DebugBits BackendPorts;
 		LIBARDOUR_API extern DebugBits VSTCallbacks;
 		LIBARDOUR_API extern DebugBits FaderPort;
+		LIBARDOUR_API extern DebugBits Freesound;
 
 	}
 }
diff --git a/libs/ardour/debug.cc b/libs/ardour/debug.cc
index 86afaf6..9986082 100644
--- a/libs/ardour/debug.cc
+++ b/libs/ardour/debug.cc
@@ -74,3 +74,4 @@ PBD::DebugBits PBD::DEBUG::BackendThreads = PBD::new_debug_bit ("backendthreads"
 PBD::DebugBits PBD::DEBUG::BackendPorts = PBD::new_debug_bit ("backendports");
 PBD::DebugBits PBD::DEBUG::VSTCallbacks = PBD::new_debug_bit ("vstcallbacks");
 PBD::DebugBits PBD::DEBUG::FaderPort = PBD::new_debug_bit ("faderport");
+PBD::DebugBits PBD::DEBUG::Freesound = PBD::new_debug_bit ("freesound");
-- 
2.7.0.rc3

colinf

2016-01-19 12:05

updater  

0002-Update-to-Freesound-API-v2-search-only.patch (11,131 bytes)   
From c4eb943e685140bebc0f3956f141a3976d954135 Mon Sep 17 00:00:00 2001
From: Colin Fletcher <colin.m.fletcher@googlemail.com>
Date: Mon, 18 Jan 2016 18:38:12 +0000
Subject: [PATCH 2/4] Update to Freesound API v2 (search only)

Update the Freesound mootcher to use the new APIv2. Mostly working, except
that the actual download of the original file fails, because Freesound now
require OAuth authorisation for downloading, which I haven't yet implemented.
---
 gtk2_ardour/sfdb_freesound_mootcher.cc | 64 +++++++++++++++++++++++-----------
 gtk2_ardour/sfdb_freesound_mootcher.h  |  3 +-
 gtk2_ardour/sfdb_ui.cc                 | 22 ++++++------
 3 files changed, 58 insertions(+), 31 deletions(-)

diff --git a/gtk2_ardour/sfdb_freesound_mootcher.cc b/gtk2_ardour/sfdb_freesound_mootcher.cc
index 94e0058..3a24958 100644
--- a/gtk2_ardour/sfdb_freesound_mootcher.cc
+++ b/gtk2_ardour/sfdb_freesound_mootcher.cc
@@ -53,19 +53,29 @@
 #include "i18n.h"
 
 #include "ardour/audio_library.h"
+#include "ardour/debug.h"
 #include "ardour/rc_configuration.h"
 #include "pbd/pthread_utils.h"
 #include "gui_thread.h"
 
 using namespace PBD;
 
-static const std::string base_url = "http://www.freesound.org/api";
-static const std::string api_key = "9d77cb8d841b4bcfa960e1aae62224eb"; // ardour3
+static const std::string base_url = "http://www.freesound.org/apiv2";
+static const std::string default_api_key = "b2cc51878bd4fde055e3e84591eb289715d01503"; // Ardour 4
+// Ardour 4 	c7eff9328525c51775cb 	b2cc51878bd4fde055e3e84591eb289715d01503
+
+static const std::string fields = "id,name,duration,filesize,samplerate,license,download";
 
 //------------------------------------------------------------------------
-Mootcher::Mootcher()
+Mootcher::Mootcher(const std::string &the_api_key)
 	: curl(curl_easy_init())
 {
+	DEBUG_TRACE(PBD::DEBUG::Freesound, "Created new Mootcher\n");
+	if  (the_api_key != "") {
+		api_key = the_api_key;
+	} else {
+		api_key = default_api_key;
+	}
 	cancel_download_btn.set_label (_("Cancel"));
 	progress_hbox.pack_start (progress_bar, true, true);
 	progress_hbox.pack_end (cancel_download_btn, false, false);
@@ -77,6 +87,7 @@ Mootcher::Mootcher()
 Mootcher:: ~Mootcher()
 {
 	curl_easy_cleanup(curl);
+	DEBUG_TRACE(PBD::DEBUG::Freesound, "Destroyed Mootcher\n");
 }
 
 //------------------------------------------------------------------------
@@ -85,6 +96,7 @@ void Mootcher::ensureWorkingDir ()
 {
 	std::string p = ARDOUR::Config->get_freesound_download_dir();
 
+	DEBUG_TRACE(PBD::DEBUG::Freesound, "ensureWorkingDir() - " + p + "\n");
 	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;
@@ -176,17 +188,21 @@ std::string Mootcher::doRequest(std::string uri, std::string params)
 	// the url to get
 	std::string url = base_url + uri + "?";
 	if (params != "") {
-		url += params + "&api_key=" + api_key + "&format=xml";
+		url += params + "&token=" + api_key + "&format=xml";
 	} else {
-		url += "api_key=" + api_key + "&format=xml";
+		url += "token=" + api_key + "&format=xml";
 	}
 
 	curl_easy_setopt(curl, CURLOPT_URL, url.c_str() );
 
+	DEBUG_TRACE(PBD::DEBUG::Freesound, url + "\n"); 
+
 	// perform online request
 	CURLcode res = curl_easy_perform(curl);
 	if( res != 0 ) {
-		error << string_compose (_("curl error %1 (%2)"), res, curl_easy_strerror(res)) << endmsg;
+		std::string errmsg = string_compose (_("curl error %1 (%2)"), res, curl_easy_strerror(res));
+		error << errmsg << endmsg;
+		DEBUG_TRACE(PBD::DEBUG::Freesound, errmsg + "\n"); 
 		return "";
 	}
 
@@ -199,6 +215,7 @@ std::string Mootcher::doRequest(std::string uri, std::string params)
 	xml_page.memory = NULL;
 	xml_page.size = 0;
 
+	DEBUG_TRACE(PBD::DEBUG::Freesound, result + "\n");
 	return result;
 }
 
@@ -207,10 +224,12 @@ std::string Mootcher::searchSimilar(std::string id)
 {
 	std::string params = "";
 
-	params += "&fields=id,original_filename,duration,filesize,samplerate,license,serve";
+	params += "&fields=" + fields;
 	params += "&num_results=100";
+	// XXX should we filter out MP3s here, too?
+	// XXX and what if there are more than 100 similar sounds?
 
-	return doRequest("/sounds/" + id + "/similar", params);
+	return doRequest("/sounds/" + id + "/similar/", params);
 }
 
 //------------------------------------------------------------------------
@@ -221,27 +240,27 @@ std::string Mootcher::searchText(std::string query, int page, std::string filter
 	char buf[24];
 
 	if (page > 1) {
-		snprintf(buf, 23, "p=%d&", page);
+		snprintf(buf, 23, "page=%d&", page);
 		params += buf;
 	}
 
 	char *eq = curl_easy_escape(curl, query.c_str(), query.length());
-	params += "q=\"" + std::string(eq) + "\"";
+	params += "query=\"" + std::string(eq) + "\"";
 	free(eq);
 
 	if (filter != "") {
 		char *ef = curl_easy_escape(curl, filter.c_str(), filter.length());
-		params += "&f=" + std::string(ef);
+		params += "&filter=" + std::string(ef);
 		free(ef);
 	}
 
 	if (sort)
-		params += "&s=" + sortMethodString(sort);
+		params += "&sort=" + sortMethodString(sort);
 
-	params += "&fields=id,original_filename,duration,filesize,samplerate,license,serve";
-	params += "&sounds_per_page=100";
+	params += "&fields=" + fields;
+	params += "&page_size=100";
 
-	return doRequest("/sounds/search", params);
+	return doRequest("/search/text/", params);
 }
 
 //------------------------------------------------------------------------
@@ -255,7 +274,7 @@ std::string Mootcher::getSoundResourceFile(std::string ID)
 
 
 	// download the xmlfile into xml_page
-	xml = doRequest("/sounds/" + ID, "");
+	xml = doRequest("/sounds/" + ID + "/", "");
 
 	XMLTree doc;
 	doc.read_buffer( xml.c_str() );
@@ -267,12 +286,12 @@ std::string Mootcher::getSoundResourceFile(std::string ID)
 		return "";
 	}
 
-	if (strcmp(doc.root()->name().c_str(), "response") != 0) {
-		error << string_compose (_("getSoundResourceFile: root = %1, != response"), doc.root()->name()) << endmsg;
+	if (strcmp(doc.root()->name().c_str(), "root") != 0) {
+		error << string_compose (_("getSoundResourceFile: root = %1, != \"root\""), doc.root()->name()) << endmsg;
 		return "";
 	}
 
-	XMLNode *name = freesound->child("original_filename");
+	XMLNode *name = freesound->child("name");
 
 	// get the file name and size from xml file
 	if (name) {
@@ -361,6 +380,7 @@ freesound_download_thread_func(void *arg)
 
 bool Mootcher::checkAudioFile(std::string originalFileName, std::string theID)
 {
+	DEBUG_TRACE(PBD::DEBUG::Freesound, string_compose("checkAudiofile(%1, %2)\n", originalFileName, theID));
 	ensureWorkingDir();
 	ID = theID;
 	audioFileName = Glib::build_filename (basePath, ID + "-" + originalFileName);
@@ -384,6 +404,9 @@ bool Mootcher::checkAudioFile(std::string originalFileName, std::string theID)
 
 bool Mootcher::fetchAudioFile(std::string originalFileName, std::string theID, std::string audioURL, SoundFileBrowser *caller)
 {
+
+	DEBUG_TRACE(PBD::DEBUG::Freesound, string_compose("fetchAudiofile(%1, %2, %3...)\n", originalFileName, theID, audioURL));
+
 	ensureWorkingDir();
 	ID = theID;
 	audioFileName = Glib::build_filename (basePath, ID + "-" + originalFileName);
@@ -395,11 +418,12 @@ bool Mootcher::fetchAudioFile(std::string originalFileName, std::string theID, s
 	theFile = g_fopen( (audioFileName + ".part").c_str(), "wb" );
 
 	if (!theFile) {
+		DEBUG_TRACE(PBD::DEBUG::Freesound, "Can't open file for writing:" + audioFileName + ".part\n");
 		return false;
 	}
 
 	// create the download url
-	audioURL += "?api_key=" + api_key;
+	audioURL += "?token=" + api_key;
 
 	setcUrlOptions();
 	curl_easy_setopt(curl, CURLOPT_URL, audioURL.c_str() );
diff --git a/gtk2_ardour/sfdb_freesound_mootcher.h b/gtk2_ardour/sfdb_freesound_mootcher.h
index 4095cc9..6dfad6c 100644
--- a/gtk2_ardour/sfdb_freesound_mootcher.h
+++ b/gtk2_ardour/sfdb_freesound_mootcher.h
@@ -66,7 +66,7 @@ enum sortMethod {
 class Mootcher: public sigc::trackable, public PBD::ScopedConnectionList
 {
 public:
-	Mootcher();
+	Mootcher(const std::string &api_key = "");
 	~Mootcher();
 
 	bool		checkAudioFile(std::string originalFileName, std::string ID);
@@ -118,5 +118,6 @@ private:
 
 	std::string basePath;
 	std::string xmlLocation;
+	std::string api_key;
 };
 
diff --git a/gtk2_ardour/sfdb_ui.cc b/gtk2_ardour/sfdb_ui.cc
index 4c96172..c61efe0 100644
--- a/gtk2_ardour/sfdb_ui.cc
+++ b/gtk2_ardour/sfdb_ui.cc
@@ -1094,7 +1094,7 @@ SoundFileBrowser::freesound_search()
 #ifdef GTKOSX
 			"", // OSX eats anything incl mp3
 #else
-			"type:wav OR type:aiff OR type:flac OR type:aif OR type:ogg OR type:oga",
+			"type:(wav OR aiff OR flac OR aif OR ogg OR oga)",
 #endif
 			sort_method
 			);
@@ -1114,14 +1114,14 @@ SoundFileBrowser::handle_freesound_results(std::string theString) {
 		return;
 	}
 
-	if ( strcmp(root->name().c_str(), "response") != 0) {
-		error << string_compose ("root node name == %1 != \"response\"", root->name()) << endmsg;
+	if ( strcmp(root->name().c_str(), "root") != 0) {
+		error << string_compose ("root node name == %1 != \"root\"", root->name()) << endmsg;
 		return;
 	}
 
 	// find out how many pages are available to search
 	int freesound_n_pages = 1;
-	XMLNode *res = root->child("num_pages");
+	XMLNode *res = root->child("count");
 	if (res) {
 		string result = res->child("text")->content();
 		freesound_n_pages = atoi(result);
@@ -1140,9 +1140,9 @@ SoundFileBrowser::handle_freesound_results(std::string theString) {
 		freesound_more_btn.set_tooltip_text(_("No more results available"));
 	}
 
-	XMLNode *sounds_root = root->child("sounds");
+	XMLNode *sounds_root = root->child("results");
 	if (!sounds_root) {
-		error << "no child node \"sounds\" found!" << endmsg;
+		error << "no child node \"results\" found!" << endmsg;
 		return;
 	}
 
@@ -1156,8 +1156,8 @@ SoundFileBrowser::handle_freesound_results(std::string theString) {
 	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;
+		if( strcmp( node->name().c_str(), "list-item") != 0 ) {
+			error << string_compose ("node->name()=%1 != \"list-item\"", node->name()) << endmsg;
 			break;
 		}
 
@@ -1165,8 +1165,8 @@ SoundFileBrowser::handle_freesound_results(std::string theString) {
 
 
 		XMLNode *id_node  = node->child ("id");
-		XMLNode *uri_node = node->child ("serve");
-		XMLNode *ofn_node = node->child ("original_filename");
+		XMLNode *uri_node = node->child ("download");
+		XMLNode *ofn_node = node->child ("name");
 		XMLNode *dur_node = node->child ("duration");
 		XMLNode *siz_node = node->child ("filesize");
 		XMLNode *srt_node = node->child ("samplerate");
@@ -1238,6 +1238,8 @@ SoundFileBrowser::handle_freesound_results(std::string theString) {
 			row[freesound_list_columns.smplrate] = srt;
 			row[freesound_list_columns.license ] = shortlicense;
 			matches++;
+		} else {
+			error << _("Failed to retrieve XML for file") << std::endl;
 		}
 	}
 }
-- 
2.7.0.rc3

colinf

2016-01-19 12:05

updater  

0003-Freesound-abuse-previews-to-get-some-kind-of-downloa.patch (6,032 bytes)   
From 15f0421dfe75e1e7ac289ced1a024b02cdad248d Mon Sep 17 00:00:00 2001
From: Colin Fletcher <colin.m.fletcher@googlemail.com>
Date: Tue, 19 Jan 2016 01:25:36 +0000
Subject: [PATCH 3/4] Freesound: abuse previews to get some kind of download
 working

The full file download requires OAuth, which I don't have the time or
knowledge to implement just now, but downloading the high quality OGG
preview can be done with just the token authentication.

Also a load more debugging output.
---
 gtk2_ardour/sfdb_freesound_mootcher.cc | 25 ++++++++++++++++---------
 gtk2_ardour/sfdb_ui.cc                 | 11 +++++++++--
 2 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/gtk2_ardour/sfdb_freesound_mootcher.cc b/gtk2_ardour/sfdb_freesound_mootcher.cc
index 3a24958..d3bdc26 100644
--- a/gtk2_ardour/sfdb_freesound_mootcher.cc
+++ b/gtk2_ardour/sfdb_freesound_mootcher.cc
@@ -61,10 +61,12 @@
 using namespace PBD;
 
 static const std::string base_url = "http://www.freesound.org/apiv2";
-static const std::string default_api_key = "b2cc51878bd4fde055e3e84591eb289715d01503"; // Ardour 4
-// Ardour 4 	c7eff9328525c51775cb 	b2cc51878bd4fde055e3e84591eb289715d01503
 
-static const std::string fields = "id,name,duration,filesize,samplerate,license,download";
+// Ardour 4
+static const std::string default_api_key = "b2cc51878bd4fde055e3e84591eb289715d01503";
+static const std::string client_id = "c7eff9328525c51775cb";
+
+static const std::string fields = "id,name,duration,filesize,samplerate,license,download,previews";
 
 //------------------------------------------------------------------------
 Mootcher::Mootcher(const std::string &the_api_key)
@@ -195,7 +197,7 @@ std::string Mootcher::doRequest(std::string uri, std::string params)
 
 	curl_easy_setopt(curl, CURLOPT_URL, url.c_str() );
 
-	DEBUG_TRACE(PBD::DEBUG::Freesound, url + "\n"); 
+	DEBUG_TRACE(PBD::DEBUG::Freesound, "doRequest() " + url + "\n");
 
 	// perform online request
 	CURLcode res = curl_easy_perform(curl);
@@ -272,6 +274,7 @@ std::string Mootcher::getSoundResourceFile(std::string ID)
 	std::string audioFileName;
 	std::string xml;
 
+	DEBUG_TRACE(PBD::DEBUG::Freesound, "getSoundResourceFile(" + ID + ")\n");
 
 	// download the xmlfile into xml_page
 	xml = doRequest("/sounds/" + ID + "/", "");
@@ -306,7 +309,7 @@ std::string Mootcher::getSoundResourceFile(std::string ID)
 			std::vector<std::string> strings;
 			for (niter = children.begin(); niter != children.end(); ++niter) {
 				XMLNode *node = *niter;
-				if( strcmp( node->name().c_str(), "resource") == 0 ) {
+				if( strcmp( node->name().c_str(), "list-item") == 0 ) {
 					XMLNode *text = node->child("text");
 					if (text) {
 						// std::cerr << "tag: " << text->content() << std::endl;
@@ -333,6 +336,7 @@ void *
 Mootcher::threadFunc() {
 CURLcode res;
 
+	DEBUG_TRACE(PBD::DEBUG::Freesound, "threadFunc\n");
 	res = curl_easy_perform (curl);
 	fclose (theFile);
 	curl_easy_setopt (curl, CURLOPT_NOPROGRESS, 1); // turn off the progress bar
@@ -391,13 +395,16 @@ bool Mootcher::checkAudioFile(std::string originalFileName, std::string theID)
 		fseek (testFile , 0 , SEEK_END);
 		if (ftell (testFile) > 256) {
 			fclose (testFile);
+			DEBUG_TRACE(PBD::DEBUG::Freesound, "checkAudiofile() - found " + audioFileName + "\n");
 			return true;
 		}
 
 		// else file was small, probably an error, delete it
-		fclose(testFile);
-		remove( audioFileName.c_str() );
+		DEBUG_TRACE(PBD::DEBUG::Freesound, "checkAudiofile() - " + audioFileName + " <= 256 bytes, removing it\n");
+		fclose (testFile);
+		remove (audioFileName.c_str() );
 	}
+	DEBUG_TRACE(PBD::DEBUG::Freesound, "checkAudiofile() - not found " + audioFileName + "\n");
 	return false;
 }
 
@@ -405,7 +412,7 @@ bool Mootcher::checkAudioFile(std::string originalFileName, std::string theID)
 bool Mootcher::fetchAudioFile(std::string originalFileName, std::string theID, std::string audioURL, SoundFileBrowser *caller)
 {
 
-	DEBUG_TRACE(PBD::DEBUG::Freesound, string_compose("fetchAudiofile(%1, %2, %3...)\n", originalFileName, theID, audioURL));
+	DEBUG_TRACE(PBD::DEBUG::Freesound, string_compose("fetchAudiofile(%1, %2, %3, ...)\n", originalFileName, theID, audioURL));
 
 	ensureWorkingDir();
 	ID = theID;
@@ -459,7 +466,7 @@ Mootcher::updateProgress(double dlnow, double dltotal)
 {
 	if (dltotal > 0) {
 		double fraction = dlnow / dltotal;
-		// std::cerr << "progress idle: " << progress->bar->get_text() << ". " << progress->dlnow << " / " << progress->dltotal << " = " << fraction << std::endl;
+		// std::cerr << "progress idle: " << progress_bar.get_text() << ". " << dlnow << " / " << dltotal << " = " << fraction << std::endl;
 		if (fraction > 1.0) {
 			fraction = 1.0;
 		} else if (fraction < 0.0) {
diff --git a/gtk2_ardour/sfdb_ui.cc b/gtk2_ardour/sfdb_ui.cc
index c61efe0..64e8130 100644
--- a/gtk2_ardour/sfdb_ui.cc
+++ b/gtk2_ardour/sfdb_ui.cc
@@ -1166,16 +1166,23 @@ SoundFileBrowser::handle_freesound_results(std::string theString) {
 
 		XMLNode *id_node  = node->child ("id");
 		XMLNode *uri_node = node->child ("download");
+		XMLNode *pre_node = node->child ("previews");
+		XMLNode *ogg_node;
+		if (pre_node) {
+			ogg_node = pre_node->child ("preview-hq-ogg");
+		} else {
+			ogg_node = uri_node;
+		}
 		XMLNode *ofn_node = node->child ("name");
 		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) {
+		if (id_node && ogg_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 uri = ogg_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();
-- 
2.7.0.rc3

colinf

2016-01-19 12:05

updater  

0004-Freesound-s-api_key-token-g.patch (3,110 bytes)   
From de902fb75c4573527ff86d8e6c6c155628efe94b Mon Sep 17 00:00:00 2001
From: Colin Fletcher <colin.m.fletcher@googlemail.com>
Date: Tue, 19 Jan 2016 11:31:54 +0000
Subject: [PATCH 4/4] Freesound: s/api_key/token/g

What used to be called an 'api_key' in the old Freesound API is now called
a token: renmae variables for consistency.
---
 gtk2_ardour/sfdb_freesound_mootcher.cc | 16 ++++++++--------
 gtk2_ardour/sfdb_freesound_mootcher.h  |  4 ++--
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/gtk2_ardour/sfdb_freesound_mootcher.cc b/gtk2_ardour/sfdb_freesound_mootcher.cc
index d3bdc26..1542bba 100644
--- a/gtk2_ardour/sfdb_freesound_mootcher.cc
+++ b/gtk2_ardour/sfdb_freesound_mootcher.cc
@@ -63,20 +63,20 @@ using namespace PBD;
 static const std::string base_url = "http://www.freesound.org/apiv2";
 
 // Ardour 4
-static const std::string default_api_key = "b2cc51878bd4fde055e3e84591eb289715d01503";
+static const std::string default_token = "b2cc51878bd4fde055e3e84591eb289715d01503";
 static const std::string client_id = "c7eff9328525c51775cb";
 
 static const std::string fields = "id,name,duration,filesize,samplerate,license,download,previews";
 
 //------------------------------------------------------------------------
-Mootcher::Mootcher(const std::string &the_api_key)
+Mootcher::Mootcher(const std::string &the_token)
 	: curl(curl_easy_init())
 {
 	DEBUG_TRACE(PBD::DEBUG::Freesound, "Created new Mootcher\n");
-	if  (the_api_key != "") {
-		api_key = the_api_key;
+	if  (the_token != "") {
+		token = the_token;
 	} else {
-		api_key = default_api_key;
+		token = default_token;
 	}
 	cancel_download_btn.set_label (_("Cancel"));
 	progress_hbox.pack_start (progress_bar, true, true);
@@ -190,9 +190,9 @@ std::string Mootcher::doRequest(std::string uri, std::string params)
 	// the url to get
 	std::string url = base_url + uri + "?";
 	if (params != "") {
-		url += params + "&token=" + api_key + "&format=xml";
+		url += params + "&token=" + token + "&format=xml";
 	} else {
-		url += "token=" + api_key + "&format=xml";
+		url += "token=" + token + "&format=xml";
 	}
 
 	curl_easy_setopt(curl, CURLOPT_URL, url.c_str() );
@@ -430,7 +430,7 @@ bool Mootcher::fetchAudioFile(std::string originalFileName, std::string theID, s
 	}
 
 	// create the download url
-	audioURL += "?token=" + api_key;
+	audioURL += "?token=" + token;
 
 	setcUrlOptions();
 	curl_easy_setopt(curl, CURLOPT_URL, audioURL.c_str() );
diff --git a/gtk2_ardour/sfdb_freesound_mootcher.h b/gtk2_ardour/sfdb_freesound_mootcher.h
index 6dfad6c..27cf793 100644
--- a/gtk2_ardour/sfdb_freesound_mootcher.h
+++ b/gtk2_ardour/sfdb_freesound_mootcher.h
@@ -66,7 +66,7 @@ enum sortMethod {
 class Mootcher: public sigc::trackable, public PBD::ScopedConnectionList
 {
 public:
-	Mootcher(const std::string &api_key = "");
+	Mootcher(const std::string &token = "");
 	~Mootcher();
 
 	bool		checkAudioFile(std::string originalFileName, std::string ID);
@@ -118,6 +118,6 @@ private:
 
 	std::string basePath;
 	std::string xmlLocation;
-	std::string api_key;
+	std::string token;
 };
 
-- 
2.7.0.rc3

colinf

2016-02-13 23:14

updater   ~0017929

Utterly hacky but basically working implementation now pushed to freesound-apiv2 branch.

The concept may well be too ugly to live; even if it's not deemed totally unacceptable there's a lot of tidying still to be done there, but I hope it's at least a starting point.

timbyr

2016-02-15 12:55

developer   ~0017937

I pulled and tested the freesound-apiv2 branch and it seems to work OK.

I haven't got any comments about code as yet but one small detail would be to set the focus on the "OK" button in the CredentialsDialog(or whatever you called it) and also that authorization occasionally seems to take some time(I noticed perhaps 15 seconds) so it may be worth having a progress bar.

Perhaps a progress bar could be added to the credentials dialog if that doesn't look too weird as that will also allow access to the Cancel button.

If I input the incorrect username and password there is no indication of failure and it appears that it will just play the last file that successfully downloaded.

colinf

2016-02-15 13:52

updater   ~0017942

Last edited: 2016-02-15 18:10

timbyr: thanks for testing!

Yes, the CredentialsDialog (can you think of a better name? I almost called it LoginDialog) really ought to have the <Enter> key act as 'OK'. I shall make it so. [EDIT] Done.

A progress bar is a nice idea. I'm not sure that it should be part of the credentials dialogue: I have a feeling it might be a bit weird that 'OK' doesn't dismiss the dialogue immediately, but I suppose if it gave you the chance to re-enter a mistyped user name or password it might make some sense.

And yes, it really ought to report login failures somehow. I'm not sure what the best way to proceed in that case would be either: I had an idea that we could just download the .OGG preview file if the user doesn't provide valid freesound login details, but I'd like to know what others think of that.

timbyr

2016-02-15 21:21

developer   ~0017943

Last edited: 2016-02-15 22:38

Yes, I agree about the progress bar, it doesn't seem appropriate. Some sort of indication like setting the wait cursor would be good eventually but considering there are other long operations in Ardour that don't do this it probably isn't much of a concern at this point.

colinf

2016-02-20 13:58

updater   ~0017976

Login progress now appears (as text) in the file download progress bar: this also allows the user to cancel the login.

timbyr

2016-02-24 02:18

developer   ~0018003

I just re-tested the latest changes.

I think the login status in progress bar works well but I still think some sort of dialog or something is needed on failure.

The other main issue I noticed is that double clicking on a file will start it downloading, but it will also play the previously downloaded file immediately which is quite confusing.

How hard would it be to have a "use low quality preview" option? As I think it may provide a faster workflow with the reduced download time. I find myself previewing many files but only importing a few of them into the session.

I'm not sure how that would tie into "only download preview on login failure" but personally I don't think it is a good idea to allow importing of low quality preview files.

colinf

2016-02-24 14:23

updater   ~0018009

I agree that we need better login failure reporting: I'm not sure a dialogue is the right thing, because it's quite possible to click 'OK' in the credentials dialogue and then carry on with something else while waiting for the login to complete, so popping up an error dialogue might interrupt that, or alternatively be missed. Would putting an error into the 'Log' window be too obscure?

Good point about the double-click, too: I guess it needs to be handled differently in the freesound list view from the other file lists, since in the other tabs the clicked file is available immediately for preview.

I like the idea of just downloading the preview on clicking the file, and only downloading the original full-quality file on request. The best way I can think of at the moment for this would be be an extra column in the file list with a tick box to mark which files are to be downloaded, and then either to download them on clicking 'Import', or via a new 'Download chosen files now' button.

turion

2016-12-02 20:16

reporter   ~0019104

Is there anything besides C++/C-coding that I can do to make this issue progress further? (Right now I'm basically stalled on my music project because there is no freesound.org import.) I'd be happy to test or debug or give/discuss UI ideas.

colinf

2022-05-20 13:43

updater   ~0026448

Done in 9fe0a4f4.

x42

2022-05-20 22:25

administrator   ~0026452

Implemented in 7.0-pre0-2782-g9fe0a4f4dd Thanks to @colinf

Issue History

Date Modified Username Field Change
2015-03-10 00:11 x42 New Issue
2015-07-31 13:33 colinf Relationship added related to 0006493
2016-01-19 01:10 colinf Note Added: 0017809
2016-01-19 12:02 colinf Note Added: 0017810
2016-01-19 12:04 colinf File Added: 0001-New-DebugBit-for-Freesound.patch
2016-01-19 12:05 colinf File Added: 0002-Update-to-Freesound-API-v2-search-only.patch
2016-01-19 12:05 colinf File Added: 0003-Freesound-abuse-previews-to-get-some-kind-of-downloa.patch
2016-01-19 12:05 colinf File Added: 0004-Freesound-s-api_key-token-g.patch
2016-02-13 23:14 colinf Note Added: 0017929
2016-02-15 12:55 timbyr Note Added: 0017937
2016-02-15 13:52 colinf Note Added: 0017942
2016-02-15 18:10 colinf Note Edited: 0017942
2016-02-15 21:21 timbyr Note Added: 0017943
2016-02-15 22:38 timbyr Note Edited: 0017943
2016-02-20 13:58 colinf Note Added: 0017976
2016-02-24 02:18 timbyr Note Added: 0018003
2016-02-24 14:23 colinf Note Added: 0018009
2016-12-02 20:16 turion Note Added: 0019104
2022-05-20 13:43 colinf Note Added: 0026448
2022-05-20 22:25 x42 Assigned To => x42
2022-05-20 22:25 x42 Status new => resolved
2022-05-20 22:25 x42 Resolution open => fixed
2022-05-20 22:25 x42 Note Added: 0026452