Merge pull request #197 from chme/mpdstats

[mpd] Implement parts of stats command
This commit is contained in:
ejurgensen 2015-11-07 08:09:14 +01:00
commit ce21134403
3 changed files with 58 additions and 6 deletions

View File

@ -1474,7 +1474,7 @@ db_build_query_count_items(struct query_params *qp, char **q)
if (qp->filter) if (qp->filter)
query = sqlite3_mprintf("SELECT COUNT(*), SUM(song_length) FROM files f WHERE f.disabled = 0 AND %s;", qp->filter); query = sqlite3_mprintf("SELECT COUNT(*), SUM(song_length) FROM files f WHERE f.disabled = 0 AND %s;", qp->filter);
else else
return -1; query = sqlite3_mprintf("SELECT COUNT(*), SUM(song_length) FROM files f WHERE f.disabled = 0;");
if (!query) if (!query)
{ {
@ -2036,6 +2036,18 @@ db_files_get_count(void)
return db_get_count("SELECT COUNT(*) FROM files f WHERE f.disabled = 0;"); return db_get_count("SELECT COUNT(*) FROM files f WHERE f.disabled = 0;");
} }
int
db_files_get_artist_count(void)
{
return db_get_count("SELECT COUNT(DISTINCT songartistid) FROM files f WHERE f.disabled = 0;");
}
int
db_files_get_album_count(void)
{
return db_get_count("SELECT COUNT(DISTINCT songalbumid) FROM files f WHERE f.disabled = 0;");
}
int int
db_files_get_count_bymatch(char *path) db_files_get_count_bymatch(char *path)
{ {

View File

@ -416,6 +416,12 @@ db_query_fetch_string_sort(struct query_params *qp, char **string, char **sortst
int int
db_files_get_count(void); db_files_get_count(void);
int
db_files_get_artist_count(void);
int
db_files_get_album_count(void);
int int
db_files_get_count_bymatch(char *path); db_files_get_count_bymatch(char *path);

View File

@ -869,7 +869,41 @@ mpd_command_status(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
static int static int
mpd_command_stats(struct evbuffer *evbuf, int argc, char **argv, char **errmsg) mpd_command_stats(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
{ {
//TODO implement command stats struct query_params qp;
struct filecount_info fci;
int artists;
int albums;
int ret;
memset(&qp, 0, sizeof(struct query_params));
qp.type = Q_COUNT_ITEMS;
ret = db_query_start(&qp);
if (ret < 0)
{
db_query_end(&qp);
ret = asprintf(errmsg, "Could not start query");
if (ret < 0)
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
return ACK_ERROR_UNKNOWN;
}
ret = db_query_fetch_count(&qp, &fci);
if (ret < 0)
{
db_query_end(&qp);
ret = asprintf(errmsg, "Could not fetch query count");
if (ret < 0)
DPRINTF(E_LOG, L_MPD, "Out of memory\n");
return ACK_ERROR_UNKNOWN;
}
artists = db_files_get_artist_count();
albums = db_files_get_album_count();
//TODO [mpd] Implement missing stats attributes (uptime, db_update, playtime)
evbuffer_add_printf(evbuf, evbuffer_add_printf(evbuf,
"artists: %d\n" "artists: %d\n"
"albums: %d\n" "albums: %d\n"
@ -878,11 +912,11 @@ mpd_command_stats(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
"db_playtime: %d\n" "db_playtime: %d\n"
"db_update: %d\n" "db_update: %d\n"
"playtime: %d\n", "playtime: %d\n",
1, artists,
2, albums,
3, fci.count,
4, 4,
5, (fci.length / 1000),
6, 6,
7); 7);