2009-10-12 22:34:04 +02:00
|
|
|
/*
|
2013-01-26 01:04:02 +01:00
|
|
|
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
2009-10-12 22:34:04 +02:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2013-01-26 01:04:02 +01:00
|
|
|
#include "PlaylistRegistry.hxx"
|
2013-01-27 17:38:09 +01:00
|
|
|
#include "PlaylistPlugin.hxx"
|
|
|
|
#include "playlist/ExtM3uPlaylistPlugin.hxx"
|
|
|
|
#include "playlist/M3uPlaylistPlugin.hxx"
|
|
|
|
#include "playlist/XspfPlaylistPlugin.hxx"
|
2013-01-26 01:04:02 +01:00
|
|
|
#include "playlist/LastFMPlaylistPlugin.hxx"
|
2013-01-21 18:24:26 +01:00
|
|
|
#include "playlist/DespotifyPlaylistPlugin.hxx"
|
2013-01-26 01:04:02 +01:00
|
|
|
#include "playlist/SoundCloudPlaylistPlugin.hxx"
|
2013-01-27 17:38:09 +01:00
|
|
|
#include "playlist/PlsPlaylistPlugin.hxx"
|
|
|
|
#include "playlist/AsxPlaylistPlugin.hxx"
|
|
|
|
#include "playlist/RssPlaylistPlugin.hxx"
|
|
|
|
#include "playlist/CuePlaylistPlugin.hxx"
|
2013-01-26 01:04:02 +01:00
|
|
|
#include "playlist/EmbeddedCuePlaylistPlugin.hxx"
|
2009-10-12 22:34:04 +02:00
|
|
|
#include "input_stream.h"
|
2013-01-26 01:04:02 +01:00
|
|
|
|
|
|
|
extern "C" {
|
2009-10-12 22:34:04 +02:00
|
|
|
#include "uri.h"
|
2013-01-26 01:04:02 +01:00
|
|
|
}
|
|
|
|
|
2010-12-23 16:13:11 +01:00
|
|
|
#include "string_util.h"
|
2009-10-13 16:19:21 +02:00
|
|
|
#include "conf.h"
|
2010-09-25 15:00:43 +02:00
|
|
|
#include "mpd_error.h"
|
2009-10-12 22:34:04 +02:00
|
|
|
|
|
|
|
#include <assert.h>
|
2009-10-13 16:19:21 +02:00
|
|
|
#include <string.h>
|
2009-11-06 00:11:36 +01:00
|
|
|
#include <stdio.h>
|
2009-10-12 22:34:04 +02:00
|
|
|
|
2012-06-12 22:12:06 +02:00
|
|
|
const struct playlist_plugin *const playlist_plugins[] = {
|
2009-11-06 00:41:42 +01:00
|
|
|
&extm3u_playlist_plugin,
|
2009-10-12 22:34:04 +02:00
|
|
|
&m3u_playlist_plugin,
|
2009-10-13 16:31:07 +02:00
|
|
|
&xspf_playlist_plugin,
|
2009-10-15 00:08:06 +02:00
|
|
|
&pls_playlist_plugin,
|
2009-10-21 23:39:47 +02:00
|
|
|
&asx_playlist_plugin,
|
2010-10-11 20:25:05 +02:00
|
|
|
&rss_playlist_plugin,
|
2011-03-27 08:41:26 +02:00
|
|
|
#ifdef ENABLE_DESPOTIFY
|
|
|
|
&despotify_playlist_plugin,
|
|
|
|
#endif
|
2009-10-13 16:32:10 +02:00
|
|
|
#ifdef ENABLE_LASTFM
|
|
|
|
&lastfm_playlist_plugin,
|
2012-02-27 13:19:45 +01:00
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_SOUNDCLOUD
|
|
|
|
&soundcloud_playlist_plugin,
|
2009-12-16 20:04:36 +01:00
|
|
|
#endif
|
|
|
|
&cue_playlist_plugin,
|
2012-02-12 15:20:38 +01:00
|
|
|
&embcue_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)];
|
|
|
|
|
2012-06-12 22:12:06 +02:00
|
|
|
#define playlist_plugins_for_each_enabled(plugin) \
|
|
|
|
playlist_plugins_for_each(plugin) \
|
|
|
|
if (playlist_plugins_enabled[playlist_plugin_iterator - 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)
|
2010-09-25 15:00:43 +02:00
|
|
|
MPD_ERROR("playlist configuration without 'plugin' name in line %d",
|
2009-10-13 16:19:21 +02:00
|
|
|
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)
|
|
|
|
{
|
2012-06-12 22:12:06 +02:00
|
|
|
playlist_plugins_for_each_enabled(plugin)
|
|
|
|
playlist_plugin_finish(plugin);
|
2009-10-12 22:34:04 +02:00
|
|
|
}
|
|
|
|
|
2009-12-16 21:09:56 +01:00
|
|
|
static struct playlist_provider *
|
2013-01-27 17:20:50 +01:00
|
|
|
playlist_list_open_uri_scheme(const char *uri, Mutex &mutex, Cond &cond,
|
2011-09-14 21:46:41 +02:00
|
|
|
bool *tried)
|
2009-10-12 22:34:04 +02:00
|
|
|
{
|
|
|
|
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];
|
|
|
|
|
2009-12-16 21:09:56 +01:00
|
|
|
assert(!tried[i]);
|
|
|
|
|
2009-12-16 21:23:20 +01:00
|
|
|
if (playlist_plugins_enabled[i] && plugin->open_uri != NULL &&
|
|
|
|
plugin->schemes != NULL &&
|
2009-11-06 19:50:47 +01:00
|
|
|
string_array_contains(plugin->schemes, scheme)) {
|
2011-09-14 21:46:41 +02:00
|
|
|
playlist = playlist_plugin_open_uri(plugin, uri,
|
|
|
|
mutex, cond);
|
2009-10-12 22:34:04 +02:00
|
|
|
if (playlist != NULL)
|
|
|
|
break;
|
2009-12-16 21:09:56 +01:00
|
|
|
|
|
|
|
tried[i] = true;
|
2009-10-12 22:34:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(scheme);
|
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
|
2009-12-16 21:09:56 +01:00
|
|
|
static struct playlist_provider *
|
2013-01-27 17:20:50 +01:00
|
|
|
playlist_list_open_uri_suffix(const char *uri, Mutex &mutex, Cond &cond,
|
2011-09-14 21:46:41 +02:00
|
|
|
const bool *tried)
|
2009-12-16 21:09:56 +01:00
|
|
|
{
|
|
|
|
const char *suffix;
|
|
|
|
struct playlist_provider *playlist = NULL;
|
|
|
|
|
|
|
|
assert(uri != NULL);
|
|
|
|
|
2009-12-26 02:20:40 +01:00
|
|
|
suffix = uri_get_suffix(uri);
|
|
|
|
if (suffix == NULL)
|
2009-12-16 21:09:56 +01:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
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)) {
|
2011-09-14 21:46:41 +02:00
|
|
|
playlist = playlist_plugin_open_uri(plugin, uri,
|
|
|
|
mutex, cond);
|
2009-12-16 21:09:56 +01:00
|
|
|
if (playlist != NULL)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct playlist_provider *
|
2013-01-27 17:20:50 +01:00
|
|
|
playlist_list_open_uri(const char *uri, Mutex &mutex, Cond &cond)
|
2009-12-16 21:09:56 +01:00
|
|
|
{
|
|
|
|
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));
|
|
|
|
|
2011-09-14 21:46:41 +02:00
|
|
|
playlist = playlist_list_open_uri_scheme(uri, mutex, cond, tried);
|
2009-12-16 21:09:56 +01:00
|
|
|
if (playlist == NULL)
|
2011-09-14 21:46:41 +02:00
|
|
|
playlist = playlist_list_open_uri_suffix(uri, mutex, cond,
|
|
|
|
tried);
|
2009-12-16 21:09:56 +01:00
|
|
|
|
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
|
2009-10-12 22:34:04 +02:00
|
|
|
static struct playlist_provider *
|
2010-06-25 22:43:35 +02:00
|
|
|
playlist_list_open_stream_mime2(struct input_stream *is, const char *mime)
|
2009-10-12 22:34:04 +02:00
|
|
|
{
|
|
|
|
struct playlist_provider *playlist;
|
|
|
|
|
|
|
|
assert(is != NULL);
|
2010-06-25 22:43:35 +02:00
|
|
|
assert(mime != NULL);
|
2009-10-12 22:34:04 +02:00
|
|
|
|
2012-06-12 22:12:06 +02:00
|
|
|
playlist_plugins_for_each_enabled(plugin) {
|
|
|
|
if (plugin->open_stream != NULL &&
|
2009-11-06 19:50:47 +01:00
|
|
|
plugin->mime_types != NULL &&
|
2010-06-25 22:43:35 +02:00
|
|
|
string_array_contains(plugin->mime_types, mime)) {
|
2009-11-06 00:11:36 +01:00
|
|
|
/* rewind the stream, so each plugin gets a
|
|
|
|
fresh start */
|
2009-11-14 23:53:04 +01:00
|
|
|
input_stream_seek(is, 0, SEEK_SET, NULL);
|
2009-11-06 00:11:36 +01:00
|
|
|
|
2009-10-12 22:34:04 +02:00
|
|
|
playlist = playlist_plugin_open_stream(plugin, is);
|
|
|
|
if (playlist != NULL)
|
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-06-25 22:43:35 +02:00
|
|
|
static struct playlist_provider *
|
2013-01-24 19:14:40 +01:00
|
|
|
playlist_list_open_stream_mime(struct input_stream *is, const char *full_mime)
|
2010-06-25 22:43:35 +02:00
|
|
|
{
|
2013-01-24 19:14:40 +01:00
|
|
|
assert(full_mime != NULL);
|
2010-06-25 22:43:35 +02:00
|
|
|
|
2013-01-24 19:14:40 +01:00
|
|
|
const char *semicolon = strchr(full_mime, ';');
|
2010-06-25 22:43:35 +02:00
|
|
|
if (semicolon == NULL)
|
2013-01-24 19:14:40 +01:00
|
|
|
return playlist_list_open_stream_mime2(is, full_mime);
|
2010-06-25 22:43:35 +02:00
|
|
|
|
2013-01-24 19:14:40 +01:00
|
|
|
if (semicolon == full_mime)
|
2010-06-25 22:43:35 +02:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* probe only the portion before the semicolon*/
|
2013-01-24 19:14:40 +01:00
|
|
|
char *mime = g_strndup(full_mime, semicolon - full_mime);
|
2010-06-25 22:43:35 +02:00
|
|
|
struct playlist_provider *playlist =
|
|
|
|
playlist_list_open_stream_mime2(is, mime);
|
|
|
|
g_free(mime);
|
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
|
2009-10-12 22:34:04 +02:00
|
|
|
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);
|
|
|
|
|
2012-06-12 22:12:06 +02:00
|
|
|
playlist_plugins_for_each_enabled(plugin) {
|
|
|
|
if (plugin->open_stream != NULL &&
|
2009-12-16 21:23:20 +01:00
|
|
|
plugin->suffixes != NULL &&
|
2009-11-06 19:50:47 +01:00
|
|
|
string_array_contains(plugin->suffixes, suffix)) {
|
2009-11-06 00:11:36 +01:00
|
|
|
/* rewind the stream, so each plugin gets a
|
|
|
|
fresh start */
|
2009-11-14 23:53:04 +01:00
|
|
|
input_stream_seek(is, 0, SEEK_SET, NULL);
|
2009-11-06 00:11:36 +01:00
|
|
|
|
2009-10-12 22:34:04 +02:00
|
|
|
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;
|
|
|
|
|
2011-09-14 21:46:41 +02:00
|
|
|
input_stream_lock_wait_ready(is);
|
2010-06-25 22:37:20 +02:00
|
|
|
|
2013-01-24 19:14:40 +01:00
|
|
|
const char *const mime = input_stream_get_mime_type(is);
|
|
|
|
if (mime != NULL) {
|
|
|
|
playlist = playlist_list_open_stream_mime(is, mime);
|
2009-10-12 22:34:04 +02:00
|
|
|
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;
|
|
|
|
}
|
2009-11-06 01:07:39 +01:00
|
|
|
|
2010-05-31 23:29:18 +02:00
|
|
|
bool
|
2009-11-06 01:07:39 +01:00
|
|
|
playlist_suffix_supported(const char *suffix)
|
|
|
|
{
|
|
|
|
assert(suffix != NULL);
|
|
|
|
|
2012-06-12 22:12:06 +02:00
|
|
|
playlist_plugins_for_each_enabled(plugin) {
|
|
|
|
if (plugin->suffixes != NULL &&
|
2009-11-06 19:50:47 +01:00
|
|
|
string_array_contains(plugin->suffixes, suffix))
|
2009-11-06 01:07:39 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct playlist_provider *
|
2013-01-27 17:20:50 +01:00
|
|
|
playlist_list_open_path(const char *path_fs, Mutex &mutex, Cond &cond,
|
2011-09-14 21:46:41 +02:00
|
|
|
struct input_stream **is_r)
|
2009-11-06 01:07:39 +01:00
|
|
|
{
|
2009-11-14 23:53:04 +01:00
|
|
|
GError *error = NULL;
|
2009-11-06 01:07:39 +01:00
|
|
|
const char *suffix;
|
2009-12-30 23:27:37 +01:00
|
|
|
struct input_stream *is;
|
2009-11-06 01:07:39 +01:00
|
|
|
struct playlist_provider *playlist;
|
|
|
|
|
|
|
|
assert(path_fs != NULL);
|
|
|
|
|
|
|
|
suffix = uri_get_suffix(path_fs);
|
2009-11-14 23:53:04 +01:00
|
|
|
if (suffix == NULL || !playlist_suffix_supported(suffix))
|
2009-11-06 01:07:39 +01:00
|
|
|
return NULL;
|
|
|
|
|
2011-09-14 21:46:41 +02:00
|
|
|
is = input_stream_open(path_fs, mutex, cond, &error);
|
2009-12-30 23:27:37 +01:00
|
|
|
if (is == NULL) {
|
2009-11-14 23:53:04 +01:00
|
|
|
if (error != NULL) {
|
|
|
|
g_warning("%s", error->message);
|
|
|
|
g_error_free(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-09-14 21:46:41 +02:00
|
|
|
input_stream_lock_wait_ready(is);
|
2009-12-27 16:53:47 +01:00
|
|
|
|
2009-11-06 01:07:39 +01:00
|
|
|
playlist = playlist_list_open_stream_suffix(is, suffix);
|
2010-06-01 09:10:58 +02:00
|
|
|
if (playlist != NULL)
|
|
|
|
*is_r = is;
|
|
|
|
else
|
2009-11-06 01:07:39 +01:00
|
|
|
input_stream_close(is);
|
|
|
|
|
|
|
|
return playlist;
|
|
|
|
}
|