I am currently developing a web application that will find artists and their associates titles. To do this, I decided to parse the API MusicBrainz, through this package (which documentation is here).
Suppose I already have the artist mbid (unique identifier for MusicBrainz).
The problem is that if I do a search on David Guetta (mbid = 302bd7b9-d012-4360-897a-93b00c855680
) for example, the script tells me that the number of releases is 196. However, the API provides 100 maximum results per request.
// Instantiate a MusicBrainz object
$brainz = new MusicBrainz(new GuzzleHttpAdapter(new Client()));
$brainz->setUserAgent('ApplicationName', '0.2', 'http://example.com');
$limit = 100;
$offset = 0;
$includes = array('labels', 'recordings');
try {
$details = $brainz->browseRelease('artist', '302bd7b9-d012-4360-897a-93b00c855680', $includes, $limit, $offset);
print_r($details);
} catch (Exception $e) {
print $e->getMessage();
}
The function browseRelease
below allows us to define such parameters as limit
and offset
.
public function browseRelease($entity, $mbid, $includes = array(), $limit = 25, $offset = null, $releaseType = array(), $releaseStatus = array())
{
if (!in_array($entity, array('artist', 'label', 'recording', 'release-group'))) {
throw new Exception('Invalid browse entity for release');
}
return $this->browse(
new Filters\ReleaseFilter(array()),
$entity,
$mbid,
$includes,
$limit,
$offset,
$releaseType,
$releaseStatus
);
}
Now we come to my real question in this post.
If I defined $limit = 100
and $offset = 0
for the first query, I don't understand how to change these values depending on the number of total releases, and thus get the results that are between 100 and 196 (in this example).