diff options
-rw-r--r-- | artists.php | 9 | ||||
-rw-r--r-- | config/ampache.cfg.php.dist | 5 | ||||
-rw-r--r-- | lib/class/artist.class.php | 32 | ||||
-rw-r--r-- | templates/show_artist.inc.php | 3 |
4 files changed, 49 insertions, 0 deletions
diff --git a/artists.php b/artists.php index 1f915d94..ea9cb414 100644 --- a/artists.php +++ b/artists.php @@ -42,6 +42,15 @@ switch($_REQUEST['action']) { $object_ids = $artist->get_songs(); require_once Config::get('prefix') . '/templates/show_artist.inc.php'; break; + + case 'show_like': + $artist = new Artist($_REQUEST['artist']); + $artist->format(); + $object_type = 'artist'; + $object_ids = $artist->get_like(); + require_once Config::get('prefix') . '/templates/show_artist.inc.php'; + break; + case 'update_from_tags': $type = 'artist'; diff --git a/config/ampache.cfg.php.dist b/config/ampache.cfg.php.dist index 8f24e57d..13e31fee 100644 --- a/config/ampache.cfg.php.dist +++ b/config/ampache.cfg.php.dist @@ -307,6 +307,11 @@ art_order = "db,tags,folder,musicbrainz,lastfm,google" ;amazon_developer_public_key = "" ;amazon_developer_private_key = "" +; LastFM API Key +; Set this to your api key that you can register +; on last.fm +;lastfm_api_key = "" + ; Amazon base urls ; An array of Amazon sites to search. ; NOTE: This will search each of these sites in turn so don't expect it 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 diff --git a/templates/show_artist.inc.php b/templates/show_artist.inc.php index 408e6b5e..d14bc665 100644 --- a/templates/show_artist.inc.php +++ b/templates/show_artist.inc.php @@ -54,6 +54,9 @@ if (Config::get('ratings')) { <?php echo Ajax::button('?action=basket&type=artist_random&id=' . $artist->id,'random',_('Random'),'random_' . $artist->id); ?> <?php echo Ajax::text('?action=basket&type=artist_random&id=' . $artist->id, sprintf(_('Add Random Songs By %s'), $artist->f_name),'random_text_' . $artist->id); ?> </li> +<li> + <a href="<?php echo $web_path; ?>/artists.php?action=show_like&artist=<?php echo $artist->id; ?>"><?php echo get_user_icon('view'); ?></a> <a href="<?php echo $web_path; ?>/artists.php?action=show_like&artist=<?php echo $artist->id; ?>"><?php printf(_("Show Similar to %s"), $artist->f_name); ?></a> +</li> <?php if (Access::check('interface','50')) { ?> <li> <a href="<?php echo $web_path; ?>/artists.php?action=update_from_tags&artist=<?php echo $artist->id; ?>"><?php echo get_user_icon('cog', _('Update from tags')); ?></a> |