We are no longer offering accounts on this server. Consider https://gitlab.freedesktop.org/ as a place to host projects.

Commit ec8f6ea3 authored by Mike Sheldon's avatar Mike Sheldon

Add artist.getTopTags() web service method

parent e8010a93
......@@ -71,6 +71,7 @@ $method_map = array(
'auth.getmobilesession' => method_auth_getMobileSession,
'artist.getinfo' => method_artist_getInfo,
'artist.gettoptracks' => method_artist_getTopTracks,
'artist.gettoptags' => method_artist_getTopTags,
'user.getinfo' => method_user_getInfo,
'user.gettoptracks' => method_user_getTopTracks,
'user.getrecenttracks' => method_user_getRecentTracks,
......@@ -157,13 +158,24 @@ function method_artist_getInfo() {
function method_artist_getTopTracks() {
if (!isset($_GET['artist'])) {
report_failure(LFM_INVALID_PARAMS);
report_failure(LFM_INVALID_PARAMS);
}
header('Content-Type: text/xml');
print(XML::prettyXML(ArtistXML::getTopTracks($_GET['artist'])));
}
function method_artist_getTopTags() {
if (!isset($_GET['artist'])) {
report_failure(LFM_INVALID_PARAMS);
}
header('Content-Type: text/xml');
print(XML::prettyXML(ArtistXML::getTopTags($_GET['artist'])));
}
/**
* Authentication methods
*/
function method_auth_getToken() {
global $adodb;
......
......@@ -59,7 +59,7 @@ class ArtistXML {
$bio->addChild('summary', $artist->bio_summary);
$bio->addChild('content', $artist->bio_content);
return($xml);
return $xml;
}
public static function getTopTracks($artistName) {
......@@ -86,7 +86,30 @@ class ArtistXML {
$track->addChild('listeners', $tracks[$i]->getListenerCount());
}
return($xml);
return $xml;
}
public static function getTopTags($artistName) {
global $base_url;
$artist = new Artist($artistName);
if (!$artist) {
return(XML::error('failed', '7', 'Invalid resource specified'));
}
$xml = new SimpleXMLElement('<lfm statis="ok"></lfm>');
$root = $xml->addChild('toptags', null);
$root->addAttribute('artist', $artist->name);
$tags = $artist->getTopTags();
foreach($tags as $tag) {
$tag_node = $root->addChild('tag', null);
$tag_node->addChild('name', $tag);
$tag_node->addChild('url', repamp($base_url . '/tag/' . $tag));
}
return $xml;
}
}
......
......@@ -139,4 +139,26 @@ class Artist {
return Server::getArtistURL($this->name);
}
/**
* Get an artist's most used tags
*
* @param int $limit The number of tags to return (defaults to 10)
* @return An array of tags
*/
function getTopTags($limit=10) {
global $adodb;
$res = $adodb->CacheGetAll(600, 'SELECT tag, COUNT(tag) AS freq FROM tags WHERE '
. ' artist = ' . $adodb->qstr($this->name)
. ' GROUP BY tag ORDER BY freq DESC '
. ' LIMIT ' . $limit);
$tags = array();
foreach($res as &$row) {
$tags[] = $row['tag'];
}
return $tags;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment