2014-05-21 13:07:31 -04:00
|
|
|
/* sfdb_freesound_mootcher.cpp **********************************************************************
|
|
|
|
|
|
|
|
Adapted for Ardour by Ben Loftis, March 2008
|
|
|
|
Updated to new Freesound API by Colin Fletcher, November 2011
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
Updated to Freesound API v2 by Colin Fletcher, May 2022
|
2014-05-21 13:07:31 -04:00
|
|
|
|
|
|
|
Mootcher 23-8-2005
|
|
|
|
|
|
|
|
Mootcher Online Access to thefreesoundproject website
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
http://freesound.org/
|
2014-05-21 13:07:31 -04:00
|
|
|
|
|
|
|
GPL 2005 Jorn Lemon
|
|
|
|
mail for questions/remarks: mootcher@twistedlemon.nl
|
|
|
|
or go to the freesound website forum
|
|
|
|
|
|
|
|
-----------------------------------------------------------------
|
|
|
|
|
|
|
|
Includes:
|
|
|
|
curl.h (version 7.14.0)
|
Fix various typos
Found via `codespell -q 3 -S *.po,./share/patchfiles,./libs -L ba,buss,busses,doubleclick,hsi,ontop,ro,seh,siz,sord,sur,te,trough,ue`
Follow-up to 364f2f078
2022-04-07 09:09:04 -04:00
|
|
|
Libraries:
|
2014-05-21 13:07:31 -04:00
|
|
|
libcurl.lib
|
|
|
|
|
|
|
|
-----------------------------------------------------------------
|
2022-10-17 09:56:50 -04:00
|
|
|
License GPL:
|
2014-05-21 13:07:31 -04:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
*************************************************************************************/
|
|
|
|
|
2022-05-20 15:41:29 -04:00
|
|
|
#include <iostream>
|
2014-05-21 13:07:31 -04:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <glib.h>
|
2015-10-05 16:10:58 -04:00
|
|
|
#include "pbd/gstdio_compat.h"
|
2014-05-21 13:07:31 -04:00
|
|
|
|
2022-05-20 15:41:29 -04:00
|
|
|
#include "pbd/error.h"
|
|
|
|
#include "pbd/pthread_utils.h"
|
|
|
|
#include "pbd/openuri.h"
|
|
|
|
#include "pbd/xml++.h"
|
2014-05-21 13:07:31 -04:00
|
|
|
|
|
|
|
#include "ardour/audio_library.h"
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
#include "ardour/debug.h"
|
|
|
|
#include "ardour/filesystem_paths.h"
|
2022-05-20 15:41:29 -04:00
|
|
|
|
|
|
|
#include "widgets/prompter.h"
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
|
|
|
|
#include "ardour_dialog.h"
|
2022-05-20 15:42:37 -04:00
|
|
|
#include "ardour_http.h"
|
2022-05-20 15:41:29 -04:00
|
|
|
#include "sfdb_freesound_mootcher.h"
|
2014-05-21 13:07:31 -04:00
|
|
|
#include "gui_thread.h"
|
2022-05-20 15:41:29 -04:00
|
|
|
#include "ui_config.h"
|
|
|
|
|
|
|
|
#include "pbd/i18n.h"
|
2014-05-21 13:07:31 -04:00
|
|
|
|
|
|
|
using namespace PBD;
|
|
|
|
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
// freesound API URLs are always https://, and don't include the www. subdomain
|
|
|
|
static const std::string base_url = "https://freesound.org/apiv2";
|
|
|
|
|
|
|
|
// Ardour 7
|
|
|
|
static const std::string default_token = "t3TjQ67WNh6zJLZRnWmArSiZ8bKlgTc2aEsV1cP7";
|
|
|
|
static const std::string client_id = "yesyr1g4StTtg2F50KT1";
|
|
|
|
|
|
|
|
static const std::string fields = "id,name,duration,filesize,samplerate,license,download,previews";
|
2014-05-21 13:07:31 -04:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
Mootcher::Mootcher(const std::string &the_token)
|
2014-05-21 13:07:31 -04:00
|
|
|
: curl(curl_easy_init())
|
|
|
|
{
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, "Created new Mootcher, oauth_token =\"" + the_token + "\"\n");
|
|
|
|
custom_headers = NULL;
|
|
|
|
oauth_token = the_token;
|
|
|
|
|
2014-05-21 13:07:31 -04:00
|
|
|
cancel_download_btn.set_label (_("Cancel"));
|
|
|
|
progress_hbox.pack_start (progress_bar, true, true);
|
|
|
|
progress_hbox.pack_end (cancel_download_btn, false, false);
|
|
|
|
progress_bar.show();
|
|
|
|
cancel_download_btn.show();
|
|
|
|
cancel_download_btn.signal_clicked().connect(sigc::mem_fun (*this, &Mootcher::cancelDownload));
|
|
|
|
};
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
Mootcher:: ~Mootcher()
|
|
|
|
{
|
|
|
|
curl_easy_cleanup(curl);
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
if (custom_headers) {
|
|
|
|
curl_slist_free_all (custom_headers);
|
|
|
|
}
|
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, "Destroyed Mootcher\n");
|
2014-05-21 13:07:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void Mootcher::ensureWorkingDir ()
|
|
|
|
{
|
2022-05-20 16:02:26 -04:00
|
|
|
std::string const& p = UIConfiguration::instance ().get_freesound_dir ();
|
2014-05-21 13:07:31 -04:00
|
|
|
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, "ensureWorkingDir() - " + p + "\n");
|
2014-05-21 13:07:31 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
basePath = p;
|
|
|
|
#ifdef PLATFORM_WINDOWS
|
|
|
|
std::string replace = "/";
|
|
|
|
size_t pos = basePath.find("\\");
|
|
|
|
while( pos != std::string::npos ){
|
|
|
|
basePath.replace(pos, 1, replace);
|
|
|
|
pos = basePath.find("\\");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-05-21 13:07:31 -04:00
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
size_t Mootcher::WriteMemoryCallback(void *ptr, size_t size, size_t nmemb, void *data)
|
|
|
|
{
|
2014-12-27 14:03:36 -05:00
|
|
|
int realsize = (int)(size * nmemb);
|
2016-09-13 00:24:28 -04:00
|
|
|
struct SfdbMemoryStruct *mem = (struct SfdbMemoryStruct *)data;
|
2014-05-21 13:07:31 -04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
|
|
|
|
std::string Mootcher::sortMethodString(enum sortMethod sort)
|
|
|
|
{
|
|
|
|
// given a sort type, returns the string value to be passed to the API to
|
|
|
|
// sort the results in the requested way.
|
|
|
|
|
|
|
|
switch (sort) {
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
case sort_duration_descending: return "duration_desc";
|
|
|
|
case sort_duration_ascending: return "duration_asc";
|
|
|
|
case sort_created_descending: return "created_desc";
|
|
|
|
case sort_created_ascending: return "created_asc";
|
|
|
|
case sort_downloads_descending: return "downloads_desc";
|
|
|
|
case sort_downloads_ascending: return "downloads_asc";
|
|
|
|
case sort_rating_descending: return "rating_desc";
|
|
|
|
case sort_rating_ascending: return "rating_asc";
|
|
|
|
default: return "";
|
2014-05-21 13:07:31 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
void Mootcher::setcUrlOptions()
|
|
|
|
{
|
|
|
|
// some servers don't like requests that are made without a user-agent field, so we provide one
|
|
|
|
curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");
|
|
|
|
// setup curl error buffer
|
|
|
|
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer);
|
|
|
|
// Allow redirection
|
|
|
|
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-05-21 13:07:31 -04:00
|
|
|
// Allow connections to time out (without using signals)
|
|
|
|
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 30);
|
2022-05-20 15:42:37 -04:00
|
|
|
|
|
|
|
/* set ca-certificates to use for bundled versions of ardour */
|
|
|
|
ArdourCurl::HttpGet::ca_setopt (curl);
|
2014-05-21 13:07:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string Mootcher::doRequest(std::string uri, std::string params)
|
|
|
|
{
|
|
|
|
std::string result;
|
2016-09-13 00:24:28 -04:00
|
|
|
struct SfdbMemoryStruct xml_page;
|
2014-05-21 13:07:31 -04:00
|
|
|
xml_page.memory = NULL;
|
|
|
|
xml_page.size = 0;
|
|
|
|
|
|
|
|
setcUrlOptions();
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) &xml_page);
|
|
|
|
|
|
|
|
// the url to get
|
|
|
|
std::string url = base_url + uri + "?";
|
|
|
|
if (params != "") {
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
url += params + "&token=" + default_token + "&format=xml";
|
2014-05-21 13:07:31 -04:00
|
|
|
} else {
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
url += "token=" + default_token + "&format=xml";
|
2014-05-21 13:07:31 -04:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-05-21 13:07:31 -04:00
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, url.c_str() );
|
2015-10-05 10:17:49 -04:00
|
|
|
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, "doRequest() " + url + "\n");
|
|
|
|
|
2014-05-21 13:07:31 -04:00
|
|
|
// perform online request
|
|
|
|
CURLcode res = curl_easy_perform(curl);
|
|
|
|
if( res != 0 ) {
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
std::string errmsg = string_compose (_("curl error %1 (%2)"), res, curl_easy_strerror(res));
|
|
|
|
error << errmsg << endmsg;
|
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, errmsg + "\n");
|
2014-05-21 13:07:31 -04:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
// free the memory
|
|
|
|
if (xml_page.memory) {
|
|
|
|
result = xml_page.memory;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-05-21 13:07:31 -04:00
|
|
|
free (xml_page.memory);
|
|
|
|
xml_page.memory = NULL;
|
|
|
|
xml_page.size = 0;
|
|
|
|
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, result + "\n");
|
2014-05-21 13:07:31 -04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string Mootcher::searchSimilar(std::string id)
|
|
|
|
{
|
|
|
|
std::string params = "";
|
|
|
|
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
params += "&fields=" + fields;
|
2014-05-21 13:07:31 -04:00
|
|
|
params += "&num_results=100";
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
// XXX should we filter out MP3s here, too?
|
|
|
|
// XXX and what if there are more than 100 similar sounds?
|
2014-05-21 13:07:31 -04:00
|
|
|
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
return doRequest("/sounds/" + id + "/similar/", params);
|
2014-05-21 13:07:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
Mootcher::report_login_error(const std::string &msg)
|
|
|
|
{
|
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, "Login failed:" + msg + "\n");
|
|
|
|
error << "Freesound login failed: " << msg << endmsg;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Mootcher::get_oauth_token()
|
|
|
|
{
|
|
|
|
std::string oauth_url = base_url + "/oauth2/authorize/?client_id="+client_id+"&response_type=code&state=hello";
|
|
|
|
std::string auth_code;
|
|
|
|
|
|
|
|
/* use the user's default browser to get an authorization token */
|
|
|
|
if (!PBD::open_uri (oauth_url)) {
|
|
|
|
report_login_error ("cannot open " + oauth_url);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
ArdourWidgets::Prompter token_entry(true);
|
|
|
|
token_entry.set_prompt(_("Please log in to Freesound in the browser window that's just been opened, and paste the authorization code here"));
|
|
|
|
token_entry.set_title(_("Authorization Code"));
|
2022-11-02 11:19:05 -04:00
|
|
|
token_entry.set_keep_above (true);
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
|
|
|
|
token_entry.set_name ("TokenEntryWindow");
|
|
|
|
// token_entry.set_size_request (250, -1);
|
|
|
|
token_entry.set_position (Gtk::WIN_POS_MOUSE);
|
2022-11-02 11:19:05 -04:00
|
|
|
token_entry.set_position (Gtk::WIN_POS_MOUSE);
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
token_entry.add_button (Gtk::Stock::OK, Gtk::RESPONSE_ACCEPT);
|
|
|
|
token_entry.show ();
|
|
|
|
|
|
|
|
if (token_entry.run () != Gtk::RESPONSE_ACCEPT)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
token_entry.get_result(auth_code);
|
|
|
|
if (auth_code == "")
|
|
|
|
return false;
|
|
|
|
|
|
|
|
oauth_token = auth_code_to_oauth_token(auth_code);
|
|
|
|
setcUrlOptions();
|
|
|
|
|
|
|
|
return oauth_token != "";;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string Mootcher::auth_code_to_oauth_token(const std::string &auth_code)
|
|
|
|
{
|
|
|
|
struct SfdbMemoryStruct json_page;
|
|
|
|
json_page.memory = NULL;
|
|
|
|
json_page.size = 0;
|
|
|
|
CURLcode res;
|
|
|
|
|
|
|
|
setcUrlOptions();
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *) &json_page);
|
|
|
|
|
|
|
|
std::string oauth_url = base_url + "/oauth2/access_token/";
|
|
|
|
std::string new_oauth_token;
|
|
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, oauth_url.c_str());
|
|
|
|
curl_easy_setopt(curl, CURLOPT_POST, 5);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_COPYPOSTFIELDS,
|
|
|
|
("client_id=" + client_id +
|
|
|
|
"&client_secret=" + default_token +
|
|
|
|
"&grant_type=authorization_code" +
|
|
|
|
"&code=" + auth_code).c_str());
|
|
|
|
|
|
|
|
progress_bar.set_text(_("Fetching Access Token (auth_code=") + auth_code + "...");
|
|
|
|
while (gtk_events_pending()) gtk_main_iteration (); // allow the progress bar text to update
|
|
|
|
|
|
|
|
res = curl_easy_perform (curl);
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
if (res != CURLE_ABORTED_BY_CALLBACK) {
|
|
|
|
report_login_error (string_compose ("curl failed: %1, error=%2", oauth_url, res));
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!json_page.memory) {
|
|
|
|
report_login_error (string_compose ("curl returned nothing, url=%1!", oauth_url));
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string access_token_json_str = json_page.memory;
|
|
|
|
free (json_page.memory);
|
|
|
|
json_page.memory = NULL;
|
|
|
|
json_page.size = 0;
|
|
|
|
|
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, access_token_json_str);
|
|
|
|
|
|
|
|
// one of these days ardour's gonna need a proper JSON parser...
|
|
|
|
size_t token_pos = access_token_json_str.find ("access_token");
|
|
|
|
oauth_token = access_token_json_str.substr (token_pos + 16, 30);
|
|
|
|
|
|
|
|
// we've set a bunch of curl options - reset the important ones now
|
|
|
|
curl_easy_setopt(curl, CURLOPT_POST, 0);
|
|
|
|
|
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, "oauth_token is :" + oauth_token + "\n");
|
|
|
|
return oauth_token;
|
|
|
|
}
|
|
|
|
|
2014-05-21 13:07:31 -04:00
|
|
|
std::string Mootcher::searchText(std::string query, int page, std::string filter, enum sortMethod sort)
|
|
|
|
{
|
|
|
|
std::string params = "";
|
|
|
|
char buf[24];
|
|
|
|
|
|
|
|
if (page > 1) {
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
snprintf(buf, 23, "page=%d&", page);
|
2014-05-21 13:07:31 -04:00
|
|
|
params += buf;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *eq = curl_easy_escape(curl, query.c_str(), query.length());
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
params += "query=\"" + std::string(eq) + "\"";
|
|
|
|
curl_free(eq);
|
2014-05-21 13:07:31 -04:00
|
|
|
|
|
|
|
if (filter != "") {
|
|
|
|
char *ef = curl_easy_escape(curl, filter.c_str(), filter.length());
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
params += "&filter=" + std::string(ef);
|
|
|
|
curl_free(ef);
|
2014-05-21 13:07:31 -04:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-05-21 13:07:31 -04:00
|
|
|
if (sort)
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
params += "&sort=" + sortMethodString(sort);
|
2014-05-21 13:07:31 -04:00
|
|
|
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
params += "&fields=" + fields;
|
|
|
|
params += "&page_size=100";
|
2014-05-21 13:07:31 -04:00
|
|
|
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
return doRequest("/search/text/", params);
|
2014-05-21 13:07:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
|
|
|
|
std::string Mootcher::getSoundResourceFile(std::string ID)
|
|
|
|
{
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
/* get the resource file for the sound with given ID.
|
|
|
|
* return the file name of the sound
|
|
|
|
*/
|
2014-05-21 13:07:31 -04:00
|
|
|
std::string originalSoundURI;
|
|
|
|
std::string audioFileName;
|
|
|
|
std::string xml;
|
|
|
|
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, "getSoundResourceFile(" + ID + ")\n");
|
2014-05-21 13:07:31 -04:00
|
|
|
|
|
|
|
// download the xmlfile into xml_page
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
xml = doRequest("/sounds/" + ID + "/", "");
|
2014-05-21 13:07:31 -04:00
|
|
|
|
|
|
|
XMLTree doc;
|
|
|
|
doc.read_buffer( xml.c_str() );
|
|
|
|
XMLNode *freesound = doc.root();
|
|
|
|
|
|
|
|
// if the page is not a valid xml document with a 'freesound' root
|
|
|
|
if (freesound == NULL) {
|
|
|
|
error << _("getSoundResourceFile: There is no valid root in the xml file") << endmsg;
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
if (strcmp(doc.root()->name().c_str(), "root") != 0) {
|
|
|
|
error << string_compose (_("getSoundResourceFile: root = %1, != \"root\""), doc.root()->name()) << endmsg;
|
2014-05-21 13:07:31 -04:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
XMLNode *name = freesound->child("name");
|
2014-05-21 13:07:31 -04:00
|
|
|
|
|
|
|
// get the file name and size from xml file
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
// assert (name);
|
2014-05-21 13:07:31 -04:00
|
|
|
if (name) {
|
|
|
|
|
|
|
|
audioFileName = Glib::build_filename (basePath, ID + "-" + name->child("text")->content());
|
|
|
|
|
|
|
|
//store all the tags in the database
|
|
|
|
XMLNode *tags = freesound->child("tags");
|
|
|
|
if (tags) {
|
|
|
|
XMLNodeList children = tags->children();
|
|
|
|
XMLNodeConstIterator niter;
|
|
|
|
std::vector<std::string> strings;
|
|
|
|
for (niter = children.begin(); niter != children.end(); ++niter) {
|
|
|
|
XMLNode *node = *niter;
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
if( strcmp( node->name().c_str(), "list-item") == 0 ) {
|
2014-05-21 13:07:31 -04:00
|
|
|
XMLNode *text = node->child("text");
|
|
|
|
if (text) {
|
|
|
|
// std::cerr << "tag: " << text->content() << std::endl;
|
|
|
|
strings.push_back(text->content());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ARDOUR::Library->set_tags (std::string("//")+audioFileName, strings);
|
|
|
|
ARDOUR::Library->save_changes ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return audioFileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
int audioFileWrite(void *buffer, size_t size, size_t nmemb, void *file)
|
|
|
|
{
|
|
|
|
return (int)fwrite(buffer, size, nmemb, (FILE*) file);
|
|
|
|
};
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void *
|
2022-06-21 23:47:04 -04:00
|
|
|
Mootcher::threadFunc()
|
|
|
|
{
|
|
|
|
CURLcode res;
|
2014-05-21 13:07:31 -04:00
|
|
|
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, "threadFunc\n");
|
2014-05-21 13:07:31 -04:00
|
|
|
res = curl_easy_perform (curl);
|
|
|
|
fclose (theFile);
|
|
|
|
curl_easy_setopt (curl, CURLOPT_NOPROGRESS, 1); // turn off the progress bar
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-05-21 13:07:31 -04:00
|
|
|
if (res != CURLE_OK) {
|
|
|
|
/* it's not an error if the user pressed the stop button */
|
|
|
|
if (res != CURLE_ABORTED_BY_CALLBACK) {
|
|
|
|
error << string_compose (_("curl error %1 (%2)"), res, curl_easy_strerror(res)) << endmsg;
|
|
|
|
}
|
2015-10-04 14:51:05 -04:00
|
|
|
remove ( (audioFileName+".part").c_str() );
|
2014-05-21 13:07:31 -04:00
|
|
|
} else {
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, string_compose("renaming %1.part to %1\n", audioFileName));
|
|
|
|
int r = rename ( (audioFileName+".part").c_str(), audioFileName.c_str() );
|
|
|
|
if (r != 0) {
|
2022-06-21 23:47:04 -04:00
|
|
|
const char * err = strerror(errno);
|
|
|
|
fatal << string_compose (_("programming error: %1\n"), string_compose (X_("freesound rename failed %1"), err));
|
2022-06-22 15:31:00 -04:00
|
|
|
abort (); /* NOTREACHED */
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
} else {
|
|
|
|
// now download the tags &c.
|
|
|
|
getSoundResourceFile(ID);
|
|
|
|
}
|
2014-05-21 13:07:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return (void *) res;
|
|
|
|
}
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-05-21 13:07:31 -04:00
|
|
|
void
|
|
|
|
Mootcher::doneWithMootcher()
|
|
|
|
{
|
2015-10-04 14:51:05 -04:00
|
|
|
// update the sound info pane if the selection in the list box is still us
|
2014-05-21 13:07:31 -04:00
|
|
|
sfb->refresh_display(ID, audioFileName);
|
|
|
|
|
|
|
|
delete this; // this should be OK to do as long as Progress and Finished signals are always received in the order in which they are emitted
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *
|
2015-10-04 14:51:05 -04:00
|
|
|
freesound_download_thread_func(void *arg)
|
|
|
|
{
|
2014-05-21 13:07:31 -04:00
|
|
|
Mootcher *thisMootcher = (Mootcher *) arg;
|
|
|
|
void *res;
|
|
|
|
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, string_compose("freesound_download_thread_func(%1)\n", arg));
|
2014-05-21 13:07:31 -04:00
|
|
|
res = thisMootcher->threadFunc();
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, string_compose("threadFunc returns %1\n", res));
|
2014-05-21 13:07:31 -04:00
|
|
|
thisMootcher->Finished(); /* EMIT SIGNAL */
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, string_compose("returning from freesound_download_thread_func()\n", res));
|
2014-05-21 13:07:31 -04:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
|
|
|
|
bool Mootcher::checkAudioFile(std::string originalFileName, std::string theID)
|
|
|
|
{
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
// return true if file already exists locally and is larger than 256
|
|
|
|
// bytes, false otherwise
|
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, string_compose("checkAudiofile(%1, %2)\n", originalFileName, theID));
|
2014-05-21 13:07:31 -04:00
|
|
|
ensureWorkingDir();
|
|
|
|
ID = theID;
|
|
|
|
audioFileName = Glib::build_filename (basePath, ID + "-" + originalFileName);
|
|
|
|
|
|
|
|
// check to see if audio file already exists
|
|
|
|
FILE *testFile = g_fopen(audioFileName.c_str(), "r");
|
2015-10-04 14:51:05 -04:00
|
|
|
if (testFile) {
|
2014-05-21 13:07:31 -04:00
|
|
|
fseek (testFile , 0 , SEEK_END);
|
|
|
|
if (ftell (testFile) > 256) {
|
|
|
|
fclose (testFile);
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, "checkAudiofile() - found " + audioFileName + "\n");
|
2014-05-21 13:07:31 -04:00
|
|
|
return true;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
// else file was small, probably an error, delete it
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, "checkAudiofile() - " + audioFileName + " <= 256 bytes, removing it\n");
|
|
|
|
fclose (testFile);
|
|
|
|
// remove (audioFileName.c_str() );
|
|
|
|
rename (audioFileName.c_str(), (audioFileName + ".bad").c_str() );
|
2014-05-21 13:07:31 -04:00
|
|
|
}
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, "checkAudiofile() - not found " + audioFileName + "\n");
|
2014-05-21 13:07:31 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
bool
|
|
|
|
Mootcher::fetchAudioFile(std::string originalFileName, std::string theID, std::string audioURL, SoundFileBrowser *caller, std::string &token)
|
2014-05-21 13:07:31 -04:00
|
|
|
{
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
|
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, string_compose("fetchAudiofile(%1, %2, %3, ...)\n", originalFileName, theID, audioURL));
|
|
|
|
|
2014-05-21 13:07:31 -04:00
|
|
|
ensureWorkingDir();
|
|
|
|
ID = theID;
|
|
|
|
audioFileName = Glib::build_filename (basePath, ID + "-" + originalFileName);
|
|
|
|
|
|
|
|
if (!curl) {
|
|
|
|
return false;
|
|
|
|
}
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
|
|
|
|
Gtk::VBox *freesound_vbox = dynamic_cast<Gtk::VBox *> (caller->notebook.get_nth_page(2));
|
|
|
|
freesound_vbox->pack_start(progress_hbox, Gtk::PACK_SHRINK);
|
|
|
|
|
|
|
|
cancel_download = false;
|
|
|
|
curl_easy_setopt (curl, CURLOPT_NOPROGRESS, 0); // turn on the progress bar
|
|
|
|
curl_easy_setopt (curl, CURLOPT_PROGRESSFUNCTION, progress_callback);
|
|
|
|
curl_easy_setopt (curl, CURLOPT_PROGRESSDATA, this);
|
|
|
|
|
|
|
|
if (oauth_token == "") {
|
|
|
|
if (!get_oauth_token()) {
|
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, "get_oauth_token() failed!\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
token = oauth_token;
|
|
|
|
|
2014-05-21 13:07:31 -04:00
|
|
|
// now download the actual file
|
|
|
|
theFile = g_fopen( (audioFileName + ".part").c_str(), "wb" );
|
|
|
|
|
|
|
|
if (!theFile) {
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, "Can't open file for writing:" + audioFileName + ".part\n");
|
2014-05-21 13:07:31 -04:00
|
|
|
return false;
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-05-21 13:07:31 -04:00
|
|
|
// create the download url
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
audioURL += "?token=" + default_token;
|
2014-05-21 13:07:31 -04:00
|
|
|
|
|
|
|
setcUrlOptions();
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
std::string auth_header = "Authorization: Bearer " + oauth_token;
|
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, "auth_header = " + auth_header + "\n");
|
|
|
|
custom_headers = curl_slist_append (custom_headers, auth_header.c_str());
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, custom_headers);
|
2014-05-21 13:07:31 -04:00
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, audioURL.c_str() );
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, audioFileWrite);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, theFile);
|
|
|
|
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
DEBUG_TRACE(PBD::DEBUG::Freesound, "Downloading audio from " + audioURL + " into " + audioFileName + ".part\n");
|
2014-05-21 13:07:31 -04:00
|
|
|
std::string prog;
|
|
|
|
prog = string_compose (_("%1"), originalFileName);
|
|
|
|
progress_bar.set_text(prog);
|
|
|
|
progress_hbox.show();
|
|
|
|
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
sfb = caller;
|
2014-05-21 13:07:31 -04:00
|
|
|
|
2024-10-18 19:51:44 -04:00
|
|
|
Progress.connect(*this, invalidator (*this), std::bind(&Mootcher::updateProgress, this, _1, _2), gui_context());
|
|
|
|
Finished.connect(*this, invalidator (*this), std::bind(&Mootcher::doneWithMootcher, this), gui_context());
|
2014-05-21 13:07:31 -04:00
|
|
|
pthread_t freesound_download_thread;
|
|
|
|
pthread_create_and_store("freesound_import", &freesound_download_thread, freesound_download_thread_func, this);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
void
|
|
|
|
Mootcher::updateProgress(double dlnow, double dltotal)
|
2014-05-21 13:07:31 -04:00
|
|
|
{
|
|
|
|
if (dltotal > 0) {
|
|
|
|
double fraction = dlnow / dltotal;
|
freesound: update to API v2
Add a new client id & token for Ardour 7, and update to Freesound's API
v2.
Implement OAuth authentication for Freesound downloads, as described at:
https://freesound.org/docs/api/authentication.html#oauth-authentication
Open the Freesound login page in the default browser, so that the user
can log in and get an authorization code, to copy-&-paste from the
browser. Exchange this authorization code for an access token, and use
it in a custom 'Authorization: Bearer $TOKEN' http header.
If logging in to Freesound to download a file fails or is cancelled,
clear the 'downloading' flag for that file in the list so that a
subsequent click on it will try to log in again.
Show login progress in download progress bar, and disable preview if
file hasn't yet been downloaded.
If a download fails for any reason (except the user cancelling it),
report an error in the Log window.
Use curl_free() for pointers returned by curl_easy_escape(), as per the
curl documentation, rather than plain free().
Also, don't use the www. sub-domain of freesound.org: although it
appears to work for most things, it returns an empty document from
https://freesound.org/apiv2/oauth2/access_token/
Remove default empty token value from Mootcher constructor, to make it
explicit when we construct a Mootcher that doesn't require
authorisation, by requiring an empty token parameter in that case.
2022-05-16 13:10:34 -04:00
|
|
|
// std::cerr << "progress idle: " << progress_bar.get_text() << ". " << dlnow << " / " << dltotal << " = " << fraction << std::endl;
|
2014-05-21 13:07:31 -04:00
|
|
|
if (fraction > 1.0) {
|
|
|
|
fraction = 1.0;
|
|
|
|
} else if (fraction < 0.0) {
|
|
|
|
fraction = 0.0;
|
|
|
|
}
|
|
|
|
progress_bar.set_fraction(fraction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
int
|
2014-05-21 13:07:31 -04:00
|
|
|
Mootcher::progress_callback(void *caller, double dltotal, double dlnow, double /*ultotal*/, double /*ulnow*/)
|
|
|
|
{
|
|
|
|
// It may seem curious to pass a pointer to an instance of an object to a static
|
|
|
|
// member function, but we can't use a normal member function as a curl progress callback,
|
|
|
|
// and we want access to some private members of Mootcher.
|
|
|
|
|
|
|
|
Mootcher *thisMootcher = (Mootcher *) caller;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-05-21 13:07:31 -04:00
|
|
|
if (thisMootcher->cancel_download) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
thisMootcher->Progress(dlnow, dltotal); /* EMIT SIGNAL */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|