diff options
author | Chris 'cslamar' Slamar <chris@slamar.org> | 2010-07-29 13:58:43 +0000 |
---|---|---|
committer | Chris 'cslamar' Slamar <chris@slamar.org> | 2010-07-29 13:58:43 +0000 |
commit | 720dd019a0fa5d529cf41e58dff27a9cc123c5f7 (patch) | |
tree | 07d5bbf654e3c04e840587b7d14c4621a3e9c570 /lib | |
parent | 06e9339109af745e7ddb30ea86d011ee1380aca4 (diff) | |
download | ampache-720dd019a0fa5d529cf41e58dff27a9cc123c5f7.tar.gz ampache-720dd019a0fa5d529cf41e58dff27a9cc123c5f7.tar.bz2 ampache-720dd019a0fa5d529cf41e58dff27a9cc123c5f7.zip |
Search for similar artists
Diffstat (limited to 'lib')
-rw-r--r-- | lib/class/artist.class.php | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/class/artist.class.php b/lib/class/artist.class.php index f7638b94..e6b5bda9 100644 --- a/lib/class/artist.class.php +++ b/lib/class/artist.class.php @@ -145,6 +145,38 @@ class Artist extends database_object { return $results; } // get_albums + public function get_like() { + $result = array(); + $lastfm_api_key = Config::get('lastfm_api_key'); + + $artistsql = "SELECT name FROM artist WHERE id = \"" . $this->id . "\""; + $artist_result = Dba::query($artistsql); + $r = Dba::fetch_assoc($artist_result); + $searchArtist = preg_replace('/ /', '%20', $r['name']); + + $lastsite = "http://ws.audioscrobbler.com/2.0/?method=artist.getsimilar&artist=" . $searchArtist . "&api_key=" . $lastfm_api_key; + debug_event('Similar', 'search url : ' . $lastsite, 5); + $lastch = curl_init(); + curl_setopt($lastch, CURLOPT_URL, $lastsite); + curl_setopt($lastch, CURLOPT_RETURNTRANSFER, 1); + + $lastxml = simplexml_load_string( curl_exec($lastch) ); + $lastcontent = curl_exec($lastch); + $lastxml = simplexml_load_string( $lastcontent ); + + foreach( $lastxml->similarartists->children() as $lastchild ) { + $check_query = 'SELECT * FROM artist WHERE name = \'' . $lastchild->name . '\''; + $check_result = Dba::query($check_query); + $row = Dba::fetch_assoc($check_result); + if( !is_null($row['id']) ) { + $result[] = $row['id']; + // debug_event('Similar', 'row return: ' . $row['id'], 5); + } + } + + return $result; + + } // get_like /** * get_songs |