/**
  * get_metadata
  * Returns song metadata for what we're passed in.
  */
 public function get_metadata($song_info)
 {
     if (!($mbid = $song_info['mb_trackid'])) {
         return null;
     }
     $mb = new MusicBrainz(new RequestsMbClient());
     $includes = array('artists', 'releases');
     try {
         $track = $mb->lookup('recording', $mbid, $includes);
     } catch (Exception $e) {
         return null;
     }
     $results = array();
     if (count($track->{'artist-credit'}) > 0) {
         $artist = $track->{'artist-credit'}[0];
         $results['mb_artistid'] = $artist->id;
         $results['artist'] = $artist->name;
         $results['title'] = $track->title;
         if (count($track->releases) == 1) {
             $release = $track->releases[0];
             $results['album'] = $release->title;
         }
     }
     return $results;
 }
Exemple #2
0
 /**
  * get_metadata
  * Returns song metadata for what we're passed in.
  */
 public function get_metadata($gather_types, $song_info)
 {
     // Music metadata only
     if (!in_array('music', $gather_types)) {
         return null;
     }
     if (!($mbid = $song_info['mb_trackid'])) {
         return null;
     }
     $mb = new MusicBrainz(new RequestsMbClient());
     $includes = array('artists', 'releases');
     try {
         $track = $mb->lookup('recording', $mbid, $includes);
     } catch (Exception $e) {
         return null;
     }
     $results = array();
     if (count($track['artist-credit']) > 0) {
         $artist = $track['artist-credit'][0];
         $artist = $artist['artist'];
         $results['mb_artistid'] = $artist['id'];
         $results['artist'] = $artist['name'];
         $results['title'] = $track['title'];
         if (count($track['releases']) == 1) {
             $release = $track['releases'][0];
             $results['album'] = $release['title'];
         }
     }
     return $results;
 }
Exemple #3
0
 /**
  * gather_musicbrainz
  * This function retrieves art based on MusicBrainz' Advanced
  * Relationships
  * @param int $limit
  * @param array $data
  * @return array
  */
 public function gather_musicbrainz($limit = 5, $data = array())
 {
     $images = array();
     $num_found = 0;
     if ($this->type != 'album') {
         return $images;
     }
     if ($data['mbid']) {
         debug_event('mbz-gatherart', "Album MBID: " . $data['mbid'], '5');
     } else {
         return $images;
     }
     $mb = new MusicBrainz(new RequestsHttpAdapter());
     $includes = array('url-rels');
     try {
         $release = $mb->lookup('release', $data['mbid'], $includes);
     } catch (Exception $e) {
         return $images;
     }
     $asin = $release->asin;
     if ($asin) {
         debug_event('mbz-gatherart', "Found ASIN: " . $asin, '5');
         $base_urls = array("01" => "ec1.images-amazon.com", "02" => "ec1.images-amazon.com", "03" => "ec2.images-amazon.com", "08" => "ec1.images-amazon.com", "09" => "ec1.images-amazon.com");
         foreach ($base_urls as $server_num => $base_url) {
             // to avoid complicating things even further, we only look for large cover art
             $url = 'http://' . $base_url . '/images/P/' . $asin . '.' . $server_num . '.LZZZZZZZ.jpg';
             debug_event('mbz-gatherart', "Evaluating Amazon URL: " . $url, '5');
             $request = Requests::get($url, array(), Core::requests_options());
             if ($request->status_code == 200) {
                 $num_found++;
                 debug_event('mbz-gatherart', "Amazon URL added: " . $url, '5');
                 $images[] = array('url' => $url, 'mime' => 'image/jpeg', 'title' => 'MusicBrainz');
                 if ($num_found >= $limit) {
                     return $images;
                 }
             }
         }
     }
     // The next bit is based directly on the MusicBrainz server code
     // that displays cover art.
     // I'm leaving in the releaseuri info for the moment, though
     // it's not going to be used.
     $coverartsites = array();
     $coverartsites[] = array('name' => "CD Baby", 'domain' => "cdbaby.com", 'regexp' => '@http://cdbaby\\.com/cd/(\\w)(\\w)(\\w*)@', 'imguri' => 'http://cdbaby.name/$matches[1]/$matches[2]/$matches[1]$matches[2]$matches[3].jpg', 'releaseuri' => 'http://cdbaby.com/cd/$matches[1]$matches[2]$matches[3]/from/musicbrainz');
     $coverartsites[] = array('name' => "CD Baby", 'domain' => "cdbaby.name", 'regexp' => "@http://cdbaby\\.name/([a-z0-9])/([a-z0-9])/([A-Za-z0-9]*).jpg@", 'imguri' => 'http://cdbaby.name/$matches[1]/$matches[2]/$matches[3].jpg', 'releaseuri' => 'http://cdbaby.com/cd/$matches[3]/from/musicbrainz');
     $coverartsites[] = array('name' => 'archive.org', 'domain' => 'archive.org', 'regexp' => '/^(.*\\.(jpg|jpeg|png|gif))$/', 'imguri' => '$matches[1]', 'releaseuri' => '');
     $coverartsites[] = array('name' => "Jamendo", 'domain' => "www.jamendo.com", 'regexp' => '/http://www\\.jamendo\\.com/(\\w\\w/)?album/(\\d+)/', 'imguri' => 'http://img.jamendo.com/albums/$matches[2]/covers/1.200.jpg', 'releaseuri' => 'http://www.jamendo.com/album/$matches[2]');
     $coverartsites[] = array('name' => '8bitpeoples.com', 'domain' => '8bitpeoples.com', 'regexp' => '/^(.*)$/', 'imguri' => '$matches[1]', 'releaseuri' => '');
     $coverartsites[] = array('name' => 'Encyclopédisque', 'domain' => 'encyclopedisque.fr', 'regexp' => '/http://www.encyclopedisque.fr/images/imgdb/(thumb250|main)/(\\d+).jpg/', 'imguri' => 'http://www.encyclopedisque.fr/images/imgdb/thumb250/$matches[2].jpg', 'releaseuri' => 'http://www.encyclopedisque.fr/');
     $coverartsites[] = array('name' => 'Thastrom', 'domain' => 'www.thastrom.se', 'regexp' => '/^(.*)$/', 'imguri' => '$matches[1]', 'releaseuri' => '');
     $coverartsites[] = array('name' => 'Universal Poplab', 'domain' => 'www.universalpoplab.com', 'regexp' => '/^(.*)$/', 'imguri' => '$matches[1]', 'releaseuri' => '');
     foreach ($release->relations as $ar) {
         $arurl = $ar->url->resource;
         debug_event('mbz-gatherart', "Found URL AR: " . $arurl, '5');
         foreach ($coverartsites as $casite) {
             if (strpos($arurl, $casite['domain']) !== false) {
                 debug_event('mbz-gatherart', "Matched coverart site: " . $casite['name'], '5');
                 if (preg_match($casite['regexp'], $arurl, $matches)) {
                     $num_found++;
                     $url = '';
                     eval("\$url = \"{$casite['imguri']}\";");
                     debug_event('mbz-gatherart', "Generated URL added: " . $url, '5');
                     $images[] = array('url' => $url, 'mime' => 'image/jpeg', 'title' => 'MusicBrainz');
                     if ($num_found >= $limit) {
                         return $images;
                     }
                 }
             }
         }
         // end foreach coverart sites
     }
     // end foreach
     return $images;
 }
<pre><?php 
use Guzzle\Http\Client;
use MusicBrainz\HttpAdapters\GuzzleHttpAdapter;
use MusicBrainz\MusicBrainz;
require dirname(__DIR__) . '/vendor/autoload.php';
// Create new MusicBrainz object
$brainz = new MusicBrainz(new GuzzleHttpAdapter(new Client()));
$brainz->setUserAgent('ApplicationName', '0.2', 'http://example.com');
/**
 * Lookup an Artist and include a list of Releases, Recordings, Release Groups and User Ratings
 * Note: You must be logged in to retrieve user-ratings
 * @see http://musicbrainz.org/doc/Artist
 */
$includes = array('releases', 'recordings', 'release-groups', 'user-ratings');
try {
    $artist = $brainz->lookup('artist', '4dbf5678-7a31-406a-abbe-232f8ac2cd63', $includes);
    print_r($artist);
} catch (Exception $e) {
    print $e->getMessage();
}
print "\n\n";
/**
 * Lookup a Release Group based on an MBID
 * @see http://musicbrainz.org/doc/Release_Group
 */
try {
    //born this way: the remix
    $releaseGroup = $brainz->lookup('release-group', 'e4307c5f-1959-4163-b4b1-ded4f9d786b0');
    print_r($releaseGroup);
} catch (Exception $e) {
    echo $e->getMessage();
 /**
  * @dataProvider MBIDProvider
  */
 public function testIsValidMBID($validation, $mbid)
 {
     $this->assertEquals($validation, $this->brainz->isValidMBID($mbid));
 }
Exemple #6
0
 /**
  * Load wanted release data.
  * @param boolean $track_details
  */
 public function load_all($track_details = true)
 {
     $mb = new MusicBrainz(new RequestsHttpAdapter());
     $this->songs = array();
     try {
         $group = $mb->lookup('release-group', $this->mbid, array('releases'));
         // Set fresh data
         $this->name = $group->title;
         $this->year = date("Y", strtotime($group->{'first-release-date'}));
         // Load from database if already cached
         $this->songs = Song_preview::get_song_previews($this->mbid);
         if (count($group->releases) > 0) {
             $this->release_mbid = $group->releases[0]->id;
             if ($track_details && count($this->songs) == 0) {
                 // Use the first release as reference for track content
                 $release = $mb->lookup('release', $this->release_mbid, array('recordings'));
                 foreach ($release->media as $media) {
                     foreach ($media->tracks as $track) {
                         $song = array();
                         $song['disk'] = $media->position;
                         $song['track'] = $track->number;
                         $song['title'] = $track->title;
                         $song['mbid'] = $track->id;
                         if ($this->artist) {
                             $song['artist'] = $this->artist;
                         }
                         $song['artist_mbid'] = $this->artist_mbid;
                         $song['session'] = session_id();
                         $song['album_mbid'] = $this->mbid;
                         if ($this->artist) {
                             $artist = new Artist($this->artist);
                             $artist_name = $artist->name;
                         } else {
                             $wartist = Wanted::get_missing_artist($this->artist_mbid);
                             $artist_name = $wartist['name'];
                         }
                         $song['file'] = null;
                         foreach (Plugin::get_plugins('get_song_preview') as $plugin_name) {
                             $plugin = new Plugin($plugin_name);
                             if ($plugin->load($GLOBALS['user'])) {
                                 $song['file'] = $plugin->_plugin->get_song_preview($track->id, $artist_name, $track->title);
                                 if ($song['file'] != null) {
                                     break;
                                 }
                             }
                         }
                         if ($song != null) {
                             $this->songs[] = new Song_Preview(Song_preview::insert($song));
                         }
                     }
                 }
             }
         }
     } catch (Exception $e) {
         $this->songs = array();
     }
     foreach ($this->songs as $song) {
         $song->f_album = $this->name;
         $song->format();
     }
 }
Exemple #7
0
 public function load_all($track_details = true)
 {
     $mb = new MusicBrainz(new RequestsMbClient());
     $this->songs = array();
     try {
         $group = $mb->lookup('release-group', $this->mbid, array('releases'));
         // Set fresh data
         $this->name = $group->title;
         $this->year = date("Y", strtotime($group->{'first-release-date'}));
         // Load from database if already cached
         $this->songs = Song_preview::get_song_previews($this->mbid);
         if (count($group->releases) > 0) {
             $this->release_mbid = $group->releases[0]->id;
             if ($track_details && count($this->songs) == 0) {
                 // Use the first release as reference for track content
                 $release = $mb->lookup('release', $this->release_mbid, array('recordings'));
                 foreach ($release->media as $media) {
                     foreach ($media->tracks as $track) {
                         $song = array();
                         $song['disk'] = $media->position;
                         $song['track'] = $track->number;
                         $song['title'] = $track->title;
                         $song['mbid'] = $track->id;
                         if ($this->artist) {
                             $song['artist'] = $this->artist;
                         }
                         $song['artist_mbid'] = $this->artist_mbid;
                         $song['session'] = session_id();
                         $song['album_mbid'] = $this->mbid;
                         if (AmpConfig::get('echonest_api_key')) {
                             $echonest = new EchoNest_Client(new EchoNest_HttpClient_Requests());
                             $echonest->authenticate(AmpConfig::get('echonest_api_key'));
                             $enSong = null;
                             try {
                                 $enProfile = $echonest->getTrackApi()->profile('musicbrainz:track:' . $track->id);
                                 $enSong = $echonest->getSongApi()->profile($enProfile['song_id'], array('id:7digital-US', 'audio_summary', 'tracks'));
                             } catch (Exception $e) {
                                 debug_event('echonest', 'EchoNest track error on `' . $track->id . '` (' . $track->title . '): ' . $e->getMessage(), '1');
                             }
                             // Wans't able to get the song with MusicBrainz ID, try a search
                             if ($enSong == null) {
                                 if ($this->artist) {
                                     $artist = new Artist($this->artist);
                                     $artist_name = $artist->name;
                                 } else {
                                     $wartist = Wanted::get_missing_artist($this->artist_mbid);
                                     $artist_name = $wartist['name'];
                                 }
                                 try {
                                     $enSong = $echonest->getSongApi()->search(array('results' => '1', 'artist' => $artist_name, 'title' => $track->title, 'bucket' => array('id:7digital-US', 'audio_summary', 'tracks')));
                                 } catch (Exception $e) {
                                     debug_event('echonest', 'EchoNest song search error: ' . $e->getMessage(), '1');
                                 }
                             }
                             if ($enSong != null) {
                                 $song['file'] = $enSong[0]['tracks'][0]['preview_url'];
                                 debug_event('echonest', 'EchoNest `' . $track->title . '` preview: ' . $song['file'], '1');
                             }
                         }
                         $this->songs[] = new Song_Preview(Song_preview::insert($song));
                     }
                 }
             }
         }
     } catch (Exception $e) {
         $this->songs = array();
     }
     foreach ($this->songs as $song) {
         $song->f_album = $this->name;
         $song->format();
     }
 }
<pre><?php 
use Guzzle\Http\Client;
use MusicBrainz\Filters\RecordingFilter;
use MusicBrainz\HttpAdapters\GuzzleHttpAdapter;
use MusicBrainz\MusicBrainz;
require dirname(__DIR__) . '/vendor/autoload.php';
//Create new MusicBrainz object
$brainz = new MusicBrainz(new GuzzleHttpAdapter(new Client()));
$brainz->setUserAgent('ApplicationName', '0.2', 'http://example.com');
// set defaults
$releaseDate = new DateTime();
$artistId = null;
$songId = null;
$trackLen = -1;
$albumName = '';
$lastScore = null;
$firstRecording = array('release' => null, 'releaseDate' => new DateTime(), 'recording' => null, 'artistId' => null, 'recordingId' => null, 'trackLength' => null);
// Set the search arguments to pass into the RecordingFilter
$args = array("recording" => 'we will rock you', "artist" => 'Queen', 'status' => 'official', 'country' => 'GB');
try {
    // Find all the recordings that match the search and loop through them
    $recordings = $brainz->search(new RecordingFilter($args));
    /** @var $recording \MusicBrainz\Recording */
    foreach ($recordings as $recording) {
        // if the recording has a lower score than the previous recording, stop the loop.
        // This is because scores less than 100 usually don't match the search well
        if (null != $lastScore && $recording->getScore() < $lastScore) {
            break;
        }
        $lastScore = $recording->getScore();
        $releaseDates = $recording->getReleaseDates();
<pre><?php 
use Guzzle\Http\Client;
use MusicBrainz\Filters\ArtistFilter;
use MusicBrainz\Filters\LabelFilter;
use MusicBrainz\Filters\RecordingFilter;
use MusicBrainz\Filters\ReleaseGroupFilter;
use MusicBrainz\HttpAdapters\GuzzleHttpAdapter;
use MusicBrainz\MusicBrainz;
require dirname(__DIR__) . '/vendor/autoload.php';
// Create new MusicBrainz object
$brainz = new MusicBrainz(new GuzzleHttpAdapter(new Client()));
$brainz->setUserAgent('ApplicationName', '0.2', 'http://example.com');
/**
 * Get the release groups for an artist
 * @see http://musicbrainz.org/doc/Release_Group
 */
$args = array("artist" => 'Weezer');
try {
    $releaseGroups = $brainz->search(new ReleaseGroupFilter($args));
    var_dump($releaseGroups);
} catch (Exception $e) {
    print $e->getMessage();
}
print "\n\n";
/**
 * Do an artist search and return a list of artists that match
 * a search
 * @see http://musicbrainz.org/doc/Artist
 */
$args = array("artist" => 'Weezer');
try {
<pre><?php 
use Guzzle\Http\Client;
use MusicBrainz\HttpAdapters\GuzzleHttpAdapter;
use MusicBrainz\MusicBrainz;
require dirname(__DIR__) . '/vendor/autoload.php';
// Create new MusicBrainz object
$brainz = new MusicBrainz(new GuzzleHttpAdapter(new Client()));
$brainz->setUserAgent('ApplicationName', '0.2', 'http://example.com');
/**
 * Browse Releases based on an Artist MBID (Weezer in this case)
 * Include the Labels for the Release and the Recordings in it
 */
$includes = array('labels', 'recordings');
try {
    $details = $brainz->browseRelease('artist', '6fe07aa5-fec0-4eca-a456-f29bff451b04', $includes, 2);
    print_r($details);
} catch (Exception $e) {
    print $e->getMessage();
}
print "\n\n";
/**
 * Browse an artist based on a Recording MBID and include their aliases and ratings
 */
$includes = array('aliases', 'ratings');
try {
    $details = $brainz->browseArtist('recording', 'd615590b-1546-441d-9703-b3cf88487cbd', $includes);
    print_r($details);
} catch (Exception $e) {
    print $e->getMessage();
}
print "\n\n";