aboutsummaryrefslogtreecommitdiffstats
path: root/src/song.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-01-17 13:23:42 +0100
committerMax Kellermann <max@duempel.org>2009-01-17 13:23:42 +0100
commit5395f5f6b34b6a98e94c8f3e8329150a2a4b9cac (patch)
treebb1e42988bd79c452b667da84ef662b45da8aa8e /src/song.c
parent43eefe9c41478f5605e4abd7e6c7fc6d710341e8 (diff)
downloadmpd-5395f5f6b34b6a98e94c8f3e8329150a2a4b9cac.tar.gz
mpd-5395f5f6b34b6a98e94c8f3e8329150a2a4b9cac.tar.xz
mpd-5395f5f6b34b6a98e94c8f3e8329150a2a4b9cac.zip
moved fallback APE/ID3 tag loader to song.c
Some plugins used the APE or ID3 tag loader as a fallback when their own methods of loading tags did not work. Move this code out of all decoder plugins, into song_file_update().
Diffstat (limited to 'src/song.c')
-rw-r--r--src/song.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/song.c b/src/song.c
index b56c798cb..2bb2b85b5 100644
--- a/src/song.c
+++ b/src/song.c
@@ -24,6 +24,7 @@
#include "playlist.h"
#include "decoder_list.h"
#include "decoder_api.h"
+#include "tag_id3.h"
#include <glib.h>
@@ -98,6 +99,38 @@ song_free(struct song *song)
g_free(song);
}
+/**
+ * Attempts to load APE or ID3 tags from the specified file.
+ */
+static struct tag *
+tag_load_fallback(const char *path)
+{
+ struct tag *tag = tag_ape_load(path);
+ if (tag == NULL)
+ tag = tag_id3_load(path);
+ return tag;
+}
+
+/**
+ * The decoder plugin failed to load any tags: fall back to the APE or
+ * ID3 tag loader.
+ */
+static struct tag *
+tag_fallback(const char *path, struct tag *tag)
+{
+ struct tag *fallback = tag_load_fallback(path);
+
+ if (fallback != NULL) {
+ /* tag was successfully loaded: copy the song
+ duration, and destroy the old (empty) tag */
+ fallback->time = tag->time;
+ tag_free(tag);
+ return fallback;
+ } else
+ /* no APE/ID3 tag found: return the empty tag */
+ return tag;
+}
+
bool
song_file_update(struct song *song)
{
@@ -142,6 +175,9 @@ song_file_update(struct song *song)
plugin = decoder_plugin_from_suffix(suffix, true);
} while (plugin != NULL);
+ if (song->tag != NULL && tag_is_empty(song->tag))
+ song->tag = tag_fallback(path_fs, song->tag);
+
g_free(path_fs);
return song->tag != NULL;
}