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( ...@@ -79,6 +79,7 @@ $method_map = array(
'radio.getplaylist' => method_radio_getPlaylist, 'radio.getplaylist' => method_radio_getPlaylist,
'track.gettoptags' => method_track_getTopTags, 'track.gettoptags' => method_track_getTopTags,
'track.gettags' => method_track_getTags, 'track.gettags' => method_track_getTags,
'track.ban' => method_track_ban,
); );
function method_user_getrecenttracks() { function method_user_getrecenttracks() {
...@@ -406,13 +407,38 @@ function method_track_getTopTags() { ...@@ -406,13 +407,38 @@ function method_track_getTopTags() {
function method_track_getTags() { function method_track_getTags() {
global $adodb; 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); report_failure(LFM_INVALID_PARAMS);
} }
$username = $adodb->GetOne('SELECT username FROM Auth WHERE ' $username = $adodb->GetOne('SELECT username FROM Auth WHERE '
. 'token = ' . $adodb->qstr($_GET['token']) . ' AND ' . '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) { if (!$username) {
report_failure(LFM_INVALID_SESSION); report_failure(LFM_INVALID_SESSION);
...@@ -421,11 +447,9 @@ function method_track_getTags() { ...@@ -421,11 +447,9 @@ function method_track_getTags() {
$userid = $adodb->GetOne('SELECT uniqueid FROM Users WHERE ' $userid = $adodb->GetOne('SELECT uniqueid FROM Users WHERE '
. 'username = ' . $adodb->qstr($username)); . 'username = ' . $adodb->qstr($username));
header('Content-Type: text/xml'); return $userid;
print(XML::prettyXML(TrackXML::getTags($_GET['artist'], $_GET['track'], $userid)));
} }
function valid_api_key($key) { function valid_api_key($key) {
return strlen($key) == 32; return strlen($key) == 32;
} }
......
...@@ -43,11 +43,9 @@ class TrackXML { ...@@ -43,11 +43,9 @@ class TrackXML {
$tag_node->addChild('url', repamp($base_url . '/tag/' . $tag['tag'])); $tag_node->addChild('url', repamp($base_url . '/tag/' . $tag['tag']));
} }
return($xml); return $xml;
} }
public static function getTags($artist, $name, $userid) { public static function getTags($artist, $name, $userid) {
global $base_url; global $base_url;
...@@ -66,8 +64,22 @@ class TrackXML { ...@@ -66,8 +64,22 @@ class TrackXML {
$tag_node->addChild('url', repamp($base_url . '/tag/' . $tag['tag'])); $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