diff options
author | Max Kellermann <max@duempel.org> | 2009-01-17 13:23:42 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-01-17 13:23:42 +0100 |
commit | 5395f5f6b34b6a98e94c8f3e8329150a2a4b9cac (patch) | |
tree | bb1e42988bd79c452b667da84ef662b45da8aa8e /src/song.c | |
parent | 43eefe9c41478f5605e4abd7e6c7fc6d710341e8 (diff) | |
download | mpd-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.c | 36 |
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; } |