You need to sign in or sign up before continuing.
Commit b3a45833 authored by Stefano Miccoli's avatar Stefano Miccoli

allow loading playlists specified as absolute filesystem paths

implement for the "load" command the same logic used for the "add" command: local clients can load playlist specified as absolute paths. For relative paths the old logic is preserved: first look for a stored playlist, then look in the music directory.
parent 281461f0
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "util/UriUtil.hxx" #include "util/UriUtil.hxx"
#include "util/ConstBuffer.hxx" #include "util/ConstBuffer.hxx"
#include "util/ChronoUtil.hxx" #include "util/ChronoUtil.hxx"
#include "LocateUri.hxx"
bool bool
playlist_commands_available() noexcept playlist_commands_available() noexcept
...@@ -66,12 +67,17 @@ handle_save(Client &client, Request args, gcc_unused Response &r) ...@@ -66,12 +67,17 @@ handle_save(Client &client, Request args, gcc_unused Response &r)
CommandResult CommandResult
handle_load(Client &client, Request args, gcc_unused Response &r) handle_load(Client &client, Request args, gcc_unused Response &r)
{ {
const auto uri = LocateUri(args.front(), &client
#ifdef ENABLE_DATABASE
, nullptr
#endif
);
RangeArg range = args.ParseOptional(1, RangeArg::All()); RangeArg range = args.ParseOptional(1, RangeArg::All());
const ScopeBulkEdit bulk_edit(client.GetPartition()); const ScopeBulkEdit bulk_edit(client.GetPartition());
const SongLoader loader(client); const SongLoader loader(client);
playlist_open_into_queue(args.front(), playlist_open_into_queue(uri,
range.start, range.end, range.start, range.end,
client.GetPlaylist(), client.GetPlaylist(),
client.GetPlayerControl(), loader); client.GetPlayerControl(), loader);
...@@ -81,7 +87,11 @@ handle_load(Client &client, Request args, gcc_unused Response &r) ...@@ -81,7 +87,11 @@ handle_load(Client &client, Request args, gcc_unused Response &r)
CommandResult CommandResult
handle_listplaylist(Client &client, Request args, Response &r) handle_listplaylist(Client &client, Request args, Response &r)
{ {
const char *const name = args.front(); const auto name = LocateUri(args.front(), &client
#ifdef ENABLE_DATABASE
, nullptr
#endif
);
if (playlist_file_print(r, client.GetPartition(), SongLoader(client), if (playlist_file_print(r, client.GetPartition(), SongLoader(client),
name, false)) name, false))
...@@ -93,7 +103,11 @@ handle_listplaylist(Client &client, Request args, Response &r) ...@@ -93,7 +103,11 @@ handle_listplaylist(Client &client, Request args, Response &r)
CommandResult CommandResult
handle_listplaylistinfo(Client &client, Request args, Response &r) handle_listplaylistinfo(Client &client, Request args, Response &r)
{ {
const char *const name = args.front(); const auto name = LocateUri(args.front(), &client
#ifdef ENABLE_DATABASE
, nullptr
#endif
);
if (playlist_file_print(r, client.GetPartition(), SongLoader(client), if (playlist_file_print(r, client.GetPartition(), SongLoader(client),
name, true)) name, true))
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "LocateUri.hxx"
#include "PlaylistAny.hxx" #include "PlaylistAny.hxx"
#include "PlaylistStream.hxx" #include "PlaylistStream.hxx"
#include "PlaylistMapper.hxx" #include "PlaylistMapper.hxx"
...@@ -25,17 +26,26 @@ ...@@ -25,17 +26,26 @@
#include "config.h" #include "config.h"
std::unique_ptr<SongEnumerator> std::unique_ptr<SongEnumerator>
playlist_open_any(const char *uri, playlist_open_any(const LocatedUri &located_uri,
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
const Storage *storage, const Storage *storage,
#endif #endif
Mutex &mutex) Mutex &mutex)
{ {
return uri_has_scheme(uri) switch (located_uri.type) {
? playlist_open_remote(uri, mutex) case LocatedUri::Type::ABSOLUTE:
: playlist_mapper_open(uri, return playlist_open_remote(located_uri.canonical_uri, mutex);
case LocatedUri::Type::PATH:
return playlist_open_path(located_uri.path, mutex);
case LocatedUri::Type::RELATIVE:
return playlist_mapper_open(located_uri.canonical_uri,
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
storage, storage,
#endif #endif
mutex); mutex);
}
gcc_unreachable();
} }
...@@ -34,7 +34,7 @@ class Storage; ...@@ -34,7 +34,7 @@ class Storage;
* music or playlist directory. * music or playlist directory.
*/ */
std::unique_ptr<SongEnumerator> std::unique_ptr<SongEnumerator>
playlist_open_any(const char *uri, playlist_open_any(const LocatedUri &located_uri,
#ifdef ENABLE_DATABASE #ifdef ENABLE_DATABASE
const Storage *storage, const Storage *storage,
#endif #endif
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
*/ */
#include "config.h" #include "config.h"
#include "LocateUri.hxx"
#include "PlaylistQueue.hxx" #include "PlaylistQueue.hxx"
#include "PlaylistAny.hxx" #include "PlaylistAny.hxx"
#include "PlaylistSong.hxx" #include "PlaylistSong.hxx"
...@@ -63,7 +64,7 @@ playlist_load_into_queue(const char *uri, SongEnumerator &e, ...@@ -63,7 +64,7 @@ playlist_load_into_queue(const char *uri, SongEnumerator &e,
} }
void void
playlist_open_into_queue(const char *uri, playlist_open_into_queue(const LocatedUri &uri,
unsigned start_index, unsigned end_index, unsigned start_index, unsigned end_index,
playlist &dest, PlayerControl &pc, playlist &dest, PlayerControl &pc,
const SongLoader &loader) const SongLoader &loader)
...@@ -78,7 +79,7 @@ playlist_open_into_queue(const char *uri, ...@@ -78,7 +79,7 @@ playlist_open_into_queue(const char *uri,
if (playlist == nullptr) if (playlist == nullptr)
throw PlaylistError::NoSuchList(); throw PlaylistError::NoSuchList();
playlist_load_into_queue(uri, *playlist, playlist_load_into_queue(uri.canonical_uri, *playlist,
start_index, end_index, start_index, end_index,
dest, pc, loader); dest, pc, loader);
} }
...@@ -49,7 +49,7 @@ playlist_load_into_queue(const char *uri, SongEnumerator &e, ...@@ -49,7 +49,7 @@ playlist_load_into_queue(const char *uri, SongEnumerator &e,
* play queue. * play queue.
*/ */
void void
playlist_open_into_queue(const char *uri, playlist_open_into_queue(const LocatedUri &uri,
unsigned start_index, unsigned end_index, unsigned start_index, unsigned end_index,
playlist &dest, PlayerControl &pc, playlist &dest, PlayerControl &pc,
const SongLoader &loader); const SongLoader &loader);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
*/ */
#include "config.h" #include "config.h"
#include "LocateUri.hxx"
#include "Print.hxx" #include "Print.hxx"
#include "PlaylistAny.hxx" #include "PlaylistAny.hxx"
#include "PlaylistSong.hxx" #include "PlaylistSong.hxx"
...@@ -55,7 +56,7 @@ playlist_provider_print(Response &r, ...@@ -55,7 +56,7 @@ playlist_provider_print(Response &r,
bool bool
playlist_file_print(Response &r, Partition &partition, playlist_file_print(Response &r, Partition &partition,
const SongLoader &loader, const SongLoader &loader,
const char *uri, bool detail) const LocatedUri &uri, bool detail)
{ {
Mutex mutex; Mutex mutex;
...@@ -71,6 +72,6 @@ playlist_file_print(Response &r, Partition &partition, ...@@ -71,6 +72,6 @@ playlist_file_print(Response &r, Partition &partition,
if (playlist == nullptr) if (playlist == nullptr)
return false; return false;
playlist_provider_print(r, loader, uri, *playlist, detail); playlist_provider_print(r, loader, uri.canonical_uri, *playlist, detail);
return true; return true;
} }
...@@ -34,6 +34,6 @@ struct Partition; ...@@ -34,6 +34,6 @@ struct Partition;
bool bool
playlist_file_print(Response &r, Partition &partition, playlist_file_print(Response &r, Partition &partition,
const SongLoader &loader, const SongLoader &loader,
const char *uri, bool detail); const LocatedUri &uri, bool detail);
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment