diff options
author | Warren Dukes <warren.dukes@gmail.com> | 2004-03-10 09:55:54 +0000 |
---|---|---|
committer | Warren Dukes <warren.dukes@gmail.com> | 2004-03-10 09:55:54 +0000 |
commit | 68dc3517a63ae26bdd34d2ebcb9c48d5fe099714 (patch) | |
tree | 029287856e36e3920d9021a7d1ce17699bcb5cc0 /src/song.c | |
parent | e5e45242e03811a42d8bb98cc5ff5024a21a261a (diff) | |
download | mpd-68dc3517a63ae26bdd34d2ebcb9c48d5fe099714.tar.gz mpd-68dc3517a63ae26bdd34d2ebcb9c48d5fe099714.tar.xz mpd-68dc3517a63ae26bdd34d2ebcb9c48d5fe099714.zip |
move adding and removeing from tables from directory.c to song.c
git-svn-id: https://svn.musicpd.org/mpd/trunk@239 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/song.c')
-rw-r--r-- | src/song.c | 68 |
1 files changed, 48 insertions, 20 deletions
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) { |