From 720dd019a0fa5d529cf41e58dff27a9cc123c5f7 Mon Sep 17 00:00:00 2001 From: Chris 'cslamar' Slamar Date: Thu, 29 Jul 2010 13:58:43 +0000 Subject: Search for similar artists --- lib/class/artist.class.php | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'lib/class/artist.class.php') 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 -- cgit