aboutsummaryrefslogtreecommitdiffstats
path: root/src/song.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/song.c')
-rw-r--r--src/song.c103
1 files changed, 23 insertions, 80 deletions
diff --git a/src/song.c b/src/song.c
index ff0ada620..0abf5c9b7 100644
--- a/src/song.c
+++ b/src/song.c
@@ -27,9 +27,6 @@
#include "inputPlugin.h"
#include "myfprintf.h"
-#define SONG_KEY "key: "
-#define SONG_MTIME "mtime: "
-
#include "os_compat.h"
static Song *newNullSong(void)
@@ -152,64 +149,24 @@ int printSongInfo(int fd, Song * song)
return 0;
}
-int printSongInfoFromList(int fd, SongList * list)
-{
- ListNode *tempNode = list->firstNode;
-
- while (tempNode != NULL) {
- printSongInfo(fd, (Song *) tempNode->data);
- tempNode = tempNode->nextNode;
- }
-
- return 0;
-}
-
-void writeSongInfoFromList(int fd, SongList * list)
+static void insertSongIntoList(struct songvec *sv, Song *newsong)
{
- ListNode *tempNode = list->firstNode;
-
- fdprintf(fd, SONG_BEGIN "\n");
-
- while (tempNode != NULL) {
- fdprintf(fd, SONG_KEY "%s\n", tempNode->key);
- printSongInfo(fd, (Song *) tempNode->data);
- fdprintf(fd, SONG_MTIME "%li\n",
- (long)((Song *) tempNode->data)->mtime);
- tempNode = tempNode->nextNode;
- }
-
- fdprintf(fd, SONG_END "\n");
-}
-
-static void insertSongIntoList(SongList * list, ListNode ** nextSongNode,
- char *key, Song * song)
-{
- ListNode *nodeTemp;
- int cmpRet = 0;
-
- while (*nextSongNode
- && (cmpRet = strcmp(key, (*nextSongNode)->key)) > 0) {
- nodeTemp = (*nextSongNode)->nextNode;
- deleteNodeFromList(list, *nextSongNode);
- *nextSongNode = nodeTemp;
- }
-
- if (!(*nextSongNode)) {
- insertInList(list, song->url, (void *)song);
- } else if (cmpRet == 0) {
- Song *tempSong = (Song *) ((*nextSongNode)->data);
- if (tempSong->mtime != song->mtime) {
- tag_free(tempSong->tag);
- tag_end_add(song->tag);
- tempSong->tag = song->tag;
- tempSong->mtime = song->mtime;
- song->tag = NULL;
+ Song *existing = songvec_find(sv, newsong->url);
+
+ if (!existing) {
+ songvec_add(sv, newsong);
+ if (newsong->tag)
+ tag_end_add(newsong->tag);
+ } else { /* prevent dupes, just update the existing song info */
+ if (existing->mtime != newsong->mtime) {
+ tag_free(existing->tag);
+ if (newsong->tag)
+ tag_end_add(newsong->tag);
+ existing->tag = newsong->tag;
+ existing->mtime = newsong->mtime;
+ newsong->tag = NULL;
}
- freeJustSong(song);
- *nextSongNode = (*nextSongNode)->nextNode;
- } else {
- insertInListBeforeNode(list, *nextSongNode, -1, song->url,
- (void *)song);
+ freeJustSong(newsong);
}
}
@@ -227,24 +184,18 @@ static int matchesAnMpdTagItemKey(char *buffer, int *itemType)
return 0;
}
-void readSongInfoIntoList(FILE * fp, SongList * list, Directory * parentDir)
+void readSongInfoIntoList(FILE * fp, Directory * parentDir)
{
char buffer[MPD_PATH_MAX + 1024];
int bufferSize = MPD_PATH_MAX + 1024;
Song *song = NULL;
- ListNode *nextSongNode = list->firstNode;
- ListNode *nodeTemp;
+ struct songvec *sv = &parentDir->songs;
int itemType;
while (myFgets(buffer, bufferSize, fp) && 0 != strcmp(SONG_END, buffer)) {
if (!prefixcmp(buffer, SONG_KEY)) {
- if (song) {
- insertSongIntoList(list, &nextSongNode,
- song->url, song);
- if (song->tag != NULL)
- tag_end_add(song->tag);
- }
-
+ if (song)
+ insertSongIntoList(sv, song);
song = newNullSong();
song->url = xstrdup(buffer + strlen(SONG_KEY));
song->type = SONG_TYPE_FILE;
@@ -281,17 +232,9 @@ void readSongInfoIntoList(FILE * fp, SongList * list, Directory * parentDir)
FATAL("songinfo: unknown line in db: %s\n", buffer);
}
- if (song) {
- insertSongIntoList(list, &nextSongNode, song->url, song);
- if (song->tag != NULL)
- tag_end_add(song->tag);
- }
-
- while (nextSongNode) {
- nodeTemp = nextSongNode->nextNode;
- deleteNodeFromList(list, nextSongNode);
- nextSongNode = nodeTemp;
- }
+ if (song)
+ insertSongIntoList(sv, song);
+ songvec_prune(sv);
}
int updateSongInfo(Song * song)