playlist_list: support URI suffix match
When no plugin matches the URI scheme, try the file name suffix.
This commit is contained in:
parent
843717d25c
commit
c128f2dd7e
@ -116,8 +116,8 @@ g_uri_parse_scheme(const char *uri)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct playlist_provider *
|
static struct playlist_provider *
|
||||||
playlist_list_open_uri(const char *uri)
|
playlist_list_open_uri_scheme(const char *uri, bool *tried)
|
||||||
{
|
{
|
||||||
char *scheme;
|
char *scheme;
|
||||||
struct playlist_provider *playlist = NULL;
|
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) {
|
for (unsigned i = 0; playlist_plugins[i] != NULL; ++i) {
|
||||||
const struct playlist_plugin *plugin = playlist_plugins[i];
|
const struct playlist_plugin *plugin = playlist_plugins[i];
|
||||||
|
|
||||||
|
assert(!tried[i]);
|
||||||
|
|
||||||
if (playlist_plugins_enabled[i] && plugin->open_uri != NULL &&
|
if (playlist_plugins_enabled[i] && plugin->open_uri != NULL &&
|
||||||
plugin->schemes != NULL &&
|
plugin->schemes != NULL &&
|
||||||
string_array_contains(plugin->schemes, scheme)) {
|
string_array_contains(plugin->schemes, scheme)) {
|
||||||
playlist = playlist_plugin_open_uri(plugin, uri);
|
playlist = playlist_plugin_open_uri(plugin, uri);
|
||||||
if (playlist != NULL)
|
if (playlist != NULL)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
tried[i] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,6 +148,54 @@ playlist_list_open_uri(const char *uri)
|
|||||||
return playlist;
|
return playlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 *
|
static struct playlist_provider *
|
||||||
playlist_list_open_stream_mime(struct input_stream *is)
|
playlist_list_open_stream_mime(struct input_stream *is)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user