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

Commit bed38734 authored by Mike Sheldon's avatar Mike Sheldon

Implement track.ban() web service method so that users can ban tracks from streaming clients

parent 8466c294
......@@ -79,6 +79,7 @@ $method_map = array(
'radio.getplaylist' => method_radio_getPlaylist,
'track.gettoptags' => method_track_getTopTags,
'track.gettags' => method_track_getTags,
'track.ban' => method_track_ban,
);
function method_user_getrecenttracks() {
......@@ -406,13 +407,38 @@ function method_track_getTopTags() {
function method_track_getTags() {
global $adodb;
if (!isset($_GET['artist']) || !isset($_GET['track']) || !isset($_GET['sk']) || !isset($_GET['token'])) {
if (!isset($_GET['artist']) || !isset($_GET['track'])) {
report_failure(LFM_INVALID_PARAMS);
}
$userid = get_userid();
header('Content-Type: text/xml');
print(XML::prettyXML(TrackXML::getTags($_GET['artist'], $_GET['track'], $userid)));
}
function method_track_ban() {
if (!isset($_GET['artist']) || !isset($_GET['track'])) {
report_failure(LFM_INVALID_PARAMS);
}
$userid = get_userid();
header('Content-Type: text/xml');
print(XML::prettyXML(TrackXML::ban($_GET['artist'], $_GET['track'], $userid)));
}
function get_userid() {
global $adodb;
if (!isset($_GET['sk']) || !isset($_GET['token'])) {
report_failure(LFM_INVALID_PARAMS);
}
$username = $adodb->GetOne('SELECT username FROM Auth WHERE '
. 'token = ' . $adodb->qstr($_GET['token']) . ' AND '
. 'username IS NOT NULL AND sk = '.$adodb->qstr($_GET['sk']));
. 'username IS NOT NULL AND sk = '.$adodb->qstr($_GET['sk']));
if (!$username) {
report_failure(LFM_INVALID_SESSION);
......@@ -421,11 +447,9 @@ function method_track_getTags() {
$userid = $adodb->GetOne('SELECT uniqueid FROM Users WHERE '
. 'username = ' . $adodb->qstr($username));
header('Content-Type: text/xml');
print(XML::prettyXML(TrackXML::getTags($_GET['artist'], $_GET['track'], $userid)));
return $userid;
}
function valid_api_key($key) {
return strlen($key) == 32;
}
......
......@@ -43,11 +43,9 @@ class TrackXML {
$tag_node->addChild('url', repamp($base_url . '/tag/' . $tag['tag']));
}
return($xml);
return $xml;
}
public static function getTags($artist, $name, $userid) {
global $base_url;
......@@ -66,8 +64,22 @@ class TrackXML {
$tag_node->addChild('url', repamp($base_url . '/tag/' . $tag['tag']));
}
return($xml);
return $xml;
}
public static function ban($artist, $name, $userid) {
global $adodb;
try {
$res = $adodb->Execute("INSERT INTO banned_tracks VALUES ("
. $userid . ', '
. $adodb->qstr($name) . ', '
. $adodb->qstr($artist) . ")");
} catch (exception $ex) {}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
return $xml;
}
}
......
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