diff options
author | Max Kellermann <max@duempel.org> | 2009-01-04 17:26:22 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-01-04 17:26:22 +0100 |
commit | ff72fff68da8edc9d28e0022425893d1641f21e5 (patch) | |
tree | 2ef8847032fddb93823e0b30c872c51a25c9ab75 | |
parent | d6b229e35c87cb246fcb77b2b04ac65adccc2b31 (diff) | |
download | mpd-ff72fff68da8edc9d28e0022425893d1641f21e5.tar.gz mpd-ff72fff68da8edc9d28e0022425893d1641f21e5.tar.xz mpd-ff72fff68da8edc9d28e0022425893d1641f21e5.zip |
ls: removed hasMusicSuffix() and get_archive_by_suffix()
Determine the suffix manually, and use decoder_plugin_from_suffix()
and archive_plugin_from_suffix() instead.
This way, song_file_update_inarchive() can be optimized: it does not
have to translate its path.
-rw-r--r-- | src/ls.c | 35 | ||||
-rw-r--r-- | src/ls.h | 6 | ||||
-rw-r--r-- | src/song.c | 47 | ||||
-rw-r--r-- | src/update.c | 10 |
4 files changed, 39 insertions, 59 deletions
@@ -19,8 +19,6 @@ #include "ls.h" #include "client.h" #include "config.h" -#include "decoder_list.h" -#include "archive_list.h" #include <string.h> @@ -66,36 +64,3 @@ const char *getSuffix(const char *utf8file) return dot != NULL ? dot + 1 : NULL; } - -const struct decoder_plugin * -hasMusicSuffix(const char *utf8file, unsigned int next) -{ - const struct decoder_plugin *ret = NULL; - - const char *s = getSuffix(utf8file); - if (s) { - ret = decoder_plugin_from_suffix(s, next); - } else { - g_debug("hasMusicSuffix: The file: %s has no valid suffix\n", - utf8file); - } - - return ret; -} - -#ifdef ENABLE_ARCHIVE -const struct archive_plugin * -get_archive_by_suffix(const char *utf8file) -{ - const struct archive_plugin *ret = NULL; - - const char *s = getSuffix(utf8file); - if (s) { - ret = archive_plugin_from_suffix(s); - } else { - g_debug("get_archive_by_suffix: The file: %s has no valid suffix\n", - utf8file); - } - return ret; -} -#endif @@ -34,12 +34,6 @@ bool uri_has_scheme(const char *uri); bool isRemoteUrl(const char *url); -const struct decoder_plugin * -hasMusicSuffix(const char *utf8file, unsigned int next); - -const struct archive_plugin * -get_archive_by_suffix(const char *utf8file); - void printRemoteUrlHandlers(struct client *client); #endif diff --git a/src/song.c b/src/song.c index 19abb963f..e89b2ac80 100644 --- a/src/song.c +++ b/src/song.c @@ -101,13 +101,23 @@ song_free(struct song *song) bool song_file_update(struct song *song) { + const char *suffix; char *path_fs; const struct decoder_plugin *plugin; - unsigned int next = 0; struct stat st; assert(song_is_file(song)); + /* check if there's a suffix and a plugin */ + + suffix = getSuffix(song->url); + if (suffix == NULL) + return false; + + plugin = decoder_plugin_from_suffix(suffix, false); + if (plugin == NULL) + return false; + path_fs = map_song_fs(song); if (path_fs == NULL) return false; @@ -124,9 +134,13 @@ song_file_update(struct song *song) song->mtime = st.st_mtime; - while (song->tag == NULL && - (plugin = hasMusicSuffix(path_fs, next++))) + do { song->tag = plugin->tag_dup(path_fs); + if (song->tag != NULL) + break; + + plugin = decoder_plugin_from_suffix(suffix, true); + } while (plugin != NULL); g_free(path_fs); return song->tag != NULL; @@ -135,29 +149,30 @@ song_file_update(struct song *song) bool song_file_update_inarchive(struct song *song) { - char *path_fs; + const char *suffix; const struct decoder_plugin *plugin; assert(song_is_file(song)); - path_fs = map_song_fs(song); - if (path_fs == NULL) + /* check if there's a suffix and a plugin */ + + suffix = getSuffix(song->url); + if (suffix == NULL) return false; - if (song->tag != NULL) { + plugin = decoder_plugin_from_suffix(suffix, false); + if (plugin == NULL) + return false; + + if (song->tag != NULL) tag_free(song->tag); - song->tag = NULL; - } + //accept every file that has music suffix //because we dont support tag reading throught //input streams - plugin = hasMusicSuffix(path_fs, 0); - g_free(path_fs); - if (plugin) { - song->tag = tag_new(); - //tag_add_item(tag, TAG_ITEM_TITLE, f->title); - } - return song->tag != NULL; + song->tag = tag_new(); + + return true; } char * diff --git a/src/update.c b/src/update.c index 826a17dc7..0cf73ff80 100644 --- a/src/update.c +++ b/src/update.c @@ -24,6 +24,7 @@ #include "ls.h" #include "mapper.h" #include "path.h" +#include "decoder_list.h" #include "playlist.h" #include "event_pipe.h" #include "condition.h" @@ -351,7 +352,12 @@ static void update_regular_file(struct directory *directory, const char *name, const struct stat *st) { - if (hasMusicSuffix(name, 0)) { + const char *suffix = getSuffix(name); + + if (suffix == NULL) + return; + + if (decoder_plugin_from_suffix(suffix, false) != NULL) { struct song *song = songvec_find(&directory->songs, name); if (song == NULL) { @@ -371,7 +377,7 @@ update_regular_file(struct directory *directory, modified = true; } #ifdef ENABLE_ARCHIVE - } else if ((archive = get_archive_by_suffix(name))) { + } else if ((archive = archive_plugin_from_suffix(suffix))) { struct archive_file *archfile; char pathname[MPD_PATH_MAX]; |