aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/directory.c12
-rw-r--r--src/main.c2
-rw-r--r--src/song.c68
3 files changed, 53 insertions, 29 deletions
diff --git a/src/directory.c b/src/directory.c
index a5ef89451..016ce376d 100644
--- a/src/directory.c
+++ b/src/directory.c
@@ -20,13 +20,12 @@
#include "ls.h"
#include "command.h"
-#include "tables.h"
#include "utils.h"
#include "path.h"
#include "log.h"
-#include "playlist.h"
#include "conf.h"
#include "stats.h"
+#include "playlist.h"
#include <string.h>
#include <sys/types.h>
@@ -98,8 +97,6 @@ Directory * newDirectory(Directory * parentDirectory, char * dirname, time_t mti
void freeDirectory(Directory * directory) {
freeDirectoryList(directory->subDirectories);
- removeSongsFromTables(directory->songs);
- deleteSongsFromPlaylist(directory->songs);
freeSongList(directory->songs);
if(directory->utf8name) free(directory->utf8name);
free(directory);
@@ -118,8 +115,6 @@ void removeSongFromDirectory(Directory * directory, char * shortname) {
if(findInList(directory->songs,shortname,&song)) {
LOG("removing: %s\n",((Song *)song)->utf8file);
- removeASongFromTables((Song *)song);
- deleteASongFromPlaylist((Song *)song);
deleteFromList(directory->songs,shortname);
}
}
@@ -153,7 +148,9 @@ int updateInDirectory(Directory * directory, char * shortname, char * name) {
}
else if(mtime!=((Song *)song)->mtime) {
LOG("updating %s\n",name);
- updateSongInfo((Song *)song);
+ if(updateSongInfo((Song *)song)<0) {
+ removeSongFromDirectory(directory,shortname);
+ }
}
}
else if(isDir(name,&mtime)) {
@@ -331,7 +328,6 @@ int addToDirectory(Directory * directory, char * shortname, char * name) {
song = addSongToList(directory->songs,shortname,name);
if(!song) return -1;
LOG("added %s\n",name);
- addSongToTables(song);
return 0;
}
diff --git a/src/main.c b/src/main.c
index 0de23c081..20bb06cbe 100644
--- a/src/main.c
+++ b/src/main.c
@@ -329,6 +329,7 @@ int main(int argc, char * argv[]) {
}
initTables();
+ initPlaylist();
if(!options.dbFile) {
strncpy(directorydb,playlistDir,MAXPATHLEN);
@@ -353,7 +354,6 @@ int main(int argc, char * argv[]) {
initPlayerData();
initVolume();
initInterfaces();
- initPlaylist();
close(STDIN_FILENO);
if(options.daemon) {
diff --git a/src/song.c b/src/song.c
index c269c2e52..374831e9c 100644
--- a/src/song.c
+++ b/src/song.c
@@ -28,6 +28,8 @@
#include "ogg_decode.h"
#include "flac_decode.h"
#include "path.h"
+#include "playlist.h"
+#include "tables.h"
#define SONG_KEY "key: "
#define SONG_FILE "file: "
@@ -41,10 +43,19 @@
#include <stdlib.h>
#include <string.h>
-Song * newSong(char * utf8file) {
+Song * newNullSong() {
Song * song = malloc(sizeof(Song));
+
+ song->tag = NULL;
+ song->utf8file = NULL;
song->time = -1;
+ return song;
+}
+
+Song * newSong(char * utf8file) {
+ Song * song = newNullSong();
+
song->utf8file = strdup(utf8file);
if(0);
@@ -81,11 +92,14 @@ Song * newSong(char * utf8file) {
freeSong(song);
song = NULL;
}
+ else addSongToTables(song);
return song;
}
void freeSong(Song * song) {
+ deleteASongFromPlaylist(song);
+ removeASongFromTables(song);
free(song->utf8file);
if(song->tag) freeMpdTag(song->tag);
free(song);
@@ -163,9 +177,7 @@ void readSongInfoIntoList(FILE * fp, SongList * list) {
free(key);
}
key = strdup(&(buffer[strlen(SONG_KEY)]));
- song = malloc(sizeof(Song));
- song->tag = NULL;
- song->utf8file = NULL;
+ song = newNullSong();
}
else if(0==strncmp(SONG_FILE,buffer,strlen(SONG_FILE))) {
if(!song || song->utf8file) {
@@ -210,32 +222,48 @@ void readSongInfoIntoList(FILE * fp, SongList * list) {
}
int updateSongInfo(Song * song) {
+ char * utf8file = song->utf8file;
+
+ removeASongFromTables(song);
if(song->tag) freeMpdTag(song->tag);
-#ifdef HAVE_MAD
- if(isMp3(song->utf8file,&(song->mtime))) {
- song->tag = mp3TagDup(song->utf8file);
- return 0;
- }
-#endif
+
+ song->time = -1;
+ song->tag = NULL;
+
+ if(0);
#ifdef HAVE_OGG
- if(isOgg(song->utf8file,&(song->mtime))) {
- song->tag = oggTagDup(song->utf8file);
- return 0;
+ else if(isOgg(utf8file,&(song->mtime))) {
+ song->time = getOggTotalTime(
+ rmp2amp(utf8ToFsCharset(utf8file)));
+ if(song->time>=0) song->tag = oggTagDup(utf8file);
}
#endif
#ifdef HAVE_FLAC
- if(isFlac(song->utf8file,&(song->mtime))) {
- song->tag = flacTagDup(song->utf8file);
- return 0;
+ else if((isFlac(utf8file,&(song->mtime)))) {
+ song->time = getFlacTotalTime(
+ rmp2amp(utf8ToFsCharset(utf8file)));
+ if(song->time>=0) song->tag = flacTagDup(utf8file);
+ }
+#endif
+#ifdef HAVE_MAD
+ else if(isMp3(utf8file,&(song->mtime))) {
+ song->time = getMp3TotalTime(
+ rmp2amp(utf8ToFsCharset(utf8file)));
+ if(song->time>=0) song->tag = mp3TagDup(utf8file);
}
#endif
#ifdef HAVE_AUDIOFILE
- if(isWave(song->utf8file,&(song->mtime))) {
- song->tag = audiofileTagDup(song->utf8file);
- return 0;
+ else if(isWave(utf8file,&(song->mtime))) {
+ song->time = getAudiofileTotalTime(
+ rmp2amp(utf8ToFsCharset(utf8file)));
+ if(song->time>=0) song->tag = audiofileTagDup(utf8file);
}
#endif
- return -1;
+
+ if(song->time<0) return -1;
+ else addSongToTables(song);
+
+ return 0;
}
Song * songDup(Song * song) {