aboutsummaryrefslogtreecommitdiffstats
path: root/src/command
diff options
context:
space:
mode:
Diffstat (limited to 'src/command')
-rw-r--r--src/command/PlaylistCommands.cxx4
-rw-r--r--src/command/QueueCommands.cxx85
2 files changed, 33 insertions, 56 deletions
diff --git a/src/command/PlaylistCommands.cxx b/src/command/PlaylistCommands.cxx
index 272fb0ee4..c3c4fe37c 100644
--- a/src/command/PlaylistCommands.cxx
+++ b/src/command/PlaylistCommands.cxx
@@ -25,6 +25,7 @@
#include "PlaylistSave.hxx"
#include "PlaylistFile.hxx"
#include "db/PlaylistVector.hxx"
+#include "SongLoader.hxx"
#include "playlist/PlaylistQueue.hxx"
#include "playlist/Print.hxx"
#include "TimePrint.hxx"
@@ -65,11 +66,12 @@ handle_load(Client &client, int argc, char *argv[])
} else if (!check_range(client, &start_index, &end_index, argv[2]))
return CommandResult::ERROR;
+ const SongLoader loader(client);
const PlaylistResult result =
playlist_open_into_queue(argv[1],
start_index, end_index,
client.playlist,
- client.player_control, true);
+ client.player_control, loader);
if (result != PlaylistResult::NO_SUCH_LIST)
return print_playlist_result(client, result);
diff --git a/src/command/QueueCommands.cxx b/src/command/QueueCommands.cxx
index 5bef1b461..f14beb872 100644
--- a/src/command/QueueCommands.cxx
+++ b/src/command/QueueCommands.cxx
@@ -21,8 +21,9 @@
#include "QueueCommands.hxx"
#include "CommandError.hxx"
#include "db/DatabaseQueue.hxx"
-#include "SongFilter.hxx"
#include "db/Selection.hxx"
+#include "SongFilter.hxx"
+#include "SongLoader.hxx"
#include "Playlist.hxx"
#include "PlaylistPrint.hxx"
#include "client/Client.hxx"
@@ -38,38 +39,32 @@
#include <string.h>
-CommandResult
-handle_add(Client &client, gcc_unused int argc, char *argv[])
+static const char *
+translate_uri(Client &client, const char *uri)
{
- char *uri = argv[1];
- PlaylistResult result;
-
- if (memcmp(uri, "file:///", 8) == 0) {
- const char *path_utf8 = uri + 7;
- const auto path_fs = AllocatedPath::FromUTF8(path_utf8);
-
- if (path_fs.IsNull()) {
- command_error(client, ACK_ERROR_NO_EXIST,
- "unsupported file name");
- return CommandResult::ERROR;
- }
-
- Error error;
- if (!client.AllowFile(path_fs, error))
- return print_error(client, error);
-
- result = client.partition.AppendFile(path_utf8);
- return print_playlist_result(client, result);
+ if (memcmp(uri, "file:///", 8) == 0)
+ /* drop the "file://", leave only an absolute path
+ (starting with a slash) */
+ return uri + 7;
+
+ if (PathTraitsUTF8::IsAbsolute(uri)) {
+ command_error(client, ACK_ERROR_NO_EXIST, "Malformed URI");
+ return nullptr;
}
- if (uri_has_scheme(uri)) {
- if (!uri_supported_scheme(uri)) {
- command_error(client, ACK_ERROR_NO_EXIST,
- "unsupported URI scheme");
- return CommandResult::ERROR;
- }
+ return uri;
+}
- result = client.partition.AppendURI(uri);
+CommandResult
+handle_add(Client &client, gcc_unused int argc, char *argv[])
+{
+ const char *const uri = translate_uri(client, argv[1]);
+ if (uri == nullptr)
+ return CommandResult::ERROR;
+
+ if (uri_has_scheme(uri) || PathTraitsUTF8::IsAbsolute(uri)) {
+ const SongLoader loader(client);
+ auto result = client.partition.AppendURI(loader, uri);
return print_playlist_result(client, result);
}
@@ -88,34 +83,14 @@ handle_add(Client &client, gcc_unused int argc, char *argv[])
CommandResult
handle_addid(Client &client, int argc, char *argv[])
{
- char *uri = argv[1];
- unsigned added_id;
- PlaylistResult result;
-
- if (memcmp(uri, "file:///", 8) == 0) {
- const char *path_utf8 = uri + 7;
- const auto path_fs = AllocatedPath::FromUTF8(path_utf8);
-
- if (path_fs.IsNull()) {
- command_error(client, ACK_ERROR_NO_EXIST,
- "unsupported file name");
- return CommandResult::ERROR;
- }
+ const char *const uri = translate_uri(client, argv[1]);
+ if (uri == nullptr)
+ return CommandResult::ERROR;
- Error error;
- if (!client.AllowFile(path_fs, error))
- return print_error(client, error);
+ const SongLoader loader(client);
- result = client.partition.AppendFile(path_utf8, &added_id);
- } else {
- if (uri_has_scheme(uri) && !uri_supported_scheme(uri)) {
- command_error(client, ACK_ERROR_NO_EXIST,
- "unsupported URI scheme");
- return CommandResult::ERROR;
- }
-
- result = client.partition.AppendURI(uri, &added_id);
- }
+ unsigned added_id;
+ auto result = client.partition.AppendURI(loader, uri, &added_id);
if (result != PlaylistResult::SUCCESS)
return print_playlist_result(client, result);