Commit 629a3768 authored by Mike Sheldon's avatar Mike Sheldon

Add chart.getTopArtists() web service method

parent 109be2cf
...@@ -33,6 +33,7 @@ require_once('../api/TrackXML.php'); ...@@ -33,6 +33,7 @@ require_once('../api/TrackXML.php');
require_once('../api/AlbumXML.php'); require_once('../api/AlbumXML.php');
require_once('../api/TagXML.php'); require_once('../api/TagXML.php');
require_once('../api/LibraryXML.php'); require_once('../api/LibraryXML.php');
require_once('../api/ChartXML.php');
require_once('../data/Server.php'); require_once('../data/Server.php');
require_once('../radio/radio-utils.php'); require_once('../radio/radio-utils.php');
...@@ -123,6 +124,7 @@ $method_map = array( ...@@ -123,6 +124,7 @@ $method_map = array(
'track.unban' => method_track_unban, 'track.unban' => method_track_unban,
'track.updatenowplaying' => method_track_updateNowPlaying, 'track.updatenowplaying' => method_track_updateNowPlaying,
'track.scrobble' => method_track_scrobble, 'track.scrobble' => method_track_scrobble,
'chart.gettopartists' => method_chart_getTopArtists,
); );
/** /**
...@@ -1506,6 +1508,7 @@ function method_track_scrobble() { ...@@ -1506,6 +1508,7 @@ function method_track_scrobble() {
respond($xml); respond($xml);
} }
/** /**
* tag.gettoptags : Get the top tags. * tag.gettoptags : Get the top tags.
* *
...@@ -1652,6 +1655,34 @@ function method_tag_getInfo() { ...@@ -1652,6 +1655,34 @@ function method_tag_getInfo() {
respond($xml); respond($xml);
} }
/**
* chart.gettopartists : Get the most popular artists on the site
*
* ###Description
* Get a list of the artists that have been loved the most on the site.
*
* ###Parameters
* * **page** (optional) : The page to show. Defaults to 1.
* * **limit** (optional) : How many items to show. Defaults to 50.
* * **format** (optional) : Format of response, **xml** or **json**. Default is xml.
* - - -
*
* @package Webservice
* @subpackage Chart
* @api
*/
function method_chart_getTopArtists() {
$limit = get_with_default('limit', 50);
$page = get_with_default('page', 1);
$streamable = True;
$cache = 600;
$xml = ChartXML::getTopArtists($limit, $page, $streamable, $cache);
respond($xml);
}
function get_userid() { function get_userid() {
global $adodb; global $adodb;
......
<?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/Chart.php');
require_once($install_path . '/data/Server.php');
require_once('xml.php');
/**
* Class with functions that returns XML-formatted data for charts.
*
* These functions are mainly used by web service methods.
*
* @package API
*/
class ChartXML {
public static function getTopArtists($limit, $page, $streamable, $cache) {
$offset = ($page - 1) * $limit;
try {
$res = Chart::getTopArtists($limit, $offset, $streamable, $cache);
} catch (Exception $e) {
return XML::error('error', '7', 'Invalid resource specified');
}
$xml = new SimpleXMLElement('<lfm status="ok"></lfm>');
$root = $xml->addChild('artists');
$root->addAttribute('page', $page);
$root->addAttribute('perPage', $limit);
foreach($res as &$row) {
$artist_node = $root->addChild('artist');
$artist = new Artist($row['artist']);
$artist_node->addChild('name', repamp($artist->name));
$artist_node->addChild('mbid', $artist->mbid);
$artist_node->addChild('url', $artist->getURL());
$artist_node->addChild('streamable', $artist->streamable);
$image_small = $artist_node->addChild('image', repamp($artist->image_small));
$image_small->addAttribute('size', 'small');
$image_medium = $artist_node->addChild('image', repamp($artist->image_medium));
$image_medium->addAttribute('size', 'medium');
$image_large = $artist_node->addChild('image', repamp($artist->image_large));
$image_large->addAttribute('size', 'large');
}
return $xml;
}
}
<?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/sanitize.php');
require_once($install_path . '/data/Artist.php');
require_once($install_path . '/data/Server.php');
/**
* Represents chart data
*/
class Chart {
/**
* Get the site's top artists
*
* @param int $limit The number of artists to return
* @param int $offset Skip this number of rows before returning artists
* @param bool $streamable Only return streamable artists
* @param int $begin Only use scrobbles with time higher than this timestamp
* @param int $end Only use scrobbles with time lower than this timestamp
* @param int $cache Caching period in seconds
* @return array An array of artists ((artist, freq, artisturl) ..) or empty array in case of failure
*/
function getTopArtists($limit = 20, $offset = 0, $streamable = False, $begin = null, $end = null, $cache = 600) {
return Server::getTopArtists($limit, $offset, $streamable, $begin, $end, null, $cache);
}
}
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