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

Commit c9dae8ac authored by Mike Sheldon's avatar Mike Sheldon

Add the track.getTags() web service method

parent 5bb96cd9
......@@ -22,6 +22,7 @@
require_once('../database.php');
require_once('../api/ArtistXML.php');
require_once('../api/UserXML.php');
require_once('../api/TrackXML.php');
# Error constants
define('LFM_INVALID_SERVICE', 2);
......@@ -75,7 +76,7 @@ $method_map = array(
'user.getrecenttracks' => method_user_getrecenttracks,
'radio.tune' => method_radio_tune,
'radio.getplaylist' => method_radio_getPlaylist,
'track.gettags' => method_track_getTags,
);
function method_user_getrecenttracks() {
......@@ -377,6 +378,19 @@ $adodb->SetFetchMode(ADODB_FETCH_ASSOC);
}
/**
* Track methods
*/
function method_track_getTags() {
if (!isset($_GET['artist']) || !isset($_GET['track'])) {
report_failure(LFM_INVALID_SIGNATURE);
}
header('Content-Type: text/xml');
print(XML::prettyXML(TrackXML::getTags($_GET['artist'], $_GET['track'])));
}
function valid_api_key($key) {
return strlen($key) == 32;
......
<?php
/* GNU FM -- a free network service for sharing your music listening habits
Copyright (C) 2009 Free Software Foundation, Inc
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require_once($install_path . '/database.php');
require_once($install_path . '/data/Track.php');
require_once('xml.php');
class TrackXML {
public static function getTags($artist, $name) {
$track = new Track($name, $artist);
$tags = $track->getTags();
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
$root = $xml->addChild('tags', null);
$root->addAttribute('artist', $artist);
$root->addAttribute('track', $name);
foreach($tags as $tag) {
$tag_node = $root->addChild('tag', null);
$tag_node->addChild('name', repamp($tag));
}
return($xml);
}
}
?>
......@@ -149,4 +149,24 @@ class Track {
return Server::getTrackURL($this->artist_name, $this->album_name, $this->name);
}
/**
* Retrieve the tags for this track.
*
* @return An array of tag names
*/
function getTags() {
global $adodb;
$adodb->SetFetchMode(ADODB_FETCH_ASSOC);
$res = $adodb->CacheGetAll(600, 'SELECT COUNT(track) AS freq, tag FROM tags WHERE'
. ' artist = ' . $adodb->qstr($this->artist_name)
. ' AND track = ' . $adodb->qstr($this->name)
. ' GROUP BY tag ORDER BY freq DESC');
foreach($res as &$row) {
$tags[] = $row['tag'];
}
return $tags;
}
}
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