コード例 #1
0
 public function testInjectApi()
 {
     $client = new EchoNest_Client();
     $artistApiMock = $this->getMockBuilder('EchoNest_ApiInterface')->getMock();
     $client->setApi('artist', $artistApiMock);
     $this->assertSame($artistApiMock, $client->getArtistApi());
 }
コード例 #2
0
ファイル: slideshow.class.php プロジェクト: nioc/ampache
 protected static function get_images($artist_name)
 {
     $images = array();
     if (AmpConfig::get('echonest_api_key')) {
         $echonest = new EchoNest_Client(new EchoNest_HttpClient_Requests());
         $echonest->authenticate(AmpConfig::get('echonest_api_key'));
         try {
             $images = $echonest->getArtistApi()->setName($artist_name)->getImages();
         } catch (Exception $e) {
             debug_event('echonest', 'EchoNest artist images error: ' . $e->getMessage(), '1');
         }
     }
     foreach (Plugin::get_plugins('get_photos') as $plugin_name) {
         $plugin = new Plugin($plugin_name);
         if ($plugin->load($GLOBALS['user'])) {
             $images += $plugin->_plugin->get_photos($artist_name);
         }
     }
     return $images;
 }
コード例 #3
0
ファイル: echonest.php プロジェクト: hkdobrev/echonest-kohana
 public function __construct(EchoNest_HttpClientInterface $httpClient = null)
 {
     parent::__construct($httpClient);
 }
コード例 #4
0
ファイル: wanted.class.php プロジェクト: axelsimon/ampache
 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();
     }
 }
コード例 #5
0
ファイル: index.php プロジェクト: ukmadlz/spotify-sentiment
<?php

error_reporting(E_ALL);
require_once __DIR__ . '/lib/EchoNest/Autoloader.php';
EchoNest_Autoloader::register();
$musixapikey = '4cc9e7ad04391df298f95ede0ba7b286';
$email = $_REQUEST['email'] ? $_REQUEST['email'] : '*****@*****.**';
$start_date = $_REQUEST['start_date'] ? $_REQUEST['start_date'] : 0;
$end_date = $_REQUEST['end_date'] ? $_REQUEST['end_date'] : time();
$echonest = new EchoNest_Client();
$echonest->authenticate('R9RBK9MF4OKHSIVRW');
$html = file_get_contents('http://widget.soundwave.com/?feedType=feed&email=' . $email);
$dom = new DOMDocument();
$dom->loadHTML($html);
$xpath = new DOMXpath($dom);
$result = $xpath->query('//div/ul/li/div[@class="media-body"]');
$frequency = 0;
if ($result->length > 0) {
    $lyrics = '';
    for ($i = 0; $i < $result->length; $i++) {
        $trackHtml = $result->item($i)->childNodes;
        $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;
コード例 #6
0
ファイル: 7Digital.plugin.php プロジェクト: bl00m/ampache
 /**
  * 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;
 }