2010-02-08 10:56:28 +01:00
|
|
|
/*
|
2021-01-01 19:54:25 +01:00
|
|
|
* Copyright 2003-2021 The Music Player Daemon Project
|
2010-02-08 10:56:28 +01: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.
|
|
|
|
*/
|
|
|
|
|
2013-01-02 18:38:32 +01:00
|
|
|
#include "PlaylistMapper.hxx"
|
2012-09-28 00:40:00 +02:00
|
|
|
#include "PlaylistFile.hxx"
|
2014-02-07 21:29:31 +01:00
|
|
|
#include "PlaylistStream.hxx"
|
2018-01-20 19:56:44 +01:00
|
|
|
#include "SongEnumerator.hxx"
|
2013-01-02 22:43:56 +01:00
|
|
|
#include "Mapper.hxx"
|
2013-10-17 21:59:35 +02:00
|
|
|
#include "fs/AllocatedPath.hxx"
|
2014-02-07 20:22:26 +01:00
|
|
|
#include "storage/StorageInterface.hxx"
|
2013-04-08 23:30:21 +02:00
|
|
|
#include "util/UriUtil.hxx"
|
2010-02-08 10:56:28 +01:00
|
|
|
|
2020-03-12 23:20:59 +01:00
|
|
|
#include <cassert>
|
2010-02-08 10:56:28 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load a playlist from the configured playlist directory.
|
|
|
|
*/
|
2018-01-20 19:56:44 +01:00
|
|
|
static std::unique_ptr<SongEnumerator>
|
2018-06-22 19:37:18 +02:00
|
|
|
playlist_open_in_playlist_dir(const char *uri, Mutex &mutex)
|
2010-02-08 10:56:28 +01:00
|
|
|
{
|
|
|
|
assert(spl_valid_name(uri));
|
|
|
|
|
2014-05-10 19:00:46 +02:00
|
|
|
const auto path_fs = map_spl_utf8_to_fs(uri);
|
|
|
|
if (path_fs.IsNull())
|
2013-10-02 08:13:28 +02:00
|
|
|
return nullptr;
|
2010-02-08 10:56:28 +01:00
|
|
|
|
2018-06-22 19:37:18 +02:00
|
|
|
return playlist_open_path(path_fs, mutex);
|
2010-02-08 10:56:28 +01:00
|
|
|
}
|
|
|
|
|
2014-01-30 20:29:48 +01:00
|
|
|
#ifdef ENABLE_DATABASE
|
|
|
|
|
2010-02-08 10:56:28 +01:00
|
|
|
/**
|
|
|
|
* Load a playlist from the configured music directory.
|
|
|
|
*/
|
2018-01-20 19:56:44 +01:00
|
|
|
static std::unique_ptr<SongEnumerator>
|
2018-06-22 19:37:18 +02:00
|
|
|
playlist_open_in_storage(const char *uri, const Storage *storage, Mutex &mutex)
|
2010-02-08 10:56:28 +01:00
|
|
|
{
|
|
|
|
assert(uri_safe_local(uri));
|
|
|
|
|
2014-02-07 20:22:26 +01:00
|
|
|
if (storage == nullptr)
|
2013-10-02 08:13:28 +02:00
|
|
|
return nullptr;
|
2010-02-08 10:56:28 +01:00
|
|
|
|
2014-02-07 20:22:26 +01:00
|
|
|
{
|
|
|
|
const auto path = storage->MapFS(uri);
|
|
|
|
if (!path.IsNull())
|
2018-06-22 19:37:18 +02:00
|
|
|
return playlist_open_path(path, mutex);
|
2014-02-07 20:22:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const auto uri2 = storage->MapUTF8(uri);
|
2018-06-22 19:37:18 +02:00
|
|
|
return playlist_open_remote(uri2.c_str(), mutex);
|
2010-02-08 10:56:28 +01:00
|
|
|
}
|
|
|
|
|
2014-01-30 20:29:48 +01:00
|
|
|
#endif
|
|
|
|
|
2018-01-20 19:56:44 +01:00
|
|
|
std::unique_ptr<SongEnumerator>
|
2014-02-07 20:22:26 +01:00
|
|
|
playlist_mapper_open(const char *uri,
|
|
|
|
#ifdef ENABLE_DATABASE
|
|
|
|
const Storage *storage,
|
|
|
|
#endif
|
2018-06-22 19:37:18 +02:00
|
|
|
Mutex &mutex)
|
2010-02-08 10:56:28 +01:00
|
|
|
{
|
|
|
|
if (spl_valid_name(uri)) {
|
2018-06-22 19:37:18 +02:00
|
|
|
auto playlist = playlist_open_in_playlist_dir(uri, mutex);
|
2013-10-02 08:13:28 +02:00
|
|
|
if (playlist != nullptr)
|
2010-02-08 10:56:28 +01:00
|
|
|
return playlist;
|
|
|
|
}
|
|
|
|
|
2014-01-30 20:29:48 +01:00
|
|
|
#ifdef ENABLE_DATABASE
|
2010-02-08 10:56:28 +01:00
|
|
|
if (uri_safe_local(uri)) {
|
2018-06-22 19:37:18 +02:00
|
|
|
auto playlist = playlist_open_in_storage(uri, storage, mutex);
|
2013-10-02 08:13:28 +02:00
|
|
|
if (playlist != nullptr)
|
2010-02-08 10:56:28 +01:00
|
|
|
return playlist;
|
|
|
|
}
|
2014-01-30 20:29:48 +01:00
|
|
|
#endif
|
2010-02-08 10:56:28 +01:00
|
|
|
|
2013-10-02 08:13:28 +02:00
|
|
|
return nullptr;
|
2010-02-08 10:56:28 +01:00
|
|
|
}
|