Commit d19bc9c5 authored by Mike Sheldon's avatar Mike Sheldon

Add initial implementation of track.getInfo webservice method

parent ae6c4d4d
......@@ -113,6 +113,7 @@ $method_map = array(
'tag.getinfo' => method_tag_getInfo,
'track.addtags' => method_track_addTags,
'track.removetag' => method_track_removeTag,
'track.getinfo' => method_track_getInfo,
'track.gettoptags' => method_track_getTopTags,
'track.gettopfans' => method_track_getTopFans,
'track.gettags' => method_track_getTags,
......@@ -1137,6 +1138,31 @@ function method_track_removeTag() {
}
/**
* track.getinfo : Get general information about a track.
*
* ###Description
* Get further information about this track.
*
* ###Parameters
* * **artist** (required) : Name of the track's artist.
* * **track** (required) : Name of the track.
* * **username** (optional) : User to get track info for (e.g. whether loved or not)
* ---
*
* @package Webservice
* @subpackage Track
* @api
*/
function method_track_getInfo() {
if (!isset($_REQUEST['artist']) || !isset($_REQUEST['track'])) {
report_failure(LFM_INVALID_PARAMS);
}
$xml = TrackXML::getInfo($_REQUEST['artist'], $_REQUEST['track'], $_REQUEST['username']);
respond($xml);
}
/**
* track.gettoptags : Get the top tags for a track.
*
......
......@@ -64,6 +64,33 @@ class TrackXML {
return $xml;
}
public static function getInfo($artist, $name, $username) {
global $adodb;
try {
$track = new Track($name, $artist);
} catch (Exception $e) {
return(XML::error('failed', '7', 'Invalid resource specified'));
}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
$root = $xml->addChild('track', null);
$root->addChild('name', $track->name);
$root->addChild('mbid', $track->mbid);
$root->addChild('url', $track->getURL());
$root->addChild('duration', $track->duration * 1000);
$streamable = $root->addChild('streamable', $track->streamable);
$streamable->addAttribute('fulltrack', $track->streamable);
$root->addChild('listeners', $track->getListenerCount());
$root->addChild('playcount', $track->getPlayCount());
if($username) {
$userid = $adodb->GetOne('SELECT uniqueid FROM Users WHERE '
. 'username = ' . $adodb->qstr($username));
$root->addChild('userloved', $track->isLoved($userid) ? 1 : 0);
}
return $xml;
}
public static function getTopTags($artist, $name, $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