playlist/Plugin: add SupportsSuffix(), SupportsMimeType()
This commit is contained in:
parent
2038620bc4
commit
4d11745156
43
src/playlist/PlaylistPlugin.cxx
Normal file
43
src/playlist/PlaylistPlugin.cxx
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2003-2019 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 "PlaylistPlugin.hxx"
|
||||||
|
#include "util/StringUtil.hxx"
|
||||||
|
#include "util/StringView.hxx"
|
||||||
|
|
||||||
|
bool
|
||||||
|
PlaylistPlugin::SupportsScheme(StringView scheme) const noexcept
|
||||||
|
{
|
||||||
|
return schemes != nullptr &&
|
||||||
|
StringArrayContainsCase(schemes, scheme);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
PlaylistPlugin::SupportsSuffix(const char *suffix) const noexcept
|
||||||
|
{
|
||||||
|
return suffixes != nullptr &&
|
||||||
|
StringArrayContainsCase(suffixes, suffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
PlaylistPlugin::SupportsMimeType(StringView mime_type) const noexcept
|
||||||
|
{
|
||||||
|
return mime_types != nullptr &&
|
||||||
|
StringArrayContainsCase(mime_types, mime_type);
|
||||||
|
}
|
@ -22,9 +22,11 @@
|
|||||||
|
|
||||||
#include "input/Ptr.hxx"
|
#include "input/Ptr.hxx"
|
||||||
#include "thread/Mutex.hxx"
|
#include "thread/Mutex.hxx"
|
||||||
|
#include "util/Compiler.h"
|
||||||
|
|
||||||
struct ConfigBlock;
|
struct ConfigBlock;
|
||||||
struct Tag;
|
struct Tag;
|
||||||
|
struct StringView;
|
||||||
class SongEnumerator;
|
class SongEnumerator;
|
||||||
|
|
||||||
struct PlaylistPlugin {
|
struct PlaylistPlugin {
|
||||||
@ -101,6 +103,24 @@ struct PlaylistPlugin {
|
|||||||
copy.mime_types = _mime_types;
|
copy.mime_types = _mime_types;
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does the plugin announce the specified URI scheme?
|
||||||
|
*/
|
||||||
|
gcc_pure gcc_nonnull_all
|
||||||
|
bool SupportsScheme(StringView scheme) const noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does the plugin announce the specified file name suffix?
|
||||||
|
*/
|
||||||
|
gcc_pure gcc_nonnull_all
|
||||||
|
bool SupportsSuffix(const char *suffix) const noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does the plugin announce the specified MIME type?
|
||||||
|
*/
|
||||||
|
gcc_pure gcc_nonnull_all
|
||||||
|
bool SupportsMimeType(StringView mime_type) const noexcept;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
#include "plugins/EmbeddedCuePlaylistPlugin.hxx"
|
#include "plugins/EmbeddedCuePlaylistPlugin.hxx"
|
||||||
#include "input/InputStream.hxx"
|
#include "input/InputStream.hxx"
|
||||||
#include "util/MimeType.hxx"
|
#include "util/MimeType.hxx"
|
||||||
#include "util/StringUtil.hxx"
|
|
||||||
#include "util/StringView.hxx"
|
#include "util/StringView.hxx"
|
||||||
#include "util/UriExtract.hxx"
|
#include "util/UriExtract.hxx"
|
||||||
#include "config/Data.hxx"
|
#include "config/Data.hxx"
|
||||||
@ -122,8 +121,7 @@ playlist_list_open_uri_scheme(const char *uri, Mutex &mutex,
|
|||||||
assert(!tried[i]);
|
assert(!tried[i]);
|
||||||
|
|
||||||
if (playlist_plugins_enabled[i] && plugin->open_uri != nullptr &&
|
if (playlist_plugins_enabled[i] && plugin->open_uri != nullptr &&
|
||||||
plugin->schemes != nullptr &&
|
plugin->SupportsScheme(scheme)) {
|
||||||
StringArrayContainsCase(plugin->schemes, scheme)) {
|
|
||||||
auto playlist = plugin->open_uri(uri, mutex);
|
auto playlist = plugin->open_uri(uri, mutex);
|
||||||
if (playlist)
|
if (playlist)
|
||||||
return playlist;
|
return playlist;
|
||||||
@ -150,8 +148,8 @@ playlist_list_open_uri_suffix(const char *uri, Mutex &mutex,
|
|||||||
const auto *plugin = playlist_plugins[i];
|
const auto *plugin = playlist_plugins[i];
|
||||||
|
|
||||||
if (playlist_plugins_enabled[i] && !tried[i] &&
|
if (playlist_plugins_enabled[i] && !tried[i] &&
|
||||||
plugin->open_uri != nullptr && plugin->suffixes != nullptr &&
|
plugin->open_uri != nullptr &&
|
||||||
StringArrayContainsCase(plugin->suffixes, suffix)) {
|
plugin->SupportsSuffix(suffix)) {
|
||||||
auto playlist = plugin->open_uri(uri, mutex);
|
auto playlist = plugin->open_uri(uri, mutex);
|
||||||
if (playlist != nullptr)
|
if (playlist != nullptr)
|
||||||
return playlist;
|
return playlist;
|
||||||
@ -183,8 +181,7 @@ playlist_list_open_stream_mime2(InputStreamPtr &&is, StringView mime)
|
|||||||
{
|
{
|
||||||
playlist_plugins_for_each_enabled(plugin) {
|
playlist_plugins_for_each_enabled(plugin) {
|
||||||
if (plugin->open_stream != nullptr &&
|
if (plugin->open_stream != nullptr &&
|
||||||
plugin->mime_types != nullptr &&
|
plugin->SupportsMimeType(mime)) {
|
||||||
StringArrayContainsCase(plugin->mime_types, mime)) {
|
|
||||||
/* rewind the stream, so each plugin gets a
|
/* rewind the stream, so each plugin gets a
|
||||||
fresh start */
|
fresh start */
|
||||||
try {
|
try {
|
||||||
@ -233,8 +230,7 @@ playlist_list_open_stream_suffix(InputStreamPtr &&is, const char *suffix)
|
|||||||
|
|
||||||
playlist_plugins_for_each_enabled(plugin) {
|
playlist_plugins_for_each_enabled(plugin) {
|
||||||
if (plugin->open_stream != nullptr &&
|
if (plugin->open_stream != nullptr &&
|
||||||
plugin->suffixes != nullptr &&
|
plugin->SupportsSuffix(suffix)) {
|
||||||
StringArrayContainsCase(plugin->suffixes, suffix)) {
|
|
||||||
/* rewind the stream, so each plugin gets a
|
/* rewind the stream, so each plugin gets a
|
||||||
fresh start */
|
fresh start */
|
||||||
try {
|
try {
|
||||||
@ -284,8 +280,7 @@ playlist_suffix_supported(const char *suffix) noexcept
|
|||||||
assert(suffix != nullptr);
|
assert(suffix != nullptr);
|
||||||
|
|
||||||
playlist_plugins_for_each_enabled(plugin) {
|
playlist_plugins_for_each_enabled(plugin) {
|
||||||
if (plugin->suffixes != nullptr &&
|
if (plugin->SupportsSuffix(suffix))
|
||||||
StringArrayContainsCase(plugin->suffixes, suffix))
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
playlist_api = static_library(
|
playlist_api = static_library(
|
||||||
'playlist_api',
|
'playlist_api',
|
||||||
|
'PlaylistPlugin.cxx',
|
||||||
'MemorySongEnumerator.cxx',
|
'MemorySongEnumerator.cxx',
|
||||||
include_directories: inc,
|
include_directories: inc,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user