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

Commit 967e0ef9 authored by Mike Sheldon's avatar Mike Sheldon

Add web service method for retrieving a user's loved tracks

parent 4d241975
......@@ -75,6 +75,7 @@ $method_map = array(
'user.gettoptracks' => method_user_gettoptracks,
'user.getrecenttracks' => method_user_getrecenttracks,
'user.gettoptags' => method_user_gettoptags,
'user.getlovedtracks' => method_user_getLovedTracks,
'radio.tune' => method_radio_tune,
'radio.getplaylist' => method_radio_getPlaylist,
'track.gettoptags' => method_track_getTopTags,
......@@ -83,6 +84,11 @@ $method_map = array(
'track.love' => method_track_love,
);
/**
* User methods
*/
function method_user_getrecenttracks() {
if (!isset($_GET['user'])) {
report_failure(LFM_INVALID_SIGNATURE);
......@@ -119,6 +125,29 @@ function method_user_getinfo() {
print(XML::prettyXML(UserXML::getInfo($_GET['user'])));
}
function method_user_getLovedTracks() {
if (!isset($_GET['user'])) {
report_failure(LFM_INVALID_PARAMS);
}
$user = $_GET['user'];
if (isset($_GET['limit'])) {
$limit = $_GET['limit'];
} else {
$limit = 50;
}
header('Content-Type: text/xml');
print(XML::prettyXML(UserXML::getLovedTracks($user, $limit)));
}
/**
* Artist methods
*/
function method_artist_getinfo() {
if (!isset($_GET['artist'])) {
report_failure(LFM_INVALID_SIGNATURE);
......
......@@ -163,5 +163,35 @@ class UserXML {
return $xml;
}
public static function getLovedTracks($u, $limit=50) {
try {
$user = new User($u);
$res = $user->getLovedTracks($limit);
} catch (exception $ex) {
return XML::error('error', '7', 'Invalid resource specified');
}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
$root = $xml->addChild('lovedtracks');
$root->addAttribute('user', $user->name);
foreach($res as &$row) {
$track = new Track($row['track'], $row['artist']);
$artist = new Artist($row['artist']);
$track_node = $root->addChild('track', null);
$track_node->addChild('name', $track->name);
$track_node->addChild('mbid', $track->mbid);
$track_node->addChild('url', $track->getURL());
$artist_node = $track_node->addChild('artist', null);
$artist_node->addChild('name', $artist->name);
$artist_node->addChild('mbid', $artist->mbid);
$artist_node->addChild('url', $artist->getURL);
}
return $xml;
}
}
?>
......@@ -289,7 +289,7 @@ class User {
/**
* Get a user's most used tags
*
* @param int $limit The number of tags to return (default to 10)
* @param int $limit The number of tags to return (defaults to 10)
* @return An array of tag details
*/
function getTopTags($limit=10) {
......@@ -302,4 +302,20 @@ class User {
return $res;
}
/**
* Get a user's loved tracks
*
* @param int $limit The number of tracks to return (defaults to 50)
* @return An array of track details
*/
function getLovedTracks($limit=50) {
global $adodb;
$res = $adodb->CacheGetAll(600, 'SELECT * FROM Loved_Tracks WHERE '
. ' userid = ' . $this->uniqueid
. ' LIMIT ' . $limit);
return $res;
}
}
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