Constructor
new SimpleFreesound(apiKey, options)
Parameters:
Name | Type | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
apiKey |
String | Your api key, as generated from your freesound developer account when creating a new application. |
||||||||||||||||||||
options |
Object | Configuration options. Properties
|
- Source:
Example
import SimpleFreesound from 'simple-freesound';
const fs = new SimpleFreesound('your_freesound_api_key_goes_here', {
destination: './downloads'
});
fs.query({
search: [ 'space', 'insect' ],
duration: [ 1, 20 ],
})
.then(() => fs.download())
.then(() => {
console.log(fs.currentSoundsInfo);
});
Members
soundsInfo
An object containing every detailed information obtained since
instantiation or last call to
.clear()
Properties:
Name | Type | Description |
---|---|---|
soundsInfo |
Object |
- Source:
currentSoundsInfo
An object containing the detailed information obtained from the last call to
,
query()
,
queryFromIds()
or
download()
.queryAndDownload()
Properties:
Name | Type | Description |
---|---|---|
currentSoundsInfo |
Object |
- Source:
Methods
query(queryParams) → {Promise}
Get a list of sound ids with detailed information, that correspond to a set of query parameters.
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
queryParams |
Object | The parameters used to build the query. Properties
|
- Source:
Throws:
-
An error if a problem occurs during the query.
- Type
- Error
Returns:
A Promise object that resolves with the list of new sound ids if the query goes well.
- Type
- Promise
queryFromIds(ids) → {Promise}
Get detailed information of sounds from their ids.
Parameters:
Name | Type | Description |
---|---|---|
ids |
Array.Number | The ids of the sounds we want to get the detailed info of. |
- Source:
Throws:
-
An error if a problem occurs during the query.
- Type
- Error
Returns:
A promise that will resolve with an array of the sound ids the detailed info of which needed to be queried.
- Type
- Promise
download(idsopt) → {Promise}
Download hq mp3 previews from their sound ids.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
ids |
Array.Number |
<optional> |
null | The ids of the sounds to download.
If |
- Source:
Throws:
-
An error if a problem occurs during the downloads.
- Type
- Error
Returns:
A promise that will resolve if the downloads go well.
- Type
- Promise
queryAndDownload(queryParams, destinationopt) → {Promise}
Download hq mp3 previews from queried sound information.
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
queryParams |
Object | The parameters used to build the query. Properties
|
||||||||||||||||||
destination |
String |
<optional> |
'.' | The folder in which to save the downloaded files. |
- Source:
Throws:
-
An error if a problem occurs during the downloads.
- Type
- Error
Returns:
A Promise object that resolves if the downloads go well.
- Type
- Promise
clear()
Clear the internal sound information lists.
- Source:
readFromFile(filename)
Retrieve sound information list from a JSON file.
Parameters:
Name | Type | Description |
---|---|---|
filename |
String | Url of the file to read. |
- Source:
writeToFile(filename)
Dump sound information list to a JSON file.
Parameters:
Name | Type | Description |
---|---|---|
filename |
String | Url of the file to dump the list of file information to. |
- Source: