Commit 4ec3df03 authored by Warren Dukes's avatar Warren Dukes

implement saved memory by not storing full path

git-svn-id: https://svn.musicpd.org/mpd/trunk@2601 09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent 03f02bad
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "playlist.h" #include "playlist.h"
#include "tag.h" #include "tag.h"
#include "tagTracker.h" #include "tagTracker.h"
#include "log.h"
#define LOCATE_TAG_FILE_TYPE TAG_NUM_OF_ITEM_TYPES+10 #define LOCATE_TAG_FILE_TYPE TAG_NUM_OF_ITEM_TYPES+10
#define LOCATE_TAG_FILE_KEY "filename" #define LOCATE_TAG_FILE_KEY "filename"
...@@ -76,7 +77,7 @@ static inline int strstrSearchTag(Song * song, int type, char * str) { ...@@ -76,7 +77,7 @@ static inline int strstrSearchTag(Song * song, int type, char * str) {
int ret = 0; int ret = 0;
if(type == LOCATE_TAG_FILE_TYPE) { if(type == LOCATE_TAG_FILE_TYPE) {
dup = strDupToUpper(song->utf8url); dup = strDupToUpper(getSongUrl(song));
if(strstr(dup, str)) ret = 1; if(strstr(dup, str)) ret = 1;
free(dup); free(dup);
return ret; return ret;
...@@ -122,7 +123,7 @@ static inline int tagItemFoundAndMatches(Song * song, int type, char * str) { ...@@ -122,7 +123,7 @@ static inline int tagItemFoundAndMatches(Song * song, int type, char * str) {
int i; int i;
if(type == LOCATE_TAG_FILE_TYPE) { if(type == LOCATE_TAG_FILE_TYPE) {
if(0 == strcmp(str, song->utf8url)) return 1; if(0 == strcmp(str, getSongUrl(song))) return 1;
} }
if(!song->tag) return 0; if(!song->tag) return 0;
...@@ -217,7 +218,7 @@ void printUnvisitedTags(FILE * fp, Song * song, int tagType) { ...@@ -217,7 +218,7 @@ void printUnvisitedTags(FILE * fp, Song * song, int tagType) {
MpdTag * tag = song->tag; MpdTag * tag = song->tag;
if(tagType == LOCATE_TAG_FILE_TYPE) { if(tagType == LOCATE_TAG_FILE_TYPE) {
myfprintf(fp, "file: %s\n", song->utf8url); printSongUrl(fp, song);
return; return;
} }
...@@ -268,3 +269,23 @@ int listAllUniqueTags(FILE * fp, int type, int numConditionals, ...@@ -268,3 +269,23 @@ int listAllUniqueTags(FILE * fp, int type, int numConditionals,
return ret; return ret;
} }
int sumSavedMemoryInDirectory(FILE * fp, Directory * dir, void * data) {
int * sum = data;
if(!dir->utf8name) return 0;
*sum += (strlen(dir->utf8name)+1-sizeof(Directory *))*
dir->songs->numberOfNodes;
return 0;
}
void printSavedMemoryFromFilenames() {
int sum;
traverseAllIn(stderr, NULL, NULL, sumSavedMemoryInDirectory,
(void *)&sum);
DEBUG("saved memory from filenames: %i\n", sum);
}
...@@ -36,4 +36,6 @@ unsigned long sumSongTimesIn(FILE * fp, char * name); ...@@ -36,4 +36,6 @@ unsigned long sumSongTimesIn(FILE * fp, char * name);
int listAllUniqueTags(FILE * fp, int type, int numConditiionals, int listAllUniqueTags(FILE * fp, int type, int numConditiionals,
LocateTagItem * conditionals); LocateTagItem * conditionals);
void printSavedMemoryFromFilenames();
#endif #endif
...@@ -280,8 +280,8 @@ void removeSongFromDirectory(Directory * directory, char * shortname) { ...@@ -280,8 +280,8 @@ void removeSongFromDirectory(Directory * directory, char * shortname) {
void * song; void * song;
if(findInList(directory->songs,shortname,&song)) { if(findInList(directory->songs,shortname,&song)) {
LOG("removing: %s\n",((Song *)song)->utf8url); LOG("removing: %s\n", getSongUrl((Song *)song));
deleteFromList(directory->songs,shortname); deleteFromList(directory->songs, shortname);
} }
} }
...@@ -317,7 +317,7 @@ int updateInDirectory(Directory * directory, char * shortname, char * name) { ...@@ -317,7 +317,7 @@ int updateInDirectory(Directory * directory, char * shortname, char * name) {
if(S_ISREG(st.st_mode) && hasMusicSuffix(name)) { if(S_ISREG(st.st_mode) && hasMusicSuffix(name)) {
if(0==findInList(directory->songs,shortname,&song)) { if(0==findInList(directory->songs,shortname,&song)) {
addToDirectory(directory,shortname,name); addToDirectory(directory, shortname, name);
return DIRECTORY_RETURN_UPDATE; return DIRECTORY_RETURN_UPDATE;
} }
else if(st.st_mtime!=((Song *)song)->mtime) { else if(st.st_mtime!=((Song *)song)->mtime) {
...@@ -540,7 +540,7 @@ int updatePath(char * utf8path) { ...@@ -540,7 +540,7 @@ int updatePath(char * utf8path) {
parentDirectory->parent, parentDirectory->parent,
parentDirectory->stat->inode, parentDirectory->stat->inode,
parentDirectory->stat->device) && parentDirectory->stat->device) &&
song && isMusic(song->utf8url,&mtime)) song && isMusic(getSongUrl(song), &mtime))
{ {
free(path); free(path);
if(song->mtime==mtime) return 0; if(song->mtime==mtime) return 0;
...@@ -553,7 +553,7 @@ int updatePath(char * utf8path) { ...@@ -553,7 +553,7 @@ int updatePath(char * utf8path) {
} }
/* if updateDirectory fials, means we should delete it */ /* if updateDirectory fials, means we should delete it */
else { else {
removeSongFromDirectory(parentDirectory,shortname); removeSongFromDirectory(parentDirectory, shortname);
ret = 1; ret = 1;
/* don't return, path maybe a directory now*/ /* don't return, path maybe a directory now*/
} }
...@@ -749,10 +749,10 @@ int addToDirectory(Directory * directory, char * shortname, char * name) { ...@@ -749,10 +749,10 @@ int addToDirectory(Directory * directory, char * shortname, char * name) {
if(S_ISREG(st.st_mode) && hasMusicSuffix(name)) { if(S_ISREG(st.st_mode) && hasMusicSuffix(name)) {
Song * song; Song * song;
song = addSongToList(directory->songs,shortname,name, song = addSongToList(directory->songs, shortname, name,
SONG_TYPE_FILE); SONG_TYPE_FILE, directory);
if(!song) return -1; if(!song) return -1;
LOG("added %s\n",name); LOG("added %s\n", name);
return 1; return 1;
} }
else if(S_ISDIR(st.st_mode)) { else if(S_ISDIR(st.st_mode)) {
...@@ -935,7 +935,7 @@ void readDirectoryInfo(FILE * fp,Directory * directory) { ...@@ -935,7 +935,7 @@ void readDirectoryInfo(FILE * fp,Directory * directory) {
readDirectoryInfo(fp,subDirectory); readDirectoryInfo(fp,subDirectory);
} }
else if(0==strncmp(SONG_BEGIN,buffer,strlen(SONG_BEGIN))) { else if(0==strncmp(SONG_BEGIN,buffer,strlen(SONG_BEGIN))) {
readSongInfoIntoList(fp,directory->songs); readSongInfoIntoList(fp, directory->songs, directory);
} }
else { else {
ERROR("Unknown line in db: %s\n",buffer); ERROR("Unknown line in db: %s\n",buffer);
......
...@@ -74,4 +74,8 @@ int traverseAllIn(FILE * fp, char * name, ...@@ -74,4 +74,8 @@ int traverseAllIn(FILE * fp, char * name,
int (*forEachSong)(FILE *, Song *, void *), int (*forEachSong)(FILE *, Song *, void *),
int (*forEachDir)(FILE *, Directory *, void *), int (*forEachDir)(FILE *, Directory *, void *),
void * data); void * data);
/* free the string that is returned */
char * catDirAndFileName(Directory * dir, char * filename);
#endif #endif
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "inputStream.h" #include "inputStream.h"
#include "tag.h" #include "tag.h"
#include "tagTracker.h" #include "tagTracker.h"
#include "dbUtils.h"
#include "../config.h" #include "../config.h"
#include <stdio.h> #include <stdio.h>
...@@ -431,6 +432,7 @@ int main(int argc, char * argv[]) { ...@@ -431,6 +432,7 @@ int main(int argc, char * argv[]) {
initInputStream(); initInputStream();
printMemorySavedByTagTracker(); printMemorySavedByTagTracker();
printSavedMemoryFromFilenames();
daemonize(&options); daemonize(&options);
......
...@@ -179,7 +179,7 @@ int playerPlay(FILE * fp, Song * song) { ...@@ -179,7 +179,7 @@ int playerPlay(FILE * fp, Song * song) {
copyMpdTagToMetadataChunk(song->tag, &(pc->fileMetadataChunk)); copyMpdTagToMetadataChunk(song->tag, &(pc->fileMetadataChunk));
strncpy(pc->utf8url, song->utf8url, MAXPATHLEN); strncpy(pc->utf8url, getSongUrl(song), MAXPATHLEN);
pc->utf8url[MAXPATHLEN] = '\0'; pc->utf8url[MAXPATHLEN] = '\0';
pc->play = 1; pc->play = 1;
...@@ -324,7 +324,7 @@ int queueSong(Song * song) { ...@@ -324,7 +324,7 @@ int queueSong(Song * song) {
PlayerControl * pc = &(getPlayerData()->playerControl); PlayerControl * pc = &(getPlayerData()->playerControl);
if(pc->queueState==PLAYER_QUEUE_BLANK) { if(pc->queueState==PLAYER_QUEUE_BLANK) {
strncpy(pc->utf8url, song->utf8url, MAXPATHLEN); strncpy(pc->utf8url, getSongUrl(song), MAXPATHLEN);
pc->utf8url[MAXPATHLEN] = '\0'; pc->utf8url[MAXPATHLEN] = '\0';
if(song->tag) pc->fileTime = song->tag->time; if(song->tag) pc->fileTime = song->tag->time;
...@@ -380,13 +380,13 @@ int playerSeek(FILE * fp, Song * song, float time) { ...@@ -380,13 +380,13 @@ int playerSeek(FILE * fp, Song * song, float time) {
return -1; return -1;
} }
if(strcmp(pc->utf8url, song->utf8url)!=0) { if(strcmp(pc->utf8url, getSongUrl(song))!=0) {
if(song->tag) pc->fileTime = song->tag->time; if(song->tag) pc->fileTime = song->tag->time;
else pc->fileTime = 0; else pc->fileTime = 0;
copyMpdTagToMetadataChunk(song->tag, &(pc->fileMetadataChunk)); copyMpdTagToMetadataChunk(song->tag, &(pc->fileMetadataChunk));
strncpy(pc->utf8url, song->utf8url, MAXPATHLEN); strncpy(pc->utf8url, getSongUrl(song), MAXPATHLEN);
pc->utf8url[MAXPATHLEN] = '\0'; pc->utf8url[MAXPATHLEN] = '\0';
} }
...@@ -476,7 +476,7 @@ Song * playerCurrentDecodeSong() { ...@@ -476,7 +476,7 @@ Song * playerCurrentDecodeSong() {
memcpy(prev, &(pc->metadataChunk), sizeof(MetadataChunk)); memcpy(prev, &(pc->metadataChunk), sizeof(MetadataChunk));
if(song) freeJustSong(song); if(song) freeJustSong(song);
song = newNullSong(); song = newNullSong();
song->utf8url = strdup(pc->currentUrl); song->url = strdup(pc->currentUrl);
song->tag = metadataChunkToMpdTagDup(prev); song->tag = metadataChunkToMpdTagDup(prev);
ret = song; ret = song;
resetPlayerMetadata(); resetPlayerMetadata();
......
...@@ -245,7 +245,7 @@ int showPlaylist(FILE * fp) { ...@@ -245,7 +245,7 @@ int showPlaylist(FILE * fp) {
int i; int i;
for(i=0;i<playlist.length;i++) { for(i=0;i<playlist.length;i++) {
myfprintf(fp,"%i:%s\n",i,(playlist.songs[i])->utf8url); myfprintf(fp,"%i:%s\n", i, getSongUrl(playlist.songs[i]));
} }
return 0; return 0;
...@@ -428,12 +428,7 @@ void readPlaylistState() { ...@@ -428,12 +428,7 @@ void readPlaylistState() {
} }
void printPlaylistSongInfo(FILE * fp, int song) { void printPlaylistSongInfo(FILE * fp, int song) {
MpdTag * tag; printSongInfo(fp, playlist.songs[song]);
myfprintf(fp, "file: %s\n", (playlist.songs[song])->utf8url);
if((tag = (playlist.songs[song])->tag)) {
printMpdTag(fp, tag);
}
myfprintf(fp, "Pos: %i\n", song); myfprintf(fp, "Pos: %i\n", song);
myfprintf(fp, "Id: %i\n", playlist.positionToId[song]); myfprintf(fp, "Id: %i\n", playlist.positionToId[song]);
} }
...@@ -523,8 +518,8 @@ void queueNextSongInPlaylist() { ...@@ -523,8 +518,8 @@ void queueNextSongInPlaylist() {
playlist.queued = playlist.current+1; playlist.queued = playlist.current+1;
DEBUG("playlist: queue song %i:\"%s\"\n", DEBUG("playlist: queue song %i:\"%s\"\n",
playlist.queued, playlist.queued,
playlist.songs[playlist.order[ getSongUrl(playlist.songs[playlist.order[
playlist.queued]]->utf8url); playlist.queued]]));
if(queueSong(playlist.songs[playlist.order[playlist.queued]]) < if(queueSong(playlist.songs[playlist.order[playlist.queued]]) <
0) 0)
{ {
...@@ -539,8 +534,8 @@ void queueNextSongInPlaylist() { ...@@ -539,8 +534,8 @@ void queueNextSongInPlaylist() {
playlist.queued = 0; playlist.queued = 0;
DEBUG("playlist: queue song %i:\"%s\"\n", DEBUG("playlist: queue song %i:\"%s\"\n",
playlist.queued, playlist.queued,
playlist.songs[playlist.order[ getSongUrl(playlist.songs[playlist.order[
playlist.queued]]->utf8url); playlist.queued]]));
if(queueSong(playlist.songs[playlist.order[playlist.queued]]) < if(queueSong(playlist.songs[playlist.order[playlist.queued]]) <
0) 0)
{ {
...@@ -603,7 +598,7 @@ int addToPlaylist(FILE * fp, char * url, int printId) { ...@@ -603,7 +598,7 @@ int addToPlaylist(FILE * fp, char * url, int printId) {
if((song = getSongFromDB(url))) { if((song = getSongFromDB(url))) {
} }
else if(isValidRemoteUtf8Url(url) && else if(isValidRemoteUtf8Url(url) &&
(song = newSong(url,SONG_TYPE_URL))) (song = newSong(url, SONG_TYPE_URL, NULL)))
{ {
} }
else { else {
...@@ -836,7 +831,7 @@ int playPlaylistOrderNumber(FILE * fp, int orderNum) { ...@@ -836,7 +831,7 @@ int playPlaylistOrderNumber(FILE * fp, int orderNum) {
playlist_queueError = 0; playlist_queueError = 0;
DEBUG("playlist: play %i:\"%s\"\n",orderNum, DEBUG("playlist: play %i:\"%s\"\n",orderNum,
(playlist.songs[playlist.order[orderNum]])->utf8url); getSongUrl(playlist.songs[playlist.order[orderNum]]));
if(playerPlay(fp,(playlist.songs[playlist.order[orderNum]])) < 0) { if(playerPlay(fp,(playlist.songs[playlist.order[orderNum]])) < 0) {
stopPlaylist(fp); stopPlaylist(fp);
...@@ -917,7 +912,7 @@ void syncCurrentPlayerDecodeMetadata() { ...@@ -917,7 +912,7 @@ void syncCurrentPlayerDecodeMetadata() {
song = playlist.songs[songNum]; song = playlist.songs[songNum];
if(song->type == SONG_TYPE_URL && if(song->type == SONG_TYPE_URL &&
0 == strcmp(song->utf8url, songPlayer->utf8url) && 0 == strcmp(getSongUrl(song), songPlayer->url) &&
!mpdTagsAreEqual(song->tag, songPlayer->tag)) !mpdTagsAreEqual(song->tag, songPlayer->tag))
{ {
if(song->tag) freeMpdTag(song->tag); if(song->tag) freeMpdTag(song->tag);
...@@ -1321,10 +1316,10 @@ int savePlaylist(FILE * fp, char * utf8file) { ...@@ -1321,10 +1316,10 @@ int savePlaylist(FILE * fp, char * utf8file) {
playlist.songs[i]->type==SONG_TYPE_FILE) playlist.songs[i]->type==SONG_TYPE_FILE)
{ {
myfprintf(fileP,"%s\n",rmp2amp(utf8ToFsCharset(( myfprintf(fileP,"%s\n",rmp2amp(utf8ToFsCharset((
playlist.songs[i])->utf8url))); getSongUrl(playlist.songs[i])))));
} }
else myfprintf(fileP,"%s\n", else myfprintf(fileP,"%s\n",
utf8ToFsCharset((playlist.songs[i])->utf8url)); utf8ToFsCharset(getSongUrl(playlist.songs[i])));
} }
while(fclose(fileP) && errno==EINTR); while(fclose(fileP) && errno==EINTR);
......
...@@ -29,16 +29,17 @@ ...@@ -29,16 +29,17 @@
#define SONG_KEY "key: " #define SONG_KEY "key: "
#define SONG_FILE "file: " #define SONG_FILE "file: "
#define SONG_TIME "Time: " #define SONG_TIME "Time: "
#define SONG_MTIME "mtime: " #define SONG_MTIME "Mtime: "
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <assert.h>
Song * newNullSong() { Song * newNullSong() {
Song * song = malloc(sizeof(Song)); Song * song = malloc(sizeof(Song));
song->tag = NULL; song->tag = NULL;
song->utf8url = NULL; song->url = NULL;
song->type = SONG_TYPE_FILE; song->type = SONG_TYPE_FILE;
song->parentDir = NULL; song->parentDir = NULL;
...@@ -48,11 +49,11 @@ Song * newNullSong() { ...@@ -48,11 +49,11 @@ Song * newNullSong() {
Song * newSong(char * url, int type, Directory * parentDir) { Song * newSong(char * url, int type, Directory * parentDir) {
Song * song = NULL; Song * song = NULL;
if(strchr(utf8url, '\n')) return NULL; if(strchr(url, '\n')) return NULL;
song = newNullSong(); song = newNullSong();
song->utf8url = strdup(utf8url); song->url = strdup(url);
song->type = type; song->type = type;
song->parentDir = parentDir; song->parentDir = parentDir;
...@@ -60,9 +61,9 @@ Song * newSong(char * url, int type, Directory * parentDir) { ...@@ -60,9 +61,9 @@ Song * newSong(char * url, int type, Directory * parentDir) {
if(song->type == SONG_TYPE_FILE) { if(song->type == SONG_TYPE_FILE) {
InputPlugin * plugin; InputPlugin * plugin;
if((plugin = isMusic(utf8url,&(song->mtime)))) { if((plugin = isMusic(getSongUrl(song), &(song->mtime)))) {
song->tag = plugin->tagDupFunc( song->tag = plugin->tagDupFunc(
rmp2amp(utf8ToFsCharset(utf8url))); rmp2amp(utf8ToFsCharset(getSongUrl(song))));
} }
if(!song->tag || song->tag->time<0) { if(!song->tag || song->tag->time<0) {
freeSong(song); freeSong(song);
...@@ -75,13 +76,11 @@ Song * newSong(char * url, int type, Directory * parentDir) { ...@@ -75,13 +76,11 @@ Song * newSong(char * url, int type, Directory * parentDir) {
void freeSong(Song * song) { void freeSong(Song * song) {
deleteASongFromPlaylist(song); deleteASongFromPlaylist(song);
free(song->utf8url); freeJustSong(song);
if(song->tag) freeMpdTag(song->tag);
free(song);
} }
void freeJustSong(Song * song) { void freeJustSong(Song * song) {
free(song->utf8url); free(song->url);
if(song->tag) freeMpdTag(song->tag); if(song->tag) freeMpdTag(song->tag);
free(song); free(song);
} }
...@@ -90,19 +89,19 @@ SongList * newSongList() { ...@@ -90,19 +89,19 @@ SongList * newSongList() {
return makeList((ListFreeDataFunc *)freeSong); return makeList((ListFreeDataFunc *)freeSong);
} }
Song * addSongToList(SongList * list, char * url, int songType, Song * addSongToList(SongList * list, char * url, char * utf8path,
Directory * parentDirectory) int songType, Directory * parentDirectory)
{ {
Song * song = NULL; Song * song = NULL;
switch(type) { switch(songType) {
case SONG_TYPE_FILE: case SONG_TYPE_FILE:
if(isMusic(utf8url,NULL)) { if(isMusic(utf8path, NULL)) {
song = newSong(url, type, parentDirectory); song = newSong(url, songType, parentDirectory);
} }
break; break;
case SONG_TYPE_URL: case SONG_TYPE_URL:
song = newSong(utf8url, type, parentDirectory); song = newSong(url, songType, parentDirectory);
break; break;
} }
...@@ -119,7 +118,7 @@ void freeSongList(SongList * list) { ...@@ -119,7 +118,7 @@ void freeSongList(SongList * list) {
void printSongUrl(FILE * fp, Song * song) { void printSongUrl(FILE * fp, Song * song) {
if(song->parentDir) { if(song->parentDir) {
myfprintf(fp, "%s%s%s\n", SONG_FILE, song->parentDir->utf8name, myfprintf(fp, "%s%s/%s\n", SONG_FILE, song->parentDir->utf8name,
song->url); song->url);
} }
else { else {
...@@ -208,11 +207,10 @@ static int matchesAnMpdTagItemKey(char * buffer, int * itemType) { ...@@ -208,11 +207,10 @@ static int matchesAnMpdTagItemKey(char * buffer, int * itemType) {
return 0; return 0;
} }
void readSongInfoIntoList(FILE * fp, SongList * list) { void readSongInfoIntoList(FILE * fp, SongList * list, Directory * parentDir) {
char buffer[MAXPATHLEN+1024]; char buffer[MAXPATHLEN+1024];
int bufferSize = MAXPATHLEN+1024; int bufferSize = MAXPATHLEN+1024;
Song * song = NULL; Song * song = NULL;
char * key = NULL;
ListNode * nextSongNode = list->firstNode; ListNode * nextSongNode = list->firstNode;
ListNode * nodeTemp; ListNode * nodeTemp;
int itemType; int itemType;
...@@ -220,21 +218,25 @@ void readSongInfoIntoList(FILE * fp, SongList * list) { ...@@ -220,21 +218,25 @@ void readSongInfoIntoList(FILE * fp, SongList * list) {
while(myFgets(buffer,bufferSize,fp) && 0!=strcmp(SONG_END,buffer)) { while(myFgets(buffer,bufferSize,fp) && 0!=strcmp(SONG_END,buffer)) {
if(0==strncmp(SONG_KEY,buffer,strlen(SONG_KEY))) { if(0==strncmp(SONG_KEY,buffer,strlen(SONG_KEY))) {
if(song) { if(song) {
insertSongIntoList(list,&nextSongNode,key,song); insertSongIntoList(list,&nextSongNode,
song->url,
song);
song = NULL; song = NULL;
free(key);
} }
key = strdup(&(buffer[strlen(SONG_KEY)]));
song = newNullSong(); song = newNullSong();
song->url = strdup(buffer+strlen(SONG_KEY));
song->type = SONG_TYPE_FILE; song->type = SONG_TYPE_FILE;
song->parentDir = parentDir;
} }
else if(0==strncmp(SONG_FILE,buffer,strlen(SONG_FILE))) { else if(0==strncmp(SONG_FILE,buffer,strlen(SONG_FILE))) {
if(!song || song->utf8url) { if(!song) {
ERROR("Problems reading song info\n"); ERROR("Problems reading song info\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
song->utf8url = strdup(&(buffer[strlen(SONG_FILE)])); /* we don't need this info anymore
song->url = strdup(&(buffer[strlen(SONG_FILE)]));
*/
} }
else if(matchesAnMpdTagItemKey(buffer, &itemType)) { else if(matchesAnMpdTagItemKey(buffer, &itemType)) {
if(!song->tag) song->tag = newMpdTag(); if(!song->tag) song->tag = newMpdTag();
...@@ -255,9 +257,8 @@ void readSongInfoIntoList(FILE * fp, SongList * list) { ...@@ -255,9 +257,8 @@ void readSongInfoIntoList(FILE * fp, SongList * list) {
} }
if(song) { if(song) {
insertSongIntoList(list,&nextSongNode,key,song); insertSongIntoList(list, &nextSongNode, song->url, song);
song = NULL; song = NULL;
free(key);
} }
while(nextSongNode) { while(nextSongNode) {
...@@ -268,8 +269,6 @@ void readSongInfoIntoList(FILE * fp, SongList * list) { ...@@ -268,8 +269,6 @@ void readSongInfoIntoList(FILE * fp, SongList * list) {
} }
int updateSongInfo(Song * song) { int updateSongInfo(Song * song) {
char * utf8url = song->utf8url;
if(song->type == SONG_TYPE_FILE) { if(song->type == SONG_TYPE_FILE) {
InputPlugin * plugin; InputPlugin * plugin;
...@@ -277,9 +276,9 @@ int updateSongInfo(Song * song) { ...@@ -277,9 +276,9 @@ int updateSongInfo(Song * song) {
song->tag = NULL; song->tag = NULL;
if((plugin = isMusic(utf8url,&(song->mtime)))) { if((plugin = isMusic(getSongUrl(song),&(song->mtime)))) {
song->tag = plugin->tagDupFunc( song->tag = plugin->tagDupFunc(
rmp2amp(utf8ToFsCharset(utf8url))); rmp2amp(getSongUrl(song)));
} }
if(!song->tag || song->tag->time<0) return -1; if(!song->tag || song->tag->time<0) return -1;
} }
...@@ -290,10 +289,41 @@ int updateSongInfo(Song * song) { ...@@ -290,10 +289,41 @@ int updateSongInfo(Song * song) {
Song * songDup(Song * song) { Song * songDup(Song * song) {
Song * ret = malloc(sizeof(Song)); Song * ret = malloc(sizeof(Song));
ret->utf8url = strdup(song->utf8url); ret->url = strdup(song->url);
ret->mtime = song->mtime; ret->mtime = song->mtime;
ret->tag = mpdTagDup(song->tag); ret->tag = mpdTagDup(song->tag);
ret->type = song->type; ret->type = song->type;
ret->parentDir = song->parentDir;
return ret; return ret;
} }
char * getSongUrl(Song * song) {
static char * buffer = NULL;
static int bufferSize = 0;
static Song * lastSong = NULL;
int slen;
int dlen;
int size;
if(!song->parentDir || !song->parentDir->utf8name) return song->url;
/* be careful with this! */
if(song == lastSong) return buffer;
slen = strlen(song->url);
dlen = strlen(song->parentDir->utf8name);
size = slen+dlen+2;
if(size > bufferSize) {
buffer = realloc(buffer, size);
bufferSize = size;
}
strcpy(buffer, song->parentDir->utf8name);
buffer[dlen] = '/';
strcpy(buffer+dlen+1, song->url);
return buffer;
}
...@@ -45,7 +45,7 @@ typedef List SongList; ...@@ -45,7 +45,7 @@ typedef List SongList;
Song * newNullSong(); Song * newNullSong();
Song * newSong(char * utf8url, int songType, struct _Directory * parentDir); Song * newSong(char * url, int songType, struct _Directory * parentDir);
void freeSong(Song *); void freeSong(Song *);
...@@ -55,7 +55,7 @@ SongList * newSongList(); ...@@ -55,7 +55,7 @@ SongList * newSongList();
void freeSongList(SongList * list); void freeSongList(SongList * list);
Song * addSongToList(SongList * list, char * key, char * utf8file, Song * addSongToList(SongList * list, char * url, char * utf8path,
int songType, struct _Directory * parentDir); int songType, struct _Directory * parentDir);
int printSongInfo(FILE * fp, Song * song); int printSongInfo(FILE * fp, Song * song);
...@@ -64,7 +64,8 @@ int printSongInfoFromList(FILE * fp, SongList * list); ...@@ -64,7 +64,8 @@ int printSongInfoFromList(FILE * fp, SongList * list);
void writeSongInfoFromList(FILE * fp, SongList * list); void writeSongInfoFromList(FILE * fp, SongList * list);
void readSongInfoIntoList(FILE * fp, SongList * list); void readSongInfoIntoList(FILE * fp, SongList * list,
struct _Directory * parent);
int updateSongInfo(Song * song); int updateSongInfo(Song * song);
...@@ -72,4 +73,6 @@ Song * songDup(Song * song); ...@@ -72,4 +73,6 @@ Song * songDup(Song * song);
void printSongUrl(FILE * fp, Song * song); void printSongUrl(FILE * fp, Song * song);
char * getSongUrl(Song * song);
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment