2009-10-12 22:34:04 +02:00
|
|
|
/*
|
2020-01-18 19:22:19 +01:00
|
|
|
* Copyright 2003-2020 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"
|
2018-01-20 19:56:44 +01:00
|
|
|
#include "SongEnumerator.hxx"
|
2020-05-05 14:45:18 +02:00
|
|
|
#include "playlist/Features.h"
|
2014-01-23 23:30:12 +01:00
|
|
|
#include "plugins/ExtM3uPlaylistPlugin.hxx"
|
|
|
|
#include "plugins/M3uPlaylistPlugin.hxx"
|
|
|
|
#include "plugins/XspfPlaylistPlugin.hxx"
|
|
|
|
#include "plugins/SoundCloudPlaylistPlugin.hxx"
|
|
|
|
#include "plugins/PlsPlaylistPlugin.hxx"
|
|
|
|
#include "plugins/AsxPlaylistPlugin.hxx"
|
|
|
|
#include "plugins/RssPlaylistPlugin.hxx"
|
2015-10-26 13:16:01 +01:00
|
|
|
#include "plugins/FlacPlaylistPlugin.hxx"
|
2014-01-23 23:30:12 +01:00
|
|
|
#include "plugins/CuePlaylistPlugin.hxx"
|
|
|
|
#include "plugins/EmbeddedCuePlaylistPlugin.hxx"
|
2020-05-05 14:45:18 +02:00
|
|
|
#include "decoder/Features.h"
|
2014-01-24 16:18:21 +01:00
|
|
|
#include "input/InputStream.hxx"
|
2016-06-10 22:24:13 +02:00
|
|
|
#include "util/MimeType.hxx"
|
2019-06-11 19:30:33 +02:00
|
|
|
#include "util/StringView.hxx"
|
2019-08-09 15:54:13 +02:00
|
|
|
#include "util/UriExtract.hxx"
|
2018-07-17 22:10:32 +02:00
|
|
|
#include "config/Data.hxx"
|
2015-01-21 22:13:44 +01:00
|
|
|
#include "config/Block.hxx"
|
2009-10-12 22:34:04 +02:00
|
|
|
|
2020-03-12 23:20:59 +01:00
|
|
|
#include <cassert>
|
2019-08-03 13:10:49 +02:00
|
|
|
#include <iterator>
|
|
|
|
|
2019-09-01 14:58:49 +02:00
|
|
|
const PlaylistPlugin *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-15 00:08:06 +02:00
|
|
|
&pls_playlist_plugin,
|
2014-11-21 22:19:57 +01:00
|
|
|
#ifdef ENABLE_EXPAT
|
2014-01-09 11:57:47 +01:00
|
|
|
&xspf_playlist_plugin,
|
2009-10-21 23:39:47 +02:00
|
|
|
&asx_playlist_plugin,
|
2010-10-11 20:25:05 +02:00
|
|
|
&rss_playlist_plugin,
|
2014-01-09 11:57:47 +01:00
|
|
|
#endif
|
2012-02-27 13:19:45 +01:00
|
|
|
#ifdef ENABLE_SOUNDCLOUD
|
|
|
|
&soundcloud_playlist_plugin,
|
2009-12-16 20:04:36 +01:00
|
|
|
#endif
|
2015-10-26 13:16:01 +01:00
|
|
|
#ifdef ENABLE_FLAC
|
|
|
|
&flac_playlist_plugin,
|
|
|
|
#endif
|
2014-12-08 18:38:03 +01:00
|
|
|
#ifdef ENABLE_CUE
|
2009-12-16 20:04:36 +01:00
|
|
|
&cue_playlist_plugin,
|
2012-02-12 15:20:38 +01:00
|
|
|
&embcue_playlist_plugin,
|
2014-12-08 18:38:03 +01:00
|
|
|
#endif
|
2013-10-02 08:13:28 +02:00
|
|
|
nullptr
|
2009-10-12 22:34:04 +02:00
|
|
|
};
|
|
|
|
|
2013-10-15 22:04:17 +02:00
|
|
|
static constexpr unsigned n_playlist_plugins =
|
2019-08-03 13:10:49 +02:00
|
|
|
std::size(playlist_plugins) - 1;
|
2013-10-15 22:04:17 +02:00
|
|
|
|
2009-10-12 22:34:04 +02:00
|
|
|
/** which plugins have been initialized successfully? */
|
2013-10-15 22:04:17 +02:00
|
|
|
static bool playlist_plugins_enabled[n_playlist_plugins];
|
2009-10-12 22:34:04 +02:00
|
|
|
|
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-12 22:34:04 +02:00
|
|
|
void
|
2018-07-17 22:10:32 +02:00
|
|
|
playlist_list_global_init(const ConfigData &config)
|
2009-10-12 22:34:04 +02:00
|
|
|
{
|
2015-01-21 22:13:44 +01:00
|
|
|
const ConfigBlock empty;
|
2013-08-04 13:54:14 +02:00
|
|
|
|
2013-10-02 08:13:28 +02:00
|
|
|
for (unsigned i = 0; playlist_plugins[i] != nullptr; ++i) {
|
2019-09-01 14:58:49 +02:00
|
|
|
const auto *plugin = playlist_plugins[i];
|
2015-01-21 22:36:13 +01:00
|
|
|
const auto *param =
|
2018-07-17 22:10:32 +02:00
|
|
|
config.FindBlock(ConfigBlockOption::PLAYLIST_PLUGIN,
|
|
|
|
"name", plugin->name);
|
2013-08-04 13:54:14 +02:00
|
|
|
if (param == nullptr)
|
|
|
|
param = ∅
|
|
|
|
else if (!param->GetBlockValue("enabled", true))
|
2009-10-13 16:19:21 +02:00
|
|
|
/* the plugin is disabled in mpd.conf */
|
|
|
|
continue;
|
|
|
|
|
2018-07-17 21:08:41 +02:00
|
|
|
if (param != nullptr)
|
|
|
|
param->SetUsed();
|
|
|
|
|
2009-10-12 22:34:04 +02:00
|
|
|
playlist_plugins_enabled[i] =
|
2013-08-04 13:54:14 +02:00
|
|
|
playlist_plugin_init(playlist_plugins[i], *param);
|
2009-10-13 16:19:21 +02:00
|
|
|
}
|
2009-10-12 22:34:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-01-21 11:24:17 +01:00
|
|
|
playlist_list_global_finish() noexcept
|
2009-10-12 22:34:04 +02:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2018-01-20 19:56:44 +01:00
|
|
|
static std::unique_ptr<SongEnumerator>
|
2018-06-22 19:37:18 +02:00
|
|
|
playlist_list_open_uri_scheme(const char *uri, Mutex &mutex,
|
2011-09-14 21:46:41 +02:00
|
|
|
bool *tried)
|
2009-10-12 22:34:04 +02:00
|
|
|
{
|
2013-10-02 08:13:28 +02:00
|
|
|
assert(uri != nullptr);
|
2009-10-12 22:34:04 +02:00
|
|
|
|
2013-12-15 17:05:18 +01:00
|
|
|
const auto scheme = uri_get_scheme(uri);
|
|
|
|
if (scheme.empty())
|
2013-10-02 08:13:28 +02:00
|
|
|
return nullptr;
|
2009-10-12 22:34:04 +02:00
|
|
|
|
2013-10-02 08:13:28 +02:00
|
|
|
for (unsigned i = 0; playlist_plugins[i] != nullptr; ++i) {
|
2019-09-01 14:58:49 +02:00
|
|
|
const auto *plugin = playlist_plugins[i];
|
2009-10-12 22:34:04 +02:00
|
|
|
|
2009-12-16 21:09:56 +01:00
|
|
|
assert(!tried[i]);
|
|
|
|
|
2013-10-02 08:13:28 +02:00
|
|
|
if (playlist_plugins_enabled[i] && plugin->open_uri != nullptr &&
|
2019-09-02 20:19:47 +02:00
|
|
|
plugin->SupportsScheme(scheme)) {
|
2018-06-22 19:37:18 +02:00
|
|
|
auto playlist = plugin->open_uri(uri, mutex);
|
2018-01-20 19:56:44 +01:00
|
|
|
if (playlist)
|
|
|
|
return playlist;
|
2009-12-16 21:09:56 +01:00
|
|
|
|
|
|
|
tried[i] = true;
|
2009-10-12 22:34:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-20 19:56:44 +01:00
|
|
|
return nullptr;
|
2009-10-12 22:34:04 +02:00
|
|
|
}
|
|
|
|
|
2018-01-20 19:56:44 +01:00
|
|
|
static std::unique_ptr<SongEnumerator>
|
2018-06-22 19:37:18 +02:00
|
|
|
playlist_list_open_uri_suffix(const char *uri, Mutex &mutex,
|
2011-09-14 21:46:41 +02:00
|
|
|
const bool *tried)
|
2009-12-16 21:09:56 +01:00
|
|
|
{
|
2013-10-02 08:13:28 +02:00
|
|
|
assert(uri != nullptr);
|
2009-12-16 21:09:56 +01:00
|
|
|
|
2014-11-01 13:20:39 +01:00
|
|
|
UriSuffixBuffer suffix_buffer;
|
|
|
|
const char *const suffix = uri_get_suffix(uri, suffix_buffer);
|
2013-10-02 08:13:28 +02:00
|
|
|
if (suffix == nullptr)
|
|
|
|
return nullptr;
|
2009-12-16 21:09:56 +01:00
|
|
|
|
2013-10-02 08:13:28 +02:00
|
|
|
for (unsigned i = 0; playlist_plugins[i] != nullptr; ++i) {
|
2019-09-01 14:58:49 +02:00
|
|
|
const auto *plugin = playlist_plugins[i];
|
2009-12-16 21:09:56 +01:00
|
|
|
|
|
|
|
if (playlist_plugins_enabled[i] && !tried[i] &&
|
2019-09-02 20:19:47 +02:00
|
|
|
plugin->open_uri != nullptr &&
|
|
|
|
plugin->SupportsSuffix(suffix)) {
|
2018-06-22 19:37:18 +02:00
|
|
|
auto playlist = plugin->open_uri(uri, mutex);
|
2013-10-02 08:13:28 +02:00
|
|
|
if (playlist != nullptr)
|
2018-01-20 19:56:44 +01:00
|
|
|
return playlist;
|
2009-12-16 21:09:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-20 19:56:44 +01:00
|
|
|
return nullptr;
|
2009-12-16 21:09:56 +01:00
|
|
|
}
|
|
|
|
|
2018-01-20 19:56:44 +01:00
|
|
|
std::unique_ptr<SongEnumerator>
|
2018-06-22 19:37:18 +02:00
|
|
|
playlist_list_open_uri(const char *uri, Mutex &mutex)
|
2009-12-16 21:09:56 +01:00
|
|
|
{
|
|
|
|
/** this array tracks which plugins have already been tried by
|
|
|
|
playlist_list_open_uri_scheme() */
|
2019-06-11 19:26:24 +02:00
|
|
|
bool tried[n_playlist_plugins]{};
|
2009-12-16 21:09:56 +01:00
|
|
|
|
2013-10-02 08:13:28 +02:00
|
|
|
assert(uri != nullptr);
|
2009-12-16 21:09:56 +01:00
|
|
|
|
2018-06-22 19:37:18 +02:00
|
|
|
auto playlist = playlist_list_open_uri_scheme(uri, mutex, tried);
|
2013-10-02 08:13:28 +02:00
|
|
|
if (playlist == nullptr)
|
2018-06-22 19:37:18 +02:00
|
|
|
playlist = playlist_list_open_uri_suffix(uri, mutex,
|
2011-09-14 21:46:41 +02:00
|
|
|
tried);
|
2009-12-16 21:09:56 +01:00
|
|
|
|
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
|
2018-01-20 19:56:44 +01:00
|
|
|
static std::unique_ptr<SongEnumerator>
|
2019-06-11 19:30:33 +02:00
|
|
|
playlist_list_open_stream_mime2(InputStreamPtr &&is, StringView mime)
|
2009-10-12 22:34:04 +02:00
|
|
|
{
|
2012-06-12 22:12:06 +02:00
|
|
|
playlist_plugins_for_each_enabled(plugin) {
|
2013-10-02 08:13:28 +02:00
|
|
|
if (plugin->open_stream != nullptr &&
|
2019-09-02 20:19:47 +02:00
|
|
|
plugin->SupportsMimeType(mime)) {
|
2009-11-06 00:11:36 +01:00
|
|
|
/* rewind the stream, so each plugin gets a
|
|
|
|
fresh start */
|
2016-09-09 18:47:42 +02:00
|
|
|
try {
|
2017-11-14 21:19:22 +01:00
|
|
|
is->LockRewind();
|
2017-12-19 10:56:23 +01:00
|
|
|
} catch (...) {
|
2016-09-09 18:47:42 +02:00
|
|
|
}
|
2009-11-06 00:11:36 +01:00
|
|
|
|
2018-01-20 19:58:11 +01:00
|
|
|
auto playlist = plugin->open_stream(std::move(is));
|
2013-10-02 08:13:28 +02:00
|
|
|
if (playlist != nullptr)
|
2009-10-12 22:34:04 +02:00
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-02 08:13:28 +02:00
|
|
|
return nullptr;
|
2009-10-12 22:34:04 +02:00
|
|
|
}
|
|
|
|
|
2019-06-11 19:32:45 +02:00
|
|
|
/**
|
|
|
|
* Extract the "main" part of a MIME type string, i.e. the portion
|
|
|
|
* before the semicolon (if one exists).
|
|
|
|
*/
|
|
|
|
gcc_pure
|
|
|
|
static StringView
|
|
|
|
ExtractMimeTypeMainPart(StringView s) noexcept
|
|
|
|
{
|
|
|
|
const auto separator = s.Find(';');
|
|
|
|
if (separator != nullptr)
|
|
|
|
s.SetEnd(separator);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2018-01-20 19:56:44 +01:00
|
|
|
static std::unique_ptr<SongEnumerator>
|
2016-02-21 12:53:47 +01:00
|
|
|
playlist_list_open_stream_mime(InputStreamPtr &&is, const char *full_mime)
|
2010-06-25 22:43:35 +02:00
|
|
|
{
|
2013-10-02 08:13:28 +02:00
|
|
|
assert(full_mime != nullptr);
|
2010-06-25 22:43:35 +02:00
|
|
|
|
|
|
|
/* probe only the portion before the semicolon*/
|
2019-06-11 19:32:45 +02:00
|
|
|
return playlist_list_open_stream_mime2(std::move(is),
|
|
|
|
ExtractMimeTypeMainPart(full_mime));
|
2010-06-25 22:43:35 +02:00
|
|
|
}
|
|
|
|
|
2018-01-20 19:56:44 +01:00
|
|
|
std::unique_ptr<SongEnumerator>
|
2016-02-21 12:53:47 +01:00
|
|
|
playlist_list_open_stream_suffix(InputStreamPtr &&is, const char *suffix)
|
2009-10-12 22:34:04 +02:00
|
|
|
{
|
2013-10-02 08:13:28 +02:00
|
|
|
assert(suffix != nullptr);
|
2009-10-12 22:34:04 +02:00
|
|
|
|
2012-06-12 22:12:06 +02:00
|
|
|
playlist_plugins_for_each_enabled(plugin) {
|
2013-10-02 08:13:28 +02:00
|
|
|
if (plugin->open_stream != nullptr &&
|
2019-09-02 20:19:47 +02:00
|
|
|
plugin->SupportsSuffix(suffix)) {
|
2009-11-06 00:11:36 +01:00
|
|
|
/* rewind the stream, so each plugin gets a
|
|
|
|
fresh start */
|
2016-09-09 18:47:42 +02:00
|
|
|
try {
|
2017-11-14 21:19:22 +01:00
|
|
|
is->LockRewind();
|
2017-12-19 10:56:23 +01:00
|
|
|
} catch (...) {
|
2016-09-09 18:47:42 +02:00
|
|
|
}
|
2009-11-06 00:11:36 +01:00
|
|
|
|
2018-01-20 19:58:11 +01:00
|
|
|
auto playlist = plugin->open_stream(std::move(is));
|
2013-10-02 08:13:28 +02:00
|
|
|
if (playlist != nullptr)
|
2009-10-12 22:34:04 +02:00
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-02 08:13:28 +02:00
|
|
|
return nullptr;
|
2009-10-12 22:34:04 +02:00
|
|
|
}
|
|
|
|
|
2018-01-20 19:56:44 +01:00
|
|
|
std::unique_ptr<SongEnumerator>
|
2016-02-21 12:53:47 +01:00
|
|
|
playlist_list_open_stream(InputStreamPtr &&is, const char *uri)
|
2009-10-12 22:34:04 +02:00
|
|
|
{
|
2016-02-21 12:53:47 +01:00
|
|
|
assert(is->IsReady());
|
2010-06-25 22:37:20 +02:00
|
|
|
|
2016-02-21 12:53:47 +01:00
|
|
|
const char *const mime = is->GetMimeType();
|
2013-10-02 08:13:28 +02:00
|
|
|
if (mime != nullptr) {
|
2016-02-21 12:53:47 +01:00
|
|
|
auto playlist = playlist_list_open_stream_mime(std::move(is),
|
2016-06-10 22:24:13 +02:00
|
|
|
GetMimeTypeBase(mime).c_str());
|
2013-10-02 08:13:28 +02:00
|
|
|
if (playlist != nullptr)
|
2009-10-12 22:34:04 +02:00
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
|
2014-11-01 13:20:39 +01:00
|
|
|
UriSuffixBuffer suffix_buffer;
|
|
|
|
const char *suffix = uri != nullptr
|
|
|
|
? uri_get_suffix(uri, suffix_buffer)
|
|
|
|
: nullptr;
|
2013-10-02 08:13:28 +02:00
|
|
|
if (suffix != nullptr) {
|
2016-02-21 12:53:47 +01:00
|
|
|
auto playlist = playlist_list_open_stream_suffix(std::move(is),
|
|
|
|
suffix);
|
2013-10-02 08:13:28 +02:00
|
|
|
if (playlist != nullptr)
|
2009-10-12 22:34:04 +02:00
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
|
2013-10-02 08:13:28 +02:00
|
|
|
return nullptr;
|
2009-10-12 22:34:04 +02:00
|
|
|
}
|
2009-11-06 01:07:39 +01:00
|
|
|
|
2019-09-02 20:28:14 +02:00
|
|
|
const PlaylistPlugin *
|
|
|
|
FindPlaylistPluginBySuffix(const char *suffix) noexcept
|
2009-11-06 01:07:39 +01:00
|
|
|
{
|
2013-10-02 08:13:28 +02:00
|
|
|
assert(suffix != nullptr);
|
2009-11-06 01:07:39 +01:00
|
|
|
|
2012-06-12 22:12:06 +02:00
|
|
|
playlist_plugins_for_each_enabled(plugin) {
|
2019-09-02 20:19:47 +02:00
|
|
|
if (plugin->SupportsSuffix(suffix))
|
2019-09-02 20:28:14 +02:00
|
|
|
return plugin;
|
2009-11-06 01:07:39 +01:00
|
|
|
}
|
|
|
|
|
2019-09-02 20:28:14 +02:00
|
|
|
return nullptr;
|
2009-11-06 01:07:39 +01:00
|
|
|
}
|