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
This commit is contained in:
parent
e5e45242e0
commit
68dc3517a6
|
@ -20,13 +20,12 @@
|
||||||
|
|
||||||
#include "ls.h"
|
#include "ls.h"
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
#include "tables.h"
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "playlist.h"
|
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "stats.h"
|
#include "stats.h"
|
||||||
|
#include "playlist.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -98,8 +97,6 @@ Directory * newDirectory(Directory * parentDirectory, char * dirname, time_t mti
|
||||||
|
|
||||||
void freeDirectory(Directory * directory) {
|
void freeDirectory(Directory * directory) {
|
||||||
freeDirectoryList(directory->subDirectories);
|
freeDirectoryList(directory->subDirectories);
|
||||||
removeSongsFromTables(directory->songs);
|
|
||||||
deleteSongsFromPlaylist(directory->songs);
|
|
||||||
freeSongList(directory->songs);
|
freeSongList(directory->songs);
|
||||||
if(directory->utf8name) free(directory->utf8name);
|
if(directory->utf8name) free(directory->utf8name);
|
||||||
free(directory);
|
free(directory);
|
||||||
|
@ -118,8 +115,6 @@ void removeSongFromDirectory(Directory * directory, char * shortname) {
|
||||||
|
|
||||||
if(findInList(directory->songs,shortname,&song)) {
|
if(findInList(directory->songs,shortname,&song)) {
|
||||||
LOG("removing: %s\n",((Song *)song)->utf8file);
|
LOG("removing: %s\n",((Song *)song)->utf8file);
|
||||||
removeASongFromTables((Song *)song);
|
|
||||||
deleteASongFromPlaylist((Song *)song);
|
|
||||||
deleteFromList(directory->songs,shortname);
|
deleteFromList(directory->songs,shortname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,7 +148,9 @@ int updateInDirectory(Directory * directory, char * shortname, char * name) {
|
||||||
}
|
}
|
||||||
else if(mtime!=((Song *)song)->mtime) {
|
else if(mtime!=((Song *)song)->mtime) {
|
||||||
LOG("updating %s\n",name);
|
LOG("updating %s\n",name);
|
||||||
updateSongInfo((Song *)song);
|
if(updateSongInfo((Song *)song)<0) {
|
||||||
|
removeSongFromDirectory(directory,shortname);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(isDir(name,&mtime)) {
|
else if(isDir(name,&mtime)) {
|
||||||
|
@ -331,7 +328,6 @@ int addToDirectory(Directory * directory, char * shortname, char * name) {
|
||||||
song = addSongToList(directory->songs,shortname,name);
|
song = addSongToList(directory->songs,shortname,name);
|
||||||
if(!song) return -1;
|
if(!song) return -1;
|
||||||
LOG("added %s\n",name);
|
LOG("added %s\n",name);
|
||||||
addSongToTables(song);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -329,6 +329,7 @@ int main(int argc, char * argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
initTables();
|
initTables();
|
||||||
|
initPlaylist();
|
||||||
|
|
||||||
if(!options.dbFile) {
|
if(!options.dbFile) {
|
||||||
strncpy(directorydb,playlistDir,MAXPATHLEN);
|
strncpy(directorydb,playlistDir,MAXPATHLEN);
|
||||||
|
@ -353,7 +354,6 @@ int main(int argc, char * argv[]) {
|
||||||
initPlayerData();
|
initPlayerData();
|
||||||
initVolume();
|
initVolume();
|
||||||
initInterfaces();
|
initInterfaces();
|
||||||
initPlaylist();
|
|
||||||
|
|
||||||
close(STDIN_FILENO);
|
close(STDIN_FILENO);
|
||||||
if(options.daemon) {
|
if(options.daemon) {
|
||||||
|
|
68
src/song.c
68
src/song.c
|
@ -28,6 +28,8 @@
|
||||||
#include "ogg_decode.h"
|
#include "ogg_decode.h"
|
||||||
#include "flac_decode.h"
|
#include "flac_decode.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
#include "playlist.h"
|
||||||
|
#include "tables.h"
|
||||||
|
|
||||||
#define SONG_KEY "key: "
|
#define SONG_KEY "key: "
|
||||||
#define SONG_FILE "file: "
|
#define SONG_FILE "file: "
|
||||||
|
@ -41,10 +43,19 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
Song * newSong(char * utf8file) {
|
Song * newNullSong() {
|
||||||
Song * song = malloc(sizeof(Song));
|
Song * song = malloc(sizeof(Song));
|
||||||
|
|
||||||
|
song->tag = NULL;
|
||||||
|
song->utf8file = NULL;
|
||||||
song->time = -1;
|
song->time = -1;
|
||||||
|
|
||||||
|
return song;
|
||||||
|
}
|
||||||
|
|
||||||
|
Song * newSong(char * utf8file) {
|
||||||
|
Song * song = newNullSong();
|
||||||
|
|
||||||
song->utf8file = strdup(utf8file);
|
song->utf8file = strdup(utf8file);
|
||||||
|
|
||||||
if(0);
|
if(0);
|
||||||
|
@ -81,11 +92,14 @@ Song * newSong(char * utf8file) {
|
||||||
freeSong(song);
|
freeSong(song);
|
||||||
song = NULL;
|
song = NULL;
|
||||||
}
|
}
|
||||||
|
else addSongToTables(song);
|
||||||
|
|
||||||
return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
|
||||||
void freeSong(Song * song) {
|
void freeSong(Song * song) {
|
||||||
|
deleteASongFromPlaylist(song);
|
||||||
|
removeASongFromTables(song);
|
||||||
free(song->utf8file);
|
free(song->utf8file);
|
||||||
if(song->tag) freeMpdTag(song->tag);
|
if(song->tag) freeMpdTag(song->tag);
|
||||||
free(song);
|
free(song);
|
||||||
|
@ -163,9 +177,7 @@ void readSongInfoIntoList(FILE * fp, SongList * list) {
|
||||||
free(key);
|
free(key);
|
||||||
}
|
}
|
||||||
key = strdup(&(buffer[strlen(SONG_KEY)]));
|
key = strdup(&(buffer[strlen(SONG_KEY)]));
|
||||||
song = malloc(sizeof(Song));
|
song = newNullSong();
|
||||||
song->tag = NULL;
|
|
||||||
song->utf8file = NULL;
|
|
||||||
}
|
}
|
||||||
else if(0==strncmp(SONG_FILE,buffer,strlen(SONG_FILE))) {
|
else if(0==strncmp(SONG_FILE,buffer,strlen(SONG_FILE))) {
|
||||||
if(!song || song->utf8file) {
|
if(!song || song->utf8file) {
|
||||||
|
@ -210,32 +222,48 @@ void readSongInfoIntoList(FILE * fp, SongList * list) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int updateSongInfo(Song * song) {
|
int updateSongInfo(Song * song) {
|
||||||
|
char * utf8file = song->utf8file;
|
||||||
|
|
||||||
|
removeASongFromTables(song);
|
||||||
if(song->tag) freeMpdTag(song->tag);
|
if(song->tag) freeMpdTag(song->tag);
|
||||||
#ifdef HAVE_MAD
|
|
||||||
if(isMp3(song->utf8file,&(song->mtime))) {
|
song->time = -1;
|
||||||
song->tag = mp3TagDup(song->utf8file);
|
song->tag = NULL;
|
||||||
return 0;
|
|
||||||
}
|
if(0);
|
||||||
#endif
|
|
||||||
#ifdef HAVE_OGG
|
#ifdef HAVE_OGG
|
||||||
if(isOgg(song->utf8file,&(song->mtime))) {
|
else if(isOgg(utf8file,&(song->mtime))) {
|
||||||
song->tag = oggTagDup(song->utf8file);
|
song->time = getOggTotalTime(
|
||||||
return 0;
|
rmp2amp(utf8ToFsCharset(utf8file)));
|
||||||
|
if(song->time>=0) song->tag = oggTagDup(utf8file);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_FLAC
|
#ifdef HAVE_FLAC
|
||||||
if(isFlac(song->utf8file,&(song->mtime))) {
|
else if((isFlac(utf8file,&(song->mtime)))) {
|
||||||
song->tag = flacTagDup(song->utf8file);
|
song->time = getFlacTotalTime(
|
||||||
return 0;
|
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
|
#endif
|
||||||
#ifdef HAVE_AUDIOFILE
|
#ifdef HAVE_AUDIOFILE
|
||||||
if(isWave(song->utf8file,&(song->mtime))) {
|
else if(isWave(utf8file,&(song->mtime))) {
|
||||||
song->tag = audiofileTagDup(song->utf8file);
|
song->time = getAudiofileTotalTime(
|
||||||
return 0;
|
rmp2amp(utf8ToFsCharset(utf8file)));
|
||||||
|
if(song->time>=0) song->tag = audiofileTagDup(utf8file);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return -1;
|
|
||||||
|
if(song->time<0) return -1;
|
||||||
|
else addSongToTables(song);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Song * songDup(Song * song) {
|
Song * songDup(Song * song) {
|
||||||
|
|
Loading…
Reference in New Issue