diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/directory.c | 19 | ||||
-rw-r--r-- | src/directory.h | 2 | ||||
-rw-r--r-- | src/stats.c | 1 | ||||
-rw-r--r-- | src/stats.h | 1 |
4 files changed, 23 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); diff --git a/src/directory.h b/src/directory.h index 925bb5e22..d6813d365 100644 --- a/src/directory.h +++ b/src/directory.h @@ -50,6 +50,8 @@ int findSongsIn(FILE * fp, char * name, char * item, char * string); int countSongsIn(FILE * fp, char * name); +unsigned long sumSongTimesIn(FILE * fp, char * name); + Song * getSong(char * file); time_t getDbModTime(); diff --git a/src/stats.c b/src/stats.c index 3d018ee0b..63ca87503 100644 --- a/src/stats.c +++ b/src/stats.c @@ -41,6 +41,7 @@ int printStats(FILE * fp) { myfprintf(fp,"songs: %i\n",stats.numberOfSongs); myfprintf(fp,"uptime: %li\n",time(NULL)-stats.daemonStart); myfprintf(fp,"playtime: %li\n",(long)(getPlayerTotalPlayTime()+0.5)); + myfprintf(fp,"db_playtime: %li\n",stats.dbPlayTime); /*myfprintf(fp,"songs_played: %li\n",stats.songsPlayed);*/ myfprintf(fp,"db_update: %li\n",getDbModTime()); return 0; diff --git a/src/stats.h b/src/stats.h index d059db014..383a8db65 100644 --- a/src/stats.h +++ b/src/stats.h @@ -24,6 +24,7 @@ typedef struct _Stats { unsigned long daemonStart; int numberOfSongs; + unsigned long dbPlayTime; /*unsigned long playTime; unsigned long songsPlayed;*/ } Stats; |