top artits & tracks

This commit is contained in:
n 2015-09-28 22:41:12 +02:00
parent e1f8735b5c
commit df0f7a5186
3 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,36 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.artisttracks.php
* Type: function
* Name: artisttracks
* Purpose: outputs an array of tracks by $artist
* -------------------------------------------------------------
*/
function smarty_function_topartists($params, $template) {
/**
* Retrieves a list of tracks
*
* @param string $artist The name of the artist (required)
* @param string $album The name of the album (optional)
* @return array artisttracks
*/
global $adodb;
$query = 'SELECT artist AS name,COUNT(artist) AS plays FROM Scrobbles WHERE time > '.strtotime("-3 month").' GROUP BY artist ORDER BY COUNT(artist) DESC LIMIT 15';
$data = $adodb->CacheGetAll(600, $query);
/*foreach($data as &$item) {
$item['trackurl'] = Server::getTrackURL($artist, null, $item['track']);
if (!$item['image']) {
$item['image'] = $default_album_image;
} else {
$item['image'] = resolve_external_url($item['image']);
}
}*/
$template->assign(topartists, $data);
}
?>

View File

@ -0,0 +1,36 @@
<?php
/*
* Smarty plugin
* -------------------------------------------------------------
* File: function.artisttracks.php
* Type: function
* Name: artisttracks
* Purpose: outputs an array of tracks by $artist
* -------------------------------------------------------------
*/
function smarty_function_toptracks($params, $template) {
/**
* Retrieves a list of tracks
*
* @param string $artist The name of the artist (required)
* @param string $album The name of the album (optional)
* @return array artisttracks
*/
global $adodb;
$query = 'SELECT artist AS artist,track AS name,count(track) AS plays FROM Scrobbles WHERE time > '.strtotime("-3 month").' GROUP BY track ORDER BY COUNT(track) DESC LIMIT 15';
$data = $adodb->CacheGetAll(600, $query);
/*foreach($data as &$item) {
$item['trackurl'] = Server::getTrackURL($artist, null, $item['track']);
if (!$item['image']) {
$item['image'] = $default_album_image;
} else {
$item['image'] = resolve_external_url($item['image']);
}
}*/
$template->assign(toptracks, $data);
}
?>

View File

@ -19,6 +19,22 @@
<h3>Recent plays</h3>
{include file="tracklist.tpl" class=#table# items=$userscrobbles fimage=true fstream=true fartist=true flove=true ftime=true}
{topartists userid=$me->uniqueid limit=10}
<h3>Top Artists</h3>
<ul>
{section name=i loop=$topartists}
<li>{$topartists[i].name} {$topartists[i].plays}</li>
{/section}
</ul>
{toptracks userid=$me->uniqueid limit=10}
<h3>Top Tracks</h3>
<ul>
{section name=i loop=$toptracks}
<li>{$toptracks[i].artist} - {$toptracks[i].name} {$toptracks[i].plays}</li>
{/section}
</ul>
{if !empty($lovedArtists)}
<br />
<h3>{t name=$me->name}Free artists that %1 loves{/t}</h3>