summaryrefslogtreecommitdiff
path: root/gtk2_ardour/sfdb_freesound_mootcher.h
blob: b6f3d7889d7918dc058cbc6e42361415f509eec6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*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

*****************************************************************************/

#include <string>
#include <fstream>
#include <iostream>
#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
struct MemoryStruct {
	char *memory;
	size_t size;
};

enum sortMethod {
	sort_none,		// no sort
	sort_duration_desc,	// Sort by the duration of the sounds, longest sounds first.
	sort_duration_asc, 	// Same as above, but shortest sounds first.
	sort_created_desc, 	// Sort by the date of when the sound was added. newest sounds first.
	sort_created_asc, 	// Same as above, but oldest sounds first.
	sort_downloads_desc, 	// Sort by the number of downloads, most downloaded sounds first.
	sort_downloads_asc, 	// Same as above, but least downloaded sounds first.
	sort_rating_desc, 	// Sort by the average rating given to the sounds, highest rated first.
	sort_rating_asc 	// Same as above, but lowest rated sounds first.
};


class Mootcher
{
public:
	Mootcher();
	~Mootcher();

	std::string	getAudioFile(std::string originalFileName, std::string ID, std::string audioURL, SoundFileBrowser *caller);
	std::string	searchText(std::string query, int page, std::string filter, enum sortMethod sort);

private:

	void		changeWorkingDir(const char *saveLocation);
	void		ensureWorkingDir();

	std::string	doRequest(std::string uri, std::string params);
	void		setcUrlOptions();

	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);

	CURL *curl;
	char errorBuffer[CURL_ERROR_SIZE];	// storage for cUrl error message

	std::string basePath;
	std::string xmlLocation;
};