예제 #1
0
 /**
  * Search an album by his title.
  *
  * @param string $albumTitle
  *
  * @return bool|array Albums collection or false on failure
  */
 public function searchAlbumByTitle($albumTitle)
 {
     //set valid request
     $this->endpoint .= '2/release/';
     $this->queryParameters['query'] = "release:{$albumTitle};";
     //execute the request
     $response = $this->executeCall();
     if ($response === false) {
         //error on response
         return false;
     }
     if ($response->count === 0) {
         $this->errorMessage = 'No album found';
         //no release matched
         return array();
     }
     //order by score
     $musicBrainzReleases = $response->releases;
     usort($musicBrainzReleases, array('MusicBrainz', 'orderByScore'));
     //get high score and apply a 90% ratio
     $thresholdScore = $musicBrainzReleases[0]->score * 0.9;
     $albums = array();
     //transform MusicBrainz albums into WMP albums
     require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/Album.php';
     foreach ($musicBrainzReleases as $musicBrainzRelease) {
         if ($musicBrainzRelease->score >= $thresholdScore) {
             $album = new Album();
             $album->mbid = $musicBrainzRelease->id;
             $album->name = $musicBrainzRelease->title;
             if (property_exists($musicBrainzRelease, 'date')) {
                 $album->year = substr($musicBrainzRelease->date, 0, 4);
             }
             if (property_exists($musicBrainzRelease, 'country')) {
                 $album->country = $musicBrainzRelease->country;
             }
             if (property_exists($musicBrainzRelease, 'artist-credit') && count($musicBrainzRelease->{'artist-credit'}) > 0) {
                 $artists = $musicBrainzRelease->{'artist-credit'};
                 $album->artistName = $artists[0]->artist->name;
             }
             $album->mbidGroup = $musicBrainzRelease->{'release-group'}->id;
             $status = '?';
             $packaging = '?';
             $type = '?';
             $media = '?';
             if (property_exists($musicBrainzRelease, 'status')) {
                 $status = $musicBrainzRelease->status;
             }
             if (property_exists($musicBrainzRelease, 'packaging')) {
                 $packaging = $musicBrainzRelease->packaging;
             }
             if (property_exists($musicBrainzRelease->{'release-group'}, 'primary-type')) {
                 $type = $musicBrainzRelease->{'release-group'}->{'primary-type'};
             }
             if (count($musicBrainzRelease->media) > 0 && property_exists($musicBrainzRelease->media[0], 'format')) {
                 $media = $musicBrainzRelease->media[0]->format;
             }
             $album->description = $type . ' - ' . $status . ' - ' . $packaging . ' - ' . $media;
             //propose a cover URL with Cover Art Archive
             require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/CoverArtArchive.php';
             $coverArtArchive = new CoverArtArchive();
             $album->coverPath = $coverArtArchive->getCoverURL($musicBrainzRelease->id);
             $album->structureData();
             unset($album->id, $album->tracks, $album->disk);
             array_push($albums, $album);
         }
     }
     //return albums
     return $albums;
 }
예제 #2
0
 /**
  * Call Cover Art Archive wrapper and store image.
  *
  * @return bool Result
  */
 private function callCoverArtArchive()
 {
     require_once $_SERVER['DOCUMENT_ROOT'] . '/server/lib/CoverArtArchive.php';
     $CoverArtArchive = new CoverArtArchive();
     $stream = $CoverArtArchive->getCoverImage($this->mbid);
     if ($stream !== false) {
         //store image
         $this->storeCover($stream);
         //returns image
         return $stream;
     }
     //returns Cover Art Archive search has encountered an error
     return false;
 }