aboutsummaryrefslogtreecommitdiffstats
path: root/src/dbUtils.c
diff options
context:
space:
mode:
authorJ. Alexander Treuman <jat@spatialrift.net>2007-04-25 23:46:11 +0000
committerJ. Alexander Treuman <jat@spatialrift.net>2007-04-25 23:46:11 +0000
commit7a8a9c10e1ea06b6ee2d79da83fa82cbddb5449f (patch)
tree01974e42655e31766eb440f33b72edbd492df599 /src/dbUtils.c
parent7fd9859540ccef194452d3d2ad3e089d7f44123f (diff)
downloadmpd-7a8a9c10e1ea06b6ee2d79da83fa82cbddb5449f.tar.gz
mpd-7a8a9c10e1ea06b6ee2d79da83fa82cbddb5449f.tar.xz
mpd-7a8a9c10e1ea06b6ee2d79da83fa82cbddb5449f.zip
Adding count command. It's usage is identical to find, but instead of
returning a list of matching songs, the number of results and total play time of the results are returned. git-svn-id: https://svn.musicpd.org/mpd/trunk@5950 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/dbUtils.c')
-rw-r--r--src/dbUtils.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/dbUtils.c b/src/dbUtils.c
index 370a38dd6..756431650 100644
--- a/src/dbUtils.c
+++ b/src/dbUtils.c
@@ -38,6 +38,12 @@ typedef struct _LocateTagItemArray {
LocateTagItem *items;
} LocateTagItemArray;
+typedef struct _SearchStats {
+ LocateTagItemArray locateArray;
+ int numberOfSongs;
+ int playTime;
+} SearchStats;
+
static int countSongsInDirectory(int fd, Directory * directory, void *data)
{
int *count = (int *)data;
@@ -120,6 +126,44 @@ int findSongsIn(int fd, char *name, int numItems, LocateTagItem * items)
return traverseAllIn(fd, name, findInDirectory, NULL, (void *)&array);
}
+static void printSearchStats(int fd, SearchStats *stats)
+{
+ fdprintf(fd, "songs: %i\n", stats->numberOfSongs);
+ fdprintf(fd, "playtime: %i\n", stats->playTime);
+}
+
+static int searchStatsInDirectory(int fd, Song * song, void *data)
+{
+ SearchStats *stats = data;
+
+ if (tagItemsFoundAndMatches(song, stats->locateArray.numItems,
+ stats->locateArray.items)) {
+ stats->numberOfSongs++;
+ if (song->tag->time > 0)
+ stats->playTime += song->tag->time;
+ }
+
+ return 0;
+}
+
+int searchStatsForSongsIn(int fd, char *name, int numItems,
+ LocateTagItem * items)
+{
+ SearchStats stats;
+ int ret;
+
+ stats.locateArray.numItems = numItems;
+ stats.locateArray.items = items;
+ stats.numberOfSongs = 0;
+ stats.playTime = 0;
+
+ ret = traverseAllIn(fd, name, searchStatsInDirectory, NULL, &stats);
+ if (ret == 0)
+ printSearchStats(fd, &stats);
+
+ return ret;
+}
+
int printAllIn(int fd, char *name)
{
return traverseAllIn(fd, name, printSongInDirectory,