2013-01-16 13:37:48 -05:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2008-2015 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2011-2012 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2013 Colin Fletcher <colin.m.fletcher@googlemail.com>
|
|
|
|
* Copyright (C) 2015-2016 Tim Mayberry <mojofunk@gmail.com>
|
|
|
|
* Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2013-01-16 13:37:48 -05:00
|
|
|
|
2013-03-15 15:59:19 -04:00
|
|
|
/*sfdb_freesound_mootcher.h****************************************************************************
|
|
|
|
|
|
|
|
Adapted for Ardour by Ben Loftis, March 2008
|
|
|
|
Updated to new Freesound API by Colin Fletcher, November 2011
|
|
|
|
|
|
|
|
Mootcher Online Access to thefreesoundproject website
|
|
|
|
http://freesound.iua.upf.edu/
|
|
|
|
|
|
|
|
GPL 2005 Jorn Lemon
|
|
|
|
mail for questions/remarks: mootcher@twistedlemon.nl
|
|
|
|
or go to the freesound website forum
|
|
|
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2015-12-07 17:08:19 -05:00
|
|
|
#ifndef __gtk_ardour_sfdb_freesound_mootcher_h__
|
|
|
|
#define __gtk_ardour_sfdb_freesound_mootcher_h__
|
|
|
|
|
2013-03-15 15:59:19 -04:00
|
|
|
#include <string>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <cstring>
|
|
|
|
#include <string>
|
|
|
|
#include <sstream>
|
|
|
|
#include <vector>
|
|
|
|
#include <gtkmm/progressbar.h>
|
|
|
|
//#include <ctime>
|
|
|
|
|
|
|
|
#include "sfdb_ui.h"
|
|
|
|
|
|
|
|
#include "curl/curl.h"
|
|
|
|
|
|
|
|
//--- struct to store XML file
|
2016-09-13 00:24:28 -04:00
|
|
|
struct SfdbMemoryStruct {
|
2013-03-15 15:59:19 -04:00
|
|
|
char *memory;
|
|
|
|
size_t size;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum sortMethod {
|
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
|
|
|
sort_none, // no sort
|
|
|
|
sort_duration_descending, // Sort by the duration of the sounds, longest sounds first.
|
|
|
|
sort_duration_ascending, // Same as above, but shortest sounds first.
|
|
|
|
sort_created_descending, // Sort by the date of when the sound was added. newest sounds first.
|
|
|
|
sort_created_ascending, // Same as above, but oldest sounds first.
|
|
|
|
sort_downloads_descending, // Sort by the number of downloads, most downloaded sounds first.
|
|
|
|
sort_downloads_ascending, // Same as above, but least downloaded sounds first.
|
|
|
|
sort_rating_descending, // Sort by the average rating given to the sounds, highest rated first.
|
|
|
|
sort_rating_ascending // Same as above, but lowest rated sounds first.
|
2013-03-15 15:59:19 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-06-16 10:43:43 -04:00
|
|
|
class Mootcher: public sigc::trackable, public PBD::ScopedConnectionList
|
2013-03-15 15:59:19 -04:00
|
|
|
{
|
|
|
|
public:
|
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(const std::string &token);
|
2013-03-15 15:59:19 -04:00
|
|
|
~Mootcher();
|
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
bool checkAudioFile(std::string originalFileName, 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
|
|
|
bool fetchAudioFile(std::string originalFileName, std::string ID, std::string audioURL, SoundFileBrowser *caller, std::string &token);
|
2019-04-13 11:48:27 -04:00
|
|
|
std::string searchText(std::string query, int page, std::string filter, enum sortMethod sort);
|
|
|
|
std::string searchSimilar(std::string id);
|
|
|
|
void* threadFunc();
|
2015-10-04 14:51:05 -04:00
|
|
|
SoundFileBrowser *sfb;
|
2019-04-13 11:48:27 -04:00
|
|
|
std::string audioFileName;
|
|
|
|
std::string ID;
|
2013-03-15 15:59:19 -04:00
|
|
|
|
2013-06-16 10:43:43 -04:00
|
|
|
/** signal emitted when mootcher reports progress updates during download.
|
|
|
|
* The parameters are current and total numbers of bytes downloaded.
|
|
|
|
*/
|
|
|
|
PBD::Signal2<void, double, double> Progress;
|
|
|
|
/** signal emitted when the mootcher has finished downloading. */
|
|
|
|
PBD::Signal0<void> Finished;
|
|
|
|
|
|
|
|
|
2013-03-15 15:59:19 -04:00
|
|
|
private:
|
2019-04-13 11:48:27 -04:00
|
|
|
void ensureWorkingDir ();
|
2013-03-15 15:59:19 -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
|
|
|
bool get_oauth_token();
|
|
|
|
std::string auth_code_to_oauth_token(const std::string &auth_code);
|
|
|
|
|
|
|
|
std::string doRequest(std::string uri, std::string params);
|
|
|
|
void setcUrlOptions();
|
2013-03-15 15:59:19 -04:00
|
|
|
|
2019-04-13 11:48:27 -04:00
|
|
|
static size_t WriteMemoryCallback (void *ptr, size_t size, size_t nmemb, void *data);
|
|
|
|
static int progress_callback (void *clientp, double dltotal, double dlnow, double ultotal, double ulnow);
|
|
|
|
std::string sortMethodString (enum sortMethod sort);
|
|
|
|
std::string getSoundResourceFile (std::string ID);
|
2013-03-15 15:59:19 -04:00
|
|
|
|
|
|
|
CURL *curl;
|
2019-04-13 11:48:27 -04:00
|
|
|
char errorBuffer[CURL_ERROR_SIZE]; // storage for cUrl error message
|
2013-03-15 15:59:19 -04:00
|
|
|
|
2013-06-14 14:17:24 -04:00
|
|
|
FILE* theFile;
|
|
|
|
|
2013-06-16 10:43:43 -04:00
|
|
|
void updateProgress(double dlnow, double dltotal);
|
|
|
|
void doneWithMootcher();
|
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 report_login_error(const std::string &msg);
|
2013-06-16 10:43:43 -04:00
|
|
|
|
2013-06-14 14:17:24 -04:00
|
|
|
Gtk::HBox progress_hbox;
|
|
|
|
Gtk::ProgressBar progress_bar;
|
|
|
|
Gtk::Button cancel_download_btn;
|
|
|
|
|
|
|
|
bool cancel_download;
|
2015-10-04 14:51:05 -04:00
|
|
|
void cancelDownload() {
|
2013-06-14 14:17:24 -04:00
|
|
|
cancel_download = true;
|
|
|
|
progress_hbox.hide();
|
|
|
|
}
|
|
|
|
|
2013-03-15 15:59:19 -04:00
|
|
|
std::string basePath;
|
|
|
|
std::string xmlLocation;
|
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 oauth_token;
|
|
|
|
struct curl_slist *custom_headers;
|
2013-03-15 15:59:19 -04:00
|
|
|
};
|
|
|
|
|
2015-12-07 17:08:19 -05:00
|
|
|
#endif // __gtk_ardour_sfdb_freesound_mootcher_h__
|