Exemplo n.º 1
0
     break;
 case 'democratic':
     $democratic = new Democratic($_REQUEST['democratic_id']);
     $urls = array($democratic->play_url());
     break;
 case 'download':
     $media_ids[] = array('object_type' => 'song', 'object_id' => scrub_in($_REQUEST['song_id']));
     break;
 case 'live_stream':
     $object = new Radio($_REQUEST['stream_id']);
     if ($object->name) {
         $media_ids[] = array('object_type' => 'radio', 'object_id' => scrub_in($_REQUEST['stream_id']));
     }
     break;
 case 'album_preview':
     $songs = Song_preview::get_song_previews($_REQUEST['mbid']);
     foreach ($songs as $song) {
         if (!empty($song->file)) {
             $media_ids[] = array('object_type' => 'song_preview', 'object_id' => $song->id);
         }
     }
     break;
 case 'song_preview':
     $media_ids[] = array('object_type' => 'song_preview', 'object_id' => scrub_in($_REQUEST['id']));
     break;
 case 'channel':
     $media_ids[] = array('object_type' => 'channel', 'object_id' => scrub_in($_REQUEST['id']));
     break;
 case 'broadcast':
     $media_ids[] = array('object_type' => 'broadcast', 'object_id' => scrub_in($_REQUEST['id']));
     break;
Exemplo n.º 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();
     }
 }
Exemplo n.º 3
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();
     }
 }
Exemplo n.º 4
0
 }
 if (!$playlist->has_access()) {
     break;
 }
 $songs = array();
 $item_id = $_REQUEST['item_id'];
 switch ($_REQUEST['item_type']) {
     case 'smartplaylist':
         $smartplaylist = new Search('song', $item_id);
         $items = $playlist->get_items();
         foreach ($items as $item) {
             $songs[] = $item['object_id'];
         }
         break;
     case 'album_preview':
         $preview_songs = Song_preview::get_song_previews($item_id);
         foreach ($preview_songs as $song) {
             if (!empty($song->file)) {
                 $songs[] = $song->id;
             }
         }
         break;
     case 'album':
         debug_event('playlist', 'Adding all songs of album(s) {' . $item_id . '}...', '5');
         $albums_array = explode(',', $item_id);
         foreach ($albums_array as $a) {
             $album = new Album($a);
             $asongs = $album->get_songs();
             foreach ($asongs as $song_id) {
                 $songs[] = $song_id;
             }