Class: SimpleFreesound

SimpleFreesound

server.SimpleFreesound

Server side class for use in Node.js, allowing to query detailed info on sounds and download them from freesound.

Powered by freesound api.

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
Name Type Attributes Default Description
publicPath String <optional>
'public'

The public path (relative to node's cwd) of the folder where clients can access files.

destination String <optional>
'.'

The path (relative to the public path) of the folder where to download files.

storeSoundsInfo Boolean <optional>
false

Store all sounds detailed informations, including preview urls, to optimize the number of queries to the API (can be memory consuming).

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(), download() or 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
Name Type Attributes Description
search Array.String <optional>

The search terms that will be used to build the query.

username Array.String <optional>

A list of usernames to search files from.

duration Array <optional>

An array of size 2 : [ minDuration, maxDuration ] (in seconds). If maxDuration is not a number, it will be interpreted as "*" (no maximum duration).

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 null, the ids from currentSoundsInfo will be used.

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
Name Type Attributes Description
search Array.String <optional>

The search terms that will be used to build the query.

username Array.String <optional>

A list of usernames to search files from.

duration Array <optional>

An array of size 2 : [ minDuration, maxDuration ] (in seconds). If maxDuration is not a number, it will be interpreted as "*" (no maximum duration).

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: