2009-10-12 22:34:04 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2003-2009 The Music Player Daemon Project
|
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "playlist_list.h"
|
|
|
|
#include "playlist_plugin.h"
|
|
|
|
#include "playlist/m3u_playlist_plugin.h"
|
2009-10-13 16:31:07 +02:00
|
|
|
#include "playlist/xspf_playlist_plugin.h"
|
2009-10-12 22:34:04 +02:00
|
|
|
#include "input_stream.h"
|
|
|
|
#include "uri.h"
|
|
|
|
#include "utils.h"
|
2009-10-13 16:19:21 +02:00
|
|
|
#include "conf.h"
|
2009-10-12 22:34:04 +02:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
2009-10-13 16:19:21 +02:00
|
|
|
#include <string.h>
|
2009-10-12 22:34:04 +02:00
|
|
|
|
|
|
|
static const struct playlist_plugin *const playlist_plugins[] = {
|
|
|
|
&m3u_playlist_plugin,
|
2009-10-13 16:31:07 +02:00
|
|
|
&xspf_playlist_plugin,
|
2009-10-12 22:34:04 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/** which plugins have been initialized successfully? */
|
|
|
|
static bool playlist_plugins_enabled[G_N_ELEMENTS(playlist_plugins)];
|
|
|
|
|
2009-10-13 16:19:21 +02:00
|
|
|
/**
|
|
|
|
* Find the "playlist" configuration block for the specified plugin.
|
|
|
|
*
|
|
|
|
* @param plugin_name the name of the playlist plugin
|
|
|
|
* @return the configuration block, or NULL if none was configured
|
|
|
|
*/
|
|
|
|
static const struct config_param *
|
|
|
|
playlist_plugin_config(const char *plugin_name)
|
|
|
|
{
|
|
|
|
const struct config_param *param = NULL;
|
|
|
|
|
|
|
|
assert(plugin_name != NULL);
|
|
|
|
|
|
|
|
while ((param = config_get_next_param(CONF_PLAYLIST_PLUGIN, param)) != NULL) {
|
|
|
|
const char *name =
|
|
|
|
config_get_block_string(param, "name", NULL);
|
|
|
|
if (name == NULL)
|
|
|
|
g_error("playlist configuration without 'plugin' name in line %d",
|
|
|
|
param->line);
|
|
|
|
|
|
|
|
if (strcmp(name, plugin_name) == 0)
|
|
|
|
return param;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-12 22:34:04 +02:00
|
|
|
void
|
|
|
|
playlist_list_global_init(void)
|
|
|
|
{
|
2009-10-13 16:19:21 +02:00
|
|
|
for (unsigned i = 0; playlist_plugins[i] != NULL; ++i) {
|
|
|
|
const struct playlist_plugin *plugin = playlist_plugins[i];
|
|
|
|
const struct config_param *param =
|
|
|
|
playlist_plugin_config(plugin->name);
|
|
|
|
|
|
|
|
if (!config_get_block_bool(param, "enabled", true))
|
|
|
|
/* the plugin is disabled in mpd.conf */
|
|
|
|
continue;
|
|
|
|
|
2009-10-12 22:34:04 +02:00
|
|
|
playlist_plugins_enabled[i] =
|
2009-10-13 16:19:21 +02:00
|
|
|
playlist_plugin_init(playlist_plugins[i], param);
|
|
|
|
}
|
2009-10-12 22:34:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
playlist_list_global_finish(void)
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; playlist_plugins[i] != NULL; ++i)
|
|
|
|
if (playlist_plugins_enabled[i])
|
|
|
|
playlist_plugin_finish(playlist_plugins[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct playlist_provider *
|
|
|
|
playlist_list_open_uri(const char *uri)
|
|
|
|
{
|
|
|
|
char *scheme;
|
2009-10-13 16:13:33 +02:00
|
|
|
struct playlist_provider *playlist = NULL;
|
2009-10-12 22:34:04 +02:00
|
|
|
|
|
|
|
assert(uri != NULL);
|
|
|
|
|
|
|
|
scheme = g_uri_parse_scheme(uri);
|
|
|
|
if (scheme == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
for (unsigned i = 0; playlist_plugins[i] != NULL; ++i) {
|
|
|
|
const struct playlist_plugin *plugin = playlist_plugins[i];
|
|
|
|
|
|
|
|
if (playlist_plugins_enabled[i] &&
|
|
|
|
stringFoundInStringArray(plugin->schemes, scheme)) {
|
|
|
|
playlist = playlist_plugin_open_uri(plugin, uri);
|
|
|
|
if (playlist != NULL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(scheme);
|
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct playlist_provider *
|
|
|
|
playlist_list_open_stream_mime(struct input_stream *is)
|
|
|
|
{
|
|
|
|
struct playlist_provider *playlist;
|
|
|
|
|
|
|
|
assert(is != NULL);
|
|
|
|
assert(is->mime != NULL);
|
|
|
|
|
|
|
|
for (unsigned i = 0; playlist_plugins[i] != NULL; ++i) {
|
|
|
|
const struct playlist_plugin *plugin = playlist_plugins[i];
|
|
|
|
|
|
|
|
if (playlist_plugins_enabled[i] &&
|
|
|
|
stringFoundInStringArray(plugin->mime_types, is->mime)) {
|
|
|
|
playlist = playlist_plugin_open_stream(plugin, is);
|
|
|
|
if (playlist != NULL)
|
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct playlist_provider *
|
|
|
|
playlist_list_open_stream_suffix(struct input_stream *is, const char *suffix)
|
|
|
|
{
|
|
|
|
struct playlist_provider *playlist;
|
|
|
|
|
|
|
|
assert(is != NULL);
|
|
|
|
assert(suffix != NULL);
|
|
|
|
|
|
|
|
for (unsigned i = 0; playlist_plugins[i] != NULL; ++i) {
|
|
|
|
const struct playlist_plugin *plugin = playlist_plugins[i];
|
|
|
|
|
|
|
|
if (playlist_plugins_enabled[i] &&
|
|
|
|
stringFoundInStringArray(plugin->suffixes, suffix)) {
|
|
|
|
playlist = playlist_plugin_open_stream(plugin, is);
|
|
|
|
if (playlist != NULL)
|
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct playlist_provider *
|
|
|
|
playlist_list_open_stream(struct input_stream *is, const char *uri)
|
|
|
|
{
|
|
|
|
const char *suffix;
|
|
|
|
struct playlist_provider *playlist;
|
|
|
|
|
|
|
|
if (is->mime != NULL) {
|
|
|
|
playlist = playlist_list_open_stream_mime(is);
|
|
|
|
if (playlist != NULL)
|
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
suffix = uri != NULL ? uri_get_suffix(uri) : NULL;
|
|
|
|
if (suffix != NULL) {
|
|
|
|
playlist = playlist_list_open_stream_suffix(is, suffix);
|
|
|
|
if (playlist != NULL)
|
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|