diff options
author | Max Kellermann <max@duempel.org> | 2009-12-16 21:09:56 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2009-12-16 22:17:16 +0100 |
commit | c128f2dd7e289f32e1ecaaaf467ac0796715d1f5 (patch) | |
tree | e4aa3fde14c21304ba8d773285c68c29fca15ff0 /src/playlist | |
parent | 843717d25c5cf36cb3f8571c72b160f427441cb2 (diff) | |
download | mpd-c128f2dd7e289f32e1ecaaaf467ac0796715d1f5.tar.gz mpd-c128f2dd7e289f32e1ecaaaf467ac0796715d1f5.tar.xz mpd-c128f2dd7e289f32e1ecaaaf467ac0796715d1f5.zip |
playlist_list: support URI suffix match
When no plugin matches the URI scheme, try the file name suffix.
Diffstat (limited to '')
-rw-r--r-- | src/playlist_list.c | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/src/playlist_list.c b/src/playlist_list.c index 175003c19..f96f45626 100644 --- a/src/playlist_list.c +++ b/src/playlist_list.c @@ -116,8 +116,8 @@ g_uri_parse_scheme(const char *uri) } #endif -struct playlist_provider * -playlist_list_open_uri(const char *uri) +static struct playlist_provider * +playlist_list_open_uri_scheme(const char *uri, bool *tried) { char *scheme; struct playlist_provider *playlist = NULL; @@ -131,12 +131,16 @@ playlist_list_open_uri(const char *uri) for (unsigned i = 0; playlist_plugins[i] != NULL; ++i) { const struct playlist_plugin *plugin = playlist_plugins[i]; + assert(!tried[i]); + if (playlist_plugins_enabled[i] && plugin->open_uri != NULL && plugin->schemes != NULL && string_array_contains(plugin->schemes, scheme)) { playlist = playlist_plugin_open_uri(plugin, uri); if (playlist != NULL) break; + + tried[i] = true; } } @@ -145,6 +149,54 @@ playlist_list_open_uri(const char *uri) } static struct playlist_provider * +playlist_list_open_uri_suffix(const char *uri, const bool *tried) +{ + const char *suffix; + struct playlist_provider *playlist = NULL; + + assert(uri != NULL); + + suffix = strrchr(uri, '.'); + if (suffix == NULL || strchr(suffix, '/') != NULL) + return NULL; + + ++suffix; + + for (unsigned i = 0; playlist_plugins[i] != NULL; ++i) { + const struct playlist_plugin *plugin = playlist_plugins[i]; + + if (playlist_plugins_enabled[i] && !tried[i] && + plugin->open_uri != NULL && plugin->suffixes != NULL && + string_array_contains(plugin->suffixes, suffix)) { + playlist = playlist_plugin_open_uri(plugin, uri); + if (playlist != NULL) + break; + } + } + + return playlist; +} + +struct playlist_provider * +playlist_list_open_uri(const char *uri) +{ + struct playlist_provider *playlist; + /** this array tracks which plugins have already been tried by + playlist_list_open_uri_scheme() */ + bool tried[G_N_ELEMENTS(playlist_plugins) - 1]; + + assert(uri != NULL); + + memset(tried, false, sizeof(tried)); + + playlist = playlist_list_open_uri_scheme(uri, tried); + if (playlist == NULL) + playlist = playlist_list_open_uri_suffix(uri, tried); + + return playlist; +} + +static struct playlist_provider * playlist_list_open_stream_mime(struct input_stream *is) { struct playlist_provider *playlist; |