From 4a23a4bfee5c7b213da4f72ae858ab69840ccbdc Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 12 Feb 2012 18:25:46 +0100 Subject: tag_{ape,id3}: remove the _load() functions Use _scan() instead, to have more control. --- src/song_update.c | 33 ++++++--------------------------- src/tag_ape.c | 12 ------------ src/tag_ape.h | 9 --------- src/tag_id3.c | 28 ---------------------------- src/tag_id3.h | 8 -------- 5 files changed, 6 insertions(+), 84 deletions(-) diff --git a/src/song_update.c b/src/song_update.c index d6f643dd..e58896ed 100644 --- a/src/song_update.c +++ b/src/song_update.c @@ -66,33 +66,12 @@ song_file_load(const char *path, struct directory *parent) /** * Attempts to load APE or ID3 tags from the specified file. */ -static struct tag * -tag_load_fallback(const char *path) +static bool +tag_scan_fallback(const char *path, + const struct tag_handler *handler, void *handler_ctx) { - 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; + return tag_ape_scan2(path, handler, handler_ctx) || + tag_id3_scan(path, handler, handler_ctx); } bool @@ -183,7 +162,7 @@ song_file_update(struct song *song) } if (song->tag != NULL && tag_is_empty(song->tag)) - song->tag = tag_fallback(path_fs, song->tag); + tag_scan_fallback(path_fs, &add_tag_handler, song->tag); g_free(path_fs); return song->tag != NULL; diff --git a/src/tag_ape.c b/src/tag_ape.c index 068a9aa6..31c177aa 100644 --- a/src/tag_ape.c +++ b/src/tag_ape.c @@ -101,15 +101,3 @@ tag_ape_scan2(const char *path_fs, return tag_ape_scan(path_fs, tag_ape_callback, &ctx); } - -struct tag * -tag_ape_load(const char *path_fs) -{ - struct tag *tag = tag_new(); - if (!tag_ape_scan2(path_fs, &add_tag_handler, tag)) { - tag_free(tag); - tag = NULL; - } - - return tag; -} diff --git a/src/tag_ape.h b/src/tag_ape.h index 2e8bfb3c..9b585611 100644 --- a/src/tag_ape.h +++ b/src/tag_ape.h @@ -33,13 +33,4 @@ bool tag_ape_scan2(const char *path_fs, const struct tag_handler *handler, void *handler_ctx); -/** - * Loads the APE tag from a file. - * - * @param path_fs the path of the file in filesystem encoding - * @return a tag object, or NULL if the file has no APE tag - */ -struct tag * -tag_ape_load(const char *path_fs); - #endif diff --git a/src/tag_id3.c b/src/tag_id3.c index 05870152..394068d3 100644 --- a/src/tag_id3.c +++ b/src/tag_id3.c @@ -570,31 +570,3 @@ tag_id3_scan(const char *path_fs, id3_tag_delete(tag); return true; } - -struct tag *tag_id3_load(const char *file) -{ - struct tag *ret; - struct id3_tag *tag; - FILE *stream; - - stream = fopen(file, "rb"); - if (!stream) { - g_debug("tag_id3_load: Failed to open file: '%s', %s", - file, strerror(errno)); - return NULL; - } - - tag = tag_id3_find_from_beginning(stream); - if (tag == NULL) - tag = tag_id3_riff_aiff_load(stream); - if (!tag) - tag = tag_id3_find_from_end(stream); - - fclose(stream); - - if (!tag) - return NULL; - ret = tag_id3_import(tag); - id3_tag_delete(tag); - return ret; -} diff --git a/src/tag_id3.h b/src/tag_id3.h index fb5c7c65..b99b4480 100644 --- a/src/tag_id3.h +++ b/src/tag_id3.h @@ -36,8 +36,6 @@ tag_id3_scan(const char *path_fs, struct id3_tag; struct tag *tag_id3_import(struct id3_tag *); -struct tag *tag_id3_load(const char *file); - #else #include @@ -50,12 +48,6 @@ tag_id3_scan(G_GNUC_UNUSED const char *path_fs, return false; } -static inline struct tag * -tag_id3_load(G_GNUC_UNUSED const char *file) -{ - return NULL; -} - #endif #endif -- cgit v1.2.3