Commit 3ef41f80 authored by Jonas Haraldsson's avatar Jonas Haraldsson

track.removetag

parent ceafdf29
......@@ -109,6 +109,7 @@ $method_map = array(
'tag.gettoptracks' => method_tag_getTopTracks,
'tag.getinfo' => method_tag_getInfo,
'track.addtags' => method_track_addTags,
'track.removetag' => method_track_removeTag,
'track.gettoptags' => method_track_getTopTags,
'track.gettags' => method_track_getTags,
'track.ban' => method_track_ban,
......@@ -1003,8 +1004,8 @@ function method_radio_getPlaylist() {
* Add tags to a track using a comma-separated list of tags.
*
* ###Parameters
* * **artist** (required) : Name of the tracks's artist.
* * **track** (required) : Name of the tracks.
* * **artist** (required) : Name of the track's artist.
* * **track** (required) : Name of the track.
* * **tags** (required) : Comma-separated list of tags.
* * **sk** (required) : Session key.
* * **album** (optional) : Name of the tracks's album.
......@@ -1030,6 +1031,40 @@ function method_track_addTags() {
respond($xml);
}
/**
* track.removetag : Remove tag from a track.
*
* ###Description
* Remove a tag from a track.
*
* ###Parameters
* * **artist** (required) : Name of the track's artist.
* * **track** (required) : Name of the track.
* * **tag** (required) : Name of tag.
* * **sk** (required) : Session key.
* * **format** (optional) : Format of response, **xml** or **json**. Default is xml.
*
* ###Additional info
* **This method requires authentication**.
*
* **HTTP request method** : POST.
* - - -
*
* @package Webservice
* @subpackage Track
* @api
*/
function method_track_removeTag() {
if (!isset($_POST['artist']) || !isset($_POST['track']) || !isset($_POST['tag'])) {
report_failure(LFM_INVALID_PARAMS);
}
$userid = get_userid();
$xml = TrackXML::removeTag($userid, $_POST['artist'], $_POST['track'], $_POST['tag']);
respond($xml);
}
/**
* track.gettoptags : Get the top tags for a track.
*
......
......@@ -43,6 +43,18 @@ class TrackXML {
return $xml;
}
public static function removeTag($userid, $artist, $trackName, $tag) {
try {
$track = new Track($trackName, $artist);
$track->removeTag($tag, $userid);
} catch (Exception $e) {
return(XML::error('failed', '7', 'Invalid resource specified'));
}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
return $xml;
}
public static function getTopTags($artist, $name, $limit, $cache) {
try {
......
......@@ -345,4 +345,27 @@ class Track {
} catch (Exception $e) {}
}
}
/**
* Remove a tag from a track
*
* @param string $tag The tag to be removed
* @param int $userid The user removing the tag
*/
function removeTag($tag, $userid) {
global $adodb;
$tag = trim($tag);
if(strlen($tag) == 0) {
return;
}
$query = 'DELETE FROM Tags WHERE tag = ? AND lower(artist) = lower(?) AND lower(track) = lower(?) AND userid = ?';
$params = array($tag, $this->artist_name, $this->name, $userid);
try {
$adodb->Execute($query, $params);
} catch (Exception $e) {
reportError($e->getMessage(), $e->getTraceAsString());
}
}
}
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