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

Commit fba8edea authored by Mike Sheldon's avatar Mike Sheldon

Implement album.getTopTags web service method

parent 52e2a226
......@@ -23,6 +23,7 @@ require_once('../database.php');
require_once('../api/ArtistXML.php');
require_once('../api/UserXML.php');
require_once('../api/TrackXML.php');
require_once('../api/AlbumXML.php');
# Error constants
define('LFM_INVALID_SERVICE', 2);
......@@ -72,6 +73,7 @@ $method_map = array(
'artist.getinfo' => method_artist_getInfo,
'artist.gettoptracks' => method_artist_getTopTracks,
'artist.gettoptags' => method_artist_getTopTags,
'album.gettoptags' => method_album_getTopTags,
'user.getinfo' => method_user_getInfo,
'user.gettoptracks' => method_user_getTopTracks,
'user.getrecenttracks' => method_user_getRecentTracks,
......@@ -172,6 +174,20 @@ function method_artist_getTopTags() {
print(XML::prettyXML(ArtistXML::getTopTags($_GET['artist'])));
}
/**
* Album methods
*/
function method_album_getTopTags() {
if (!isset($_GET['artist']) || !isset($_GET['album'])) {
report_failure(LFM_INVALID_PARAMS);
}
header('Content-Type: text/xml');
print(XML::prettyXML(AlbumXML::getTopTags($_GET['artist'], $_GET['album'])));
}
/**
* Authentication methods
*/
......
<?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/Album.php');
require_once('xml.php');
class AlbumXML {
public static function getTopTags($artist, $album) {
$album = new Album($album, $artist);
if (!$album) {
return(XML::error('failed', '7', 'Invalid resource specified'));
}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
$root = $xml->addChild('toptags', null);
$root->addAttribute('artist', $album->artist_name);
$root->addAttribute('album', $album->name);
$tags = $album->getTopTags();
foreach($tags as &$tag) {
$tag_node = $root->addChild('tag', null);
$tag_node->addChild('name', repamp($tag['tag']));
$tag_node->addChild('count', $tag['freq']);
$tag_node->addChild('url', Server::getTagURL($tag['tag']));
}
return $xml;
}
}
?>
......@@ -90,7 +90,6 @@ class ArtistXML {
}
public static function getTopTags($artistName) {
global $base_url;
$artist = new Artist($artistName);
......
<?php
require_once('API.php');
class album extends API {
public static function getInfo($params) {
$required = array('api_key' => 'string');
$optional = array('artist' => 'string', 'album' => 'string', 'mbid' => 'string', 'lang' => 'string');
$this->checkParams($params, $required);
}
}
?>
......@@ -122,6 +122,25 @@ class Album {
return Server::getAlbumURL($this->artist_name, $this->name);
}
/**
* Get an albums's most used tags
*
* @param int $limit The number of tags to return (defaults to 10)
* @return An array of tags
*/
function getTopTags($limit=10) {
global $adodb;
$res = $adodb->CacheGetAll(600, 'SELECT tag, COUNT(tag) AS freq FROM tags WHERE '
. ' artist = ' . $adodb->qstr($this->artist_name)
. ' AND album = ' . $adodb->qstr($this->name)
. ' GROUP BY tag ORDER BY freq DESC '
. ' LIMIT ' . $limit);
return $res;
}
/*
* Return Album Art URL from Wikipedia
* @param string Album
......
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