From 598db0d296a8c16e181b488040a324f9ae20cc33 Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Tue, 9 Nov 2004 22:07:01 +0000 Subject: work in progress git-svn-id: https://svn.musicpd.org/mpd/branches/r2562-metadata-handling-rewrite@2566 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/song.c | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) (limited to 'src/song.c') diff --git a/src/song.c b/src/song.c index fac103fad..3d8ef4769 100644 --- a/src/song.c +++ b/src/song.c @@ -28,11 +28,6 @@ #define SONG_KEY "key: " #define SONG_FILE "file: " -#define SONG_ARTIST "Artist: " -#define SONG_ALBUM "Album: " -#define SONG_TRACK "Track: " -#define SONG_TITLE "Title: " -#define SONG_NAME "Name: " #define SONG_TIME "Time: " #define SONG_MTIME "mtime: " @@ -185,6 +180,20 @@ void insertSongIntoList(SongList * list, ListNode ** nextSongNode, char * key, } } +static int matchesAnMpdTagItemKey(char * buffer, int * itemType) { + int i; + + for(i = 0; i < TAG_NUM_OF_ITEM_TYPES; i++) { + if( 0 == strncmp(mpdTagItemKeys[i], buffer, + strlen(mpdTagItemKeys[i]))) + { + return 1; + } + } + + return 0; +} + void readSongInfoIntoList(FILE * fp, SongList * list) { char buffer[MAXPATHLEN+1024]; int bufferSize = MAXPATHLEN+1024; @@ -192,6 +201,7 @@ void readSongInfoIntoList(FILE * fp, SongList * list) { char * key = NULL; ListNode * nextSongNode = list->firstNode; ListNode * nodeTemp; + int itemType; while(myFgets(buffer,bufferSize,fp) && 0!=strcmp(SONG_END,buffer)) { if(0==strncmp(SONG_KEY,buffer,strlen(SONG_KEY))) { @@ -212,32 +222,17 @@ void readSongInfoIntoList(FILE * fp, SongList * list) { } song->utf8url = strdup(&(buffer[strlen(SONG_FILE)])); } - else if(0==strncmp(SONG_ARTIST,buffer,strlen(SONG_ARTIST))) { - if(!song->tag) song->tag = newMpdTag(); - song->tag->artist = strdup(&(buffer[strlen(SONG_ARTIST)])); - } - else if(0==strncmp(SONG_ALBUM,buffer,strlen(SONG_ALBUM))) { - if(!song->tag) song->tag = newMpdTag(); - song->tag->album = strdup(&(buffer[strlen(SONG_ALBUM)])); - } - else if(0==strncmp(SONG_TRACK,buffer,strlen(SONG_TRACK))) { - if(!song->tag) song->tag = newMpdTag(); - song->tag->track = strdup(&(buffer[strlen(SONG_TRACK)])); - } - else if(0==strncmp(SONG_TITLE,buffer,strlen(SONG_TITLE))) { - if(!song->tag) song->tag = newMpdTag(); - song->tag->title = strdup(&(buffer[strlen(SONG_TITLE)])); - } - else if(0==strncmp(SONG_NAME,buffer,strlen(SONG_NAME))) { + else if(matchesAnMpdTagItemKey(buffer, &itemType)) { if(!song->tag) song->tag = newMpdTag(); - song->tag->name = strdup(&(buffer[strlen(SONG_NAME)])); + addItemToMpdTag(song->tag, itemType, + &(buffer[strlen(mpdTagItemKeys[itemType])])); } else if(0==strncmp(SONG_TIME,buffer,strlen(SONG_TIME))) { if(!song->tag) song->tag = newMpdTag(); song->tag->time = atoi(&(buffer[strlen(SONG_TIME)])); } else if(0==strncmp(SONG_MTIME,buffer,strlen(SONG_MTIME))) { - song->mtime = atoi(&(buffer[strlen(SONG_TITLE)])); + song->mtime = atoi(&(buffer[strlen(SONG_MTIME)])); } else { ERROR("songinfo: unknown line in db: %s\n",buffer); -- cgit v1.2.3