aboutsummaryrefslogtreecommitdiffstats
path: root/src/directory.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-02-27 15:39:19 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-02-27 15:39:19 +0000
commit79effd62e14c8c524552ae578d593750b038004a (patch)
tree588b6370288aacf1b05a92b951192f4a38c62084 /src/directory.c
parenta78c5e4aea595cf2275da31e46e0d7174d1d8615 (diff)
downloadmpd-79effd62e14c8c524552ae578d593750b038004a.tar.gz
mpd-79effd62e14c8c524552ae578d593750b038004a.tar.xz
mpd-79effd62e14c8c524552ae578d593750b038004a.zip
display db_playtime in stats
git-svn-id: https://svn.musicpd.org/mpd/trunk@98 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/directory.c')
-rw-r--r--src/directory.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/directory.c b/src/directory.c
index c933a9f0c..9f85f2683 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -477,6 +477,7 @@ int writeDirectoryDB() {
sortDirectory(mp3rootDirectory);
stats.numberOfSongs = countSongsIn(stderr,NULL);
+ stats.dbPlayTime = sumSongTimesIn(stderr,NULL);
while(!(fp=fopen(directorydb,"w")) && errno==EINTR);
if(!fp) return -1;
@@ -570,6 +571,7 @@ int readDirectoryDB() {
while(fclose(fp) && errno==EINTR);
stats.numberOfSongs = countSongsIn(stderr,NULL);
+ stats.dbPlayTime = sumSongTimesIn(stderr,NULL);
return 0;
}
@@ -777,6 +779,14 @@ int directoryPrintSongInfo(FILE * fp, Song * song, void * data) {
return printSongInfo(fp,song);
}
+int sumSongTime(FILE * fp, Song * song, void * data) {
+ unsigned long * time = (unsigned long *)data;
+
+ if(song->tag && song->tag->time>=0) *time+=song->tag->time;
+
+ return 0;
+}
+
int printInfoForAllIn(FILE * fp, char * name) {
return traverseAllIn(fp,name,directoryPrintSongInfo,NULL,NULL);
}
@@ -790,6 +800,15 @@ int countSongsIn(FILE * fp, char * name) {
return count;
}
+unsigned long sumSongTimesIn(FILE * fp, char * name) {
+ unsigned long dbPlayTime = 0;
+ void * ptr = (void *)&dbPlayTime;
+
+ traverseAllIn(fp,name,sumSongTime,NULL,ptr);
+
+ return dbPlayTime;
+}
+
void initMp3Directory() {
mp3rootDirectory = newDirectory(NULL,NULL,0);
exploreDirectory(mp3rootDirectory);