Exemple #1
0
     $time = $trackHtml->item(0)->textContent;
     $timeVal = substr($time, -1);
     switch ($timeVal) {
         case "m":
             $timeDiff = substr($time, 0, strlen($time) - 1) * 60;
             break;
         case "h":
         default:
             $timeDiff = substr($time, 0, strlen($time) - 1) * 60 * 60;
             break;
     }
     $timestamp = time() - $timeDiff;
     $artist = $trackHtml->item(1)->textContent;
     $track = $trackHtml->item(2)->textContent;
     if ($timestamp > $start_date && $timestamp < $end_date) {
         $songApi = $echonest->getSongApi();
         $songData = $songApi->search(array('title' => $track, 'artist' => $artist, 'bucket' => 'id:musixmatch-WW'));
         $musixMatchData = explode(':', $songData[0]['foreign_ids'][0]['foreign_id']);
         $musixMatchId = $musixMatchData[count($musixMatchData) - 1];
         $musixMatchResponse = json_decode(file_get_contents('http://api.musixmatch.com/ws/1.1/track.lyrics.get?format=json&apikey=' . $musixapikey . '&track_id=' . $musixMatchId));
         $lyrics .= $musixMatchResponse->message->body->lyrics->lyrics_body;
         $frequency++;
     }
     if ($i == 19) {
         break;
     }
 }
 $url = 'http://battlehack.jakelprice.com/api/nlp';
 $fields = array('payload' => $lyrics);
 //url-ify the data for the POST
 $fields_string = '';
Exemple #2
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();
     }
 }
Exemple #3
0
 /**
  * Get song preview.
  * @param string $track_mbid
  * @param string $artist_name
  * @param string $title
  * @return array
  */
 public function get_song_preview($track_mbid, $artist_name, $title)
 {
     $file = null;
     $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_mbid);
         $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_mbid . '` (' . $title . '): ' . $e->getMessage(), '1');
     }
     // Wans't able to get the song with MusicBrainz ID, try a search
     if ($enSong == null) {
         try {
             $enSong = $echonest->getSongApi()->search(array('results' => '1', 'artist' => $artist_name, 'title' => $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) {
         $file = $enSong[0]['tracks'][0]['preview_url'];
         debug_event('echonest', 'EchoNest `' . $title . '` preview: ' . $file, '1');
     }
     return $file;
 }