/** * Performs a query based on the parameters * supplied in the TrackFilter object. Returns * an array of possible matches with scores, as * returned by the musicBrainz XML web service. * Note that these types of queries only return some * information, and not all the information available * about a particular track is available using * this type of query. You will need to get the * MusicBrainz id (mbid) and perform a lookup with * getTrack to return complete information about * a release. This method returns an array of * Track objects that are possible matches. * * @param phpBrainz_TrackFilter $trackFilterObj * @return array */ public function findTrack(phpBrainz_TrackFilter $trackFilterObj) { if (sizeof($trackFilterObj->createParameters()) < 1) { throw new Exception('The release filter object needs at least 1 argument to create a query.'); } $queryStr = TRACK_URL . "?type=xml"; $args = $trackFilterObj->createParameters(); foreach ($args as $key => $value) { $args[$key] = utf8_encode($value); } $queryStr .= "&" . http_build_query($args); $xml = simplexml_load_file($queryStr); if ($xml === false) { throw new Exception("Unable to load XML file. URL: " . $url); } $tracks = array(); foreach ($xml->{'track-list'}->track as $track) { # Must specify the namespace $attrNS = $track->attributes("http://musicbrainz.org/ns/ext-1.0#"); $trackRels = array(); foreach ($track->{'release-list'}->release as $release) { $trackRels[] = $this->parseReleaseXML($release); } $newTrack = $this->parseTrackXML($track); $tracks[] = $newTrack; } return $tracks; }
/** * Performs a query based on the parameters * supplied in the TrackFilter object. Returns * an array of possible matches with scores, as * returned by the musicBrainz XML web service. * Note that these types of queries only return some * information, and not all the information available * about a particular track is available using * this type of query. You will need to get the * MusicBrainz id (mbid) and perform a lookup with * getTrack to return complete information about * a release. This method returns an array of * Track objects that are possible matches. * * @param phpBrainz_TrackFilter $trackFilterObj * @return array */ public function findTrack(phpBrainz_TrackFilter $trackFilterObj) { if (sizeof($trackFilterObj->createParameters()) < 1) { die(print "At least one argument must be supplied to performa a query."); } $queryStr = TRACK_URL . "?type=xml"; $args = $trackFilterObj->createParameters(); foreach ($args as $key => $value) { $queryStr .= "&" . $key . "=" . urlencode($value); } $xml = simplexml_load_file($queryStr); $tracks = array(); foreach ($xml->{'track-list'}->track as $track) { $attrNS = $track->attributes("http://musicbrainz.org/ns/ext-1.0#"); $trackRels = array(); foreach ($track->{'release-list'}->release as $release) { $trackRels[] = $this->parseReleaseXML($release); } $newTrack = $this->parseTrackXML($track); $tracks[] = $newTrack; } return $tracks; }