mirror of
https://github.com/owntone/owntone-server.git
synced 2024-12-27 07:35:57 -05:00
Merge pull request #197 from chme/mpdstats
[mpd] Implement parts of stats command
This commit is contained in:
commit
ce21134403
14
src/db.c
14
src/db.c
@ -1474,7 +1474,7 @@ db_build_query_count_items(struct query_params *qp, char **q)
|
||||
if (qp->filter)
|
||||
query = sqlite3_mprintf("SELECT COUNT(*), SUM(song_length) FROM files f WHERE f.disabled = 0 AND %s;", qp->filter);
|
||||
else
|
||||
return -1;
|
||||
query = sqlite3_mprintf("SELECT COUNT(*), SUM(song_length) FROM files f WHERE f.disabled = 0;");
|
||||
|
||||
if (!query)
|
||||
{
|
||||
@ -2036,6 +2036,18 @@ db_files_get_count(void)
|
||||
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
|
||||
db_files_get_count_bymatch(char *path)
|
||||
{
|
||||
|
6
src/db.h
6
src/db.h
@ -416,6 +416,12 @@ db_query_fetch_string_sort(struct query_params *qp, char **string, char **sortst
|
||||
int
|
||||
db_files_get_count(void);
|
||||
|
||||
int
|
||||
db_files_get_artist_count(void);
|
||||
|
||||
int
|
||||
db_files_get_album_count(void);
|
||||
|
||||
int
|
||||
db_files_get_count_bymatch(char *path);
|
||||
|
||||
|
44
src/mpd.c
44
src/mpd.c
@ -869,7 +869,41 @@ mpd_command_status(struct evbuffer *evbuf, int argc, char **argv, char **errmsg)
|
||||
static int
|
||||
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,
|
||||
"artists: %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_update: %d\n"
|
||||
"playtime: %d\n",
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
artists,
|
||||
albums,
|
||||
fci.count,
|
||||
4,
|
||||
5,
|
||||
(fci.length / 1000),
|
||||
6,
|
||||
7);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user