2012-08-25 12:59:54 +02:00
|
|
|
/*
|
2015-01-01 19:48:13 +01:00
|
|
|
* Copyright (C) 2003-2015 The Music Player Daemon Project
|
2012-08-25 12:59:54 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "PlaylistCommands.hxx"
|
2015-08-11 22:11:28 +02:00
|
|
|
#include "Request.hxx"
|
2014-01-24 16:18:50 +01:00
|
|
|
#include "db/DatabasePlaylist.hxx"
|
2012-09-25 12:10:12 +02:00
|
|
|
#include "CommandError.hxx"
|
2012-08-29 20:17:13 +02:00
|
|
|
#include "PlaylistPrint.hxx"
|
2012-09-27 22:55:57 +02:00
|
|
|
#include "PlaylistSave.hxx"
|
2012-09-28 00:40:00 +02:00
|
|
|
#include "PlaylistFile.hxx"
|
2014-01-27 11:05:21 +01:00
|
|
|
#include "db/PlaylistVector.hxx"
|
2014-02-02 14:37:52 +01:00
|
|
|
#include "SongLoader.hxx"
|
2014-07-11 20:01:53 +02:00
|
|
|
#include "BulkEdit.hxx"
|
2014-01-23 23:30:12 +01:00
|
|
|
#include "playlist/PlaylistQueue.hxx"
|
|
|
|
#include "playlist/Print.hxx"
|
2014-02-27 17:12:42 +01:00
|
|
|
#include "queue/Playlist.hxx"
|
2013-01-02 20:29:24 +01:00
|
|
|
#include "TimePrint.hxx"
|
2014-01-24 00:26:53 +01:00
|
|
|
#include "client/Client.hxx"
|
2015-08-06 22:10:25 +02:00
|
|
|
#include "client/Response.hxx"
|
2013-01-03 17:34:51 +01:00
|
|
|
#include "ls.hxx"
|
2014-10-25 23:49:35 +02:00
|
|
|
#include "Mapper.hxx"
|
|
|
|
#include "fs/AllocatedPath.hxx"
|
2013-04-08 23:30:21 +02:00
|
|
|
#include "util/UriUtil.hxx"
|
2013-08-10 18:02:44 +02:00
|
|
|
#include "util/Error.hxx"
|
2014-12-06 00:08:08 +01:00
|
|
|
#include "util/ConstBuffer.hxx"
|
2012-08-25 12:59:54 +02:00
|
|
|
|
2014-10-25 23:49:35 +02:00
|
|
|
bool
|
|
|
|
playlist_commands_available()
|
|
|
|
{
|
|
|
|
return !map_spl_path().IsNull();
|
|
|
|
}
|
|
|
|
|
2012-08-25 12:59:54 +02:00
|
|
|
static void
|
2015-08-06 22:10:25 +02:00
|
|
|
print_spl_list(Response &r, const PlaylistVector &list)
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
2012-09-27 23:48:29 +02:00
|
|
|
for (const auto &i : list) {
|
2015-08-06 22:10:25 +02:00
|
|
|
r.Format("playlist: %s\n", i.name.c_str());
|
2012-08-25 12:59:54 +02:00
|
|
|
|
2012-09-27 23:48:29 +02:00
|
|
|
if (i.mtime > 0)
|
2015-08-06 22:10:25 +02:00
|
|
|
time_print(r, "Last-Modified", i.mtime);
|
2012-08-25 12:59:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2015-12-26 06:30:25 +01:00
|
|
|
handle_save(Client &client, Request args, gcc_unused Response &r)
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
2015-12-26 06:30:25 +01:00
|
|
|
spl_save_playlist(args.front(), client.playlist);
|
|
|
|
return CommandResult::OK;
|
2012-08-25 12:59:54 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2015-08-13 12:48:31 +02:00
|
|
|
handle_load(Client &client, Request args, Response &r)
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
2015-12-18 09:50:48 +01:00
|
|
|
RangeArg range = args.ParseOptional(1, RangeArg::All());
|
2012-08-25 12:59:54 +02:00
|
|
|
|
2014-07-11 20:01:53 +02:00
|
|
|
const ScopeBulkEdit bulk_edit(client.partition);
|
|
|
|
|
2014-02-27 17:27:23 +01:00
|
|
|
Error error;
|
2014-02-02 14:37:52 +01:00
|
|
|
const SongLoader loader(client);
|
2014-12-06 00:08:08 +01:00
|
|
|
if (!playlist_open_into_queue(args.front(),
|
2015-08-11 21:35:52 +02:00
|
|
|
range.start, range.end,
|
2014-02-27 17:27:23 +01:00
|
|
|
client.playlist,
|
|
|
|
client.player_control, loader, error))
|
2015-08-06 22:10:25 +02:00
|
|
|
return print_error(r, error);
|
2012-08-25 12:59:54 +02:00
|
|
|
|
2014-05-10 19:02:33 +02:00
|
|
|
return CommandResult::OK;
|
2012-08-25 12:59:54 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2015-08-13 12:48:31 +02:00
|
|
|
handle_listplaylist(Client &client, Request args, Response &r)
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
2014-12-06 00:08:08 +01:00
|
|
|
const char *const name = args.front();
|
|
|
|
|
2015-08-06 22:10:25 +02:00
|
|
|
if (playlist_file_print(r, client.partition, SongLoader(client),
|
|
|
|
name, false))
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::OK;
|
2012-08-25 12:59:54 +02:00
|
|
|
|
2015-12-26 06:30:25 +01:00
|
|
|
spl_print(r, client.partition, name, false);
|
|
|
|
return CommandResult::OK;
|
2012-08-25 12:59:54 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2015-08-13 12:48:31 +02:00
|
|
|
handle_listplaylistinfo(Client &client, Request args, Response &r)
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
2014-12-06 00:08:08 +01:00
|
|
|
const char *const name = args.front();
|
|
|
|
|
2015-08-06 22:10:25 +02:00
|
|
|
if (playlist_file_print(r, client.partition, SongLoader(client),
|
|
|
|
name, true))
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::OK;
|
2012-08-25 12:59:54 +02:00
|
|
|
|
2015-12-26 06:30:25 +01:00
|
|
|
spl_print(r, client.partition, name, true);
|
|
|
|
return CommandResult::OK;
|
2012-08-25 12:59:54 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2015-12-28 07:22:10 +01:00
|
|
|
handle_rm(gcc_unused Client &client, Request args, gcc_unused Response &r)
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
2014-12-06 00:08:08 +01:00
|
|
|
const char *const name = args.front();
|
|
|
|
|
2015-12-28 07:22:10 +01:00
|
|
|
spl_delete(name);
|
|
|
|
return CommandResult::OK;
|
2012-08-25 12:59:54 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2015-12-28 07:22:10 +01:00
|
|
|
handle_rename(gcc_unused Client &client, Request args, gcc_unused Response &r)
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
2014-12-06 00:08:08 +01:00
|
|
|
const char *const old_name = args[0];
|
|
|
|
const char *const new_name = args[1];
|
|
|
|
|
2015-12-28 07:22:10 +01:00
|
|
|
spl_rename(old_name, new_name);
|
|
|
|
return CommandResult::OK;
|
2012-08-25 12:59:54 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2015-12-26 06:30:25 +01:00
|
|
|
handle_playlistdelete(gcc_unused Client &client,
|
|
|
|
Request args, gcc_unused Response &r)
|
2014-12-06 00:08:08 +01:00
|
|
|
{
|
|
|
|
const char *const name = args[0];
|
2015-12-18 09:50:48 +01:00
|
|
|
unsigned from = args.ParseUnsigned(1);
|
2012-08-25 12:59:54 +02:00
|
|
|
|
2015-12-26 06:30:25 +01:00
|
|
|
spl_remove_index(name, from);
|
|
|
|
return CommandResult::OK;
|
2012-08-25 12:59:54 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2015-12-26 06:30:25 +01:00
|
|
|
handle_playlistmove(gcc_unused Client &client,
|
|
|
|
Request args, gcc_unused Response &r)
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
2014-12-06 00:08:08 +01:00
|
|
|
const char *const name = args.front();
|
2015-12-18 09:50:48 +01:00
|
|
|
unsigned from = args.ParseUnsigned(1);
|
|
|
|
unsigned to = args.ParseUnsigned(2);
|
2012-08-25 12:59:54 +02:00
|
|
|
|
2015-12-26 06:30:25 +01:00
|
|
|
spl_move_index(name, from, to);
|
|
|
|
return CommandResult::OK;
|
2012-08-25 12:59:54 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2015-12-28 07:22:10 +01:00
|
|
|
handle_playlistclear(gcc_unused Client &client,
|
|
|
|
Request args, gcc_unused Response &r)
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
2014-12-06 00:08:08 +01:00
|
|
|
const char *const name = args.front();
|
|
|
|
|
2015-12-28 07:22:10 +01:00
|
|
|
spl_clear(name);
|
|
|
|
return CommandResult::OK;
|
2012-08-25 12:59:54 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2015-08-13 12:48:31 +02:00
|
|
|
handle_playlistadd(Client &client, Request args, Response &r)
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
2014-12-06 00:08:08 +01:00
|
|
|
const char *const playlist = args[0];
|
|
|
|
const char *const uri = args[1];
|
2012-08-25 12:59:54 +02:00
|
|
|
|
|
|
|
bool success;
|
2013-08-10 18:02:44 +02:00
|
|
|
Error error;
|
2012-08-25 12:59:54 +02:00
|
|
|
if (uri_has_scheme(uri)) {
|
2014-02-03 23:30:34 +01:00
|
|
|
const SongLoader loader(client);
|
|
|
|
success = spl_append_uri(playlist, loader, uri, error);
|
2014-01-30 20:29:48 +01:00
|
|
|
} else {
|
|
|
|
#ifdef ENABLE_DATABASE
|
2014-02-01 00:26:34 +01:00
|
|
|
const Database *db = client.GetDatabase(error);
|
2014-02-01 01:11:50 +01:00
|
|
|
if (db == nullptr)
|
2015-08-06 22:10:25 +02:00
|
|
|
return print_error(r, error);
|
2014-02-01 01:11:50 +01:00
|
|
|
|
2014-02-07 00:29:07 +01:00
|
|
|
success = search_add_to_playlist(*db, *client.GetStorage(),
|
|
|
|
uri, playlist, nullptr,
|
2013-08-10 18:02:44 +02:00
|
|
|
error);
|
2014-01-30 20:29:48 +01:00
|
|
|
#else
|
|
|
|
success = false;
|
|
|
|
#endif
|
|
|
|
}
|
2012-08-25 12:59:54 +02:00
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
if (!success && !error.IsDefined()) {
|
2015-08-06 22:10:25 +02:00
|
|
|
r.Error(ACK_ERROR_NO_EXIST, "directory or file not found");
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::ERROR;
|
2012-08-25 12:59:54 +02:00
|
|
|
}
|
|
|
|
|
2015-08-06 22:10:25 +02:00
|
|
|
return success ? CommandResult::OK : print_error(r, error);
|
2012-08-25 12:59:54 +02:00
|
|
|
}
|
|
|
|
|
2013-10-20 13:10:54 +02:00
|
|
|
CommandResult
|
2015-08-13 12:48:31 +02:00
|
|
|
handle_listplaylists(gcc_unused Client &client, gcc_unused Request args,
|
|
|
|
Response &r)
|
2012-08-25 12:59:54 +02:00
|
|
|
{
|
2015-12-29 12:41:45 +01:00
|
|
|
print_spl_list(r, ListPlaylistFiles());
|
2013-10-20 13:10:54 +02:00
|
|
|
return CommandResult::OK;
|
2012-08-25 12:59:54 +02:00
|
|
|
}
|