PHP code example of aportela / musicbrainz-wrapper
1. Go to this page and download the library: Download aportela/musicbrainz-wrapper library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
aportela / musicbrainz-wrapper example snippets
er = new \Psr\Log\NullLogger();
/**
* NOTE regarding \aportela\MusicBrainzWrapper\Entity constructor params
* $logger => the log handler
* $apiFormat => json/xml
* $throttleDelayMS => milliseconds between consecutive MusicBrainz getEntity API calls (please use a reasonable value to avoid overloading the servers, ex: > 250ms)
* $cachePath => disk cache path, useful when we are continuously testing with the same values and don't want to overload the servers with repeated requests.
*/
// JSON format
$mbArtist = new \aportela\MusicBrainzWrapper\Artist($logger, \aportela\MusicBrainzWrapper\APIFormat::JSON);
// get artist object from MusicBrainz API
$mbArtist->get("ca891d65-d9b0-4258-89f7-e6ba29d83767");
// parse raw json string (use this if you have an stored pre-cached json music brainz artist api response) into artist object
$mbArtist->parse($mbArtist->raw);
// get youtube url artist relationships
$urls = $mbArtist->getURLRelationshipValues(\aportela\MusicBrainzWrapper\ArtistURLRelationshipType::SOCIAL_YOUTUBE);
// XML format
$mbArtist = new \aportela\MusicBrainzWrapper\Artist($logger, \aportela\MusicBrainzWrapper\APIFormat::XML);
// get artist object from MusicBrainz API
$mbArtist->get("ca891d65-d9b0-4258-89f7-e6ba29d83767");
// parse raw xml string (use this if you have an stored pre-cached xml music brainz artist api response) into artist object
$mbArtist->parse($mbArtist->raw);
// get youtube url artist relationships
$urls = $mbArtist->getURLRelationshipValues(\aportela\MusicBrainzWrapper\ArtistURLRelationshipType::SOCIAL_YOUTUBE);
// JSON format
$mbRelease = new \aportela\MusicBrainzWrapper\Release($logger, \aportela\MusicBrainzWrapper\APIFormat::JSON);
// get release object from MusicBrainz API
$mbRelease->get("723df70e-f79e-4602-8d1f-13cad619a6e8");
// parse raw json string (use this if you have an stored pre-cached json music brainz release api response) into release object
$mbRelease->parse($mbRelease->raw);
// XML format
$mbRelease = new \aportela\MusicBrainzWrapper\Release($logger, \aportela\MusicBrainzWrapper\APIFormat::XML);
// get release object from MusicBrainz API
$mbRelease->get("723df70e-f79e-4602-8d1f-13cad619a6e8");
// parse raw xml string (use this if you have an stored pre-cached xml music brainz release api response) into release object
$mbRelease->parse($mbRelease->raw);
// JSON format
$mbRecording = new \aportela\MusicBrainzWrapper\Recording($logger, \aportela\MusicBrainzWrapper\APIFormat::JSON);
// get recording object from MusicBrainz API
$mbRecording->get("4fba6ee9-b49d-4503-ba34-7337ed2e972f");
// parse raw json string (use this if you have an stored pre-cached json music brainz recording api response) into recording object
$mbRecording->parse($mbRecording->raw);
// XML format
$mbRecording = new \aportela\MusicBrainzWrapper\Recording($logger, \aportela\MusicBrainzWrapper\APIFormat::XML);
// get recording object from MusicBrainz API
$mbRecording->get("4fba6ee9-b49d-4503-ba34-7337ed2e972f");
// parse raw xml string (use this if you have an stored pre-cached json music brainz recording api response) into recording object
$mbRecording->parse($mbRecording->raw);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.