Commit 66e9594a authored by Jonas Haraldsson's avatar Jonas Haraldsson

gettopfans ws methods

parent d9a26dcd
......@@ -86,13 +86,14 @@ $method_map = array(
'artist.getinfo' => method_artist_getInfo,
'artist.gettoptracks' => method_artist_getTopTracks,
'artist.gettoptags' => method_artist_getTopTags,
'artist.gettopfans' => method_artist_getTopFans,
'artist.gettags' => method_artist_getTags,
'artist.getflattr' => method_artist_getFlattr,
'album.addtags' => method_album_addTags,
'album.gettoptags' => method_album_getTopTags,
'album.gettags' => method_album_getTags,
'user.getinfo' => method_user_getInfo,
'user.gettopartists' => method_user_getTopArtists,
'user.gettopartists' => method_user_getTopArtists,
'user.gettoptracks' => method_user_getTopTracks,
'user.getrecenttracks' => method_user_getRecentTracks,
'user.gettoptags' => method_user_getTopTags,
......@@ -111,6 +112,7 @@ $method_map = array(
'track.addtags' => method_track_addTags,
'track.removetag' => method_track_removeTag,
'track.gettoptags' => method_track_getTopTags,
'track.gettopfans' => method_track_getTopFans,
'track.gettags' => method_track_getTags,
'track.ban' => method_track_ban,
'track.love' => method_track_love,
......@@ -477,7 +479,7 @@ function method_artist_getInfo() {
}
/**
* artist.gettoptracks : Get the top tracks for an aritst.
* artist.gettoptracks : Get the top tracks for an artist.
*
* ###Description
* Get the top tracks for an artist, ordered by play count.
......@@ -511,10 +513,10 @@ function method_artist_getTopTracks() {
* artist.gettoptags : Get the top tags for an artist.
*
* ###Description
* Get the top tags used for an artist, ordered by tag count.
* Get the top fans used for an artist, ordered by tag count.
*
* ###Parameters
* * **artist** (required) : Name of the album's artist.
* * **artist** (required) : Name of the artist.
* * **limit** (optional) : How many items to show. Defaults to 50.
* * **format** (optional) : Format of response, **xml** or **json**. Default is xml.
* - - -
......@@ -536,6 +538,35 @@ function method_artist_getTopTags() {
respond($xml);
}
/**
* artist.gettopfans : Get the top fans for an artist.
*
* ###Description
* Get the top fans used for an artist, ordered by play count.
*
* ###Parameters
* * **artist** (required) : Name of the artist.
* * **limit** (optional) : How many items to show. Defaults to 50.
* * **format** (optional) : Format of response, **xml** or **json**. Default is xml.
* - - -
*
* @package Webservice
* @subpackage Artist
* @api
*/
function method_artist_getTopFans() {
if (!isset($_REQUEST['artist'])) {
report_failure(LFM_INVALID_PARAMS);
}
$limit = get_with_default('limit', 50);
$cache = 600;
$xml = ArtistXML::getTopFans($_REQUEST['artist'], $limit, $cache);
respond($xml);
}
/**
* artist.gettags : Get a user's top tags for an artist.
*
......@@ -1095,6 +1126,36 @@ function method_track_getTopTags() {
respond($xml);
}
/**
* track.gettopfans : Get the top fans for a track.
*
* ###Description
* Get the top fans for a track, ordered by play count.
*
* ###Parameters
* * **artist** (required) : Name of the artist.
* * **track** (required) : Name of the track.
* * **limit** (optional) : How many items to show. Defaults to 50.
* * **format** (optional) : Format of response, **xml** or **json**. Default is xml.
* - - -
*
* @package Webservice
* @subpackage Track
* @api
*/
function method_track_getTopFans() {
if (!isset($_REQUEST['artist']) OR !isset($_REQUEST['track'])) {
report_failure(LFM_INVALID_PARAMS);
}
$limit = get_with_default('limit', 50);
$cache = 600;
$xml = TrackXML::getTopFans($_REQUEST['track'], $_REQUEST['artist'], $limit, $cache);
respond($xml);
}
/**
* track.gettags : Get a user's top tags for a track.
*
......
......@@ -135,6 +135,42 @@ class ArtistXML {
return $xml;
}
public static function getTopFans($artistname, $limit, $cache) {
global $adodb;
try {
$artist = new Artist($artistname);
$res = $artist->getTopListeners($limit, 0, False, null, null, $cache);
} catch (Exception $e) {
return XML::error('error', '7', 'Invalid resource specified');
}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
$root = $xml->addChild('topfans', null);
$root->addAttribute('artist', $artist->name);
$i = $offset + 1;
foreach($res as &$row) {
try {
$user = new User($row['username']);
$user_node = $root->addChild('user', null);
$user_node->addChild('name', $user->name);
$user_node->addChild('realname', $user->fullname);
$user_node->addChild('url', repamp($user->getURL()));
$image_small = $user_node->addChild('image', null);
$image_small->addAttribute('size', 'small');
$image_medium = $user_node->addChild('image', null);
$image_medium->addAttribute('size', 'medium');
$image_large = $user_node->addChild('image', null);
$image_large->addAttribute('size', 'large');
$user_node->addChild('weight', $row['freq']);
} catch (Exception $e) {}
$i++;
}
return $xml;
}
public static function getTopTags($artistName, $limit, $cache) {
try {
......
......@@ -83,6 +83,43 @@ class TrackXML {
return $xml;
}
public static function getTopFans($name, $artistname, $limit, $cache) {
global $adodb;
try {
$track = new Track($name, $artistname);
$res = $track->getTopListeners($limit, 0, False, null, null, $cache);
} catch (Exception $e) {
return XML::error('error', '7', 'Invalid resource specified');
}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
$root = $xml->addChild('topfans', null);
$root->addAttribute('artist', $track->artist_name);
$root->addAttribute('track', $track->name);
$i = $offset + 1;
foreach($res as &$row) {
try {
$user = new User($row['username']);
$user_node = $root->addChild('user', null);
$user_node->addChild('name', $user->name);
$user_node->addChild('realname', $user->fullname);
$user_node->addChild('url', repamp($user->getURL()));
$image_small = $user_node->addChild('image', null);
$image_small->addAttribute('size', 'small');
$image_medium = $user_node->addChild('image', null);
$image_medium->addAttribute('size', 'medium');
$image_large = $user_node->addChild('image', null);
$image_large->addAttribute('size', 'large');
$user_node->addChild('weight', $row['freq']);
} catch (Exception $e) {}
$i++;
}
return $xml;
}
public static function getTags($artist, $name, $userid, $limit, $cache) {
try {
......
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