Skip to content

Commit e733eaa

Browse files
committed
ADD replace command
Allow to replace an existing playlist, calling mpd_send_save_queue with the MPD_QUEUE_SAVE_MODE_REPLACE flag.
1 parent ec10401 commit e733eaa

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

doc/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ Playlist Commands
252252

253253
:command:`save <file>` - Saves playlist as <file>.
254254

255+
:command:`replace <file>` - Replaces playlist in <file>.
256+
255257
:command:`addplaylist <playlist> <file>` - Adds a song from the music database to the
256258
playlist. The playlist will be created if it does not exist.
257259
Can also read input from pipes.

src/command.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,3 +1376,12 @@ cmd_partitiondelete(int argc, char **argv, struct mpd_connection *conn) {
13761376
}
13771377
return 0;
13781378
}
1379+
1380+
int
1381+
cmd_replace(gcc_unused int argc, char **argv, struct mpd_connection *conn)
1382+
{
1383+
if (!mpd_send_save_queue(conn, charset_to_utf8(argv[0]), MPD_QUEUE_SAVE_MODE_REPLACE)) {
1384+
printErrorAndExit(conn);
1385+
}
1386+
return 0;
1387+
}

src/command.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,7 @@ cmd_subscribe(int argc, char **argv, struct mpd_connection *conn);
6969
int
7070
cmd_tags(int argc, char **argv, struct mpd_connection *conn);
7171

72+
int
73+
cmd_replace(int argc, char **argv, struct mpd_connection *conn);
74+
7275
#endif /* COMMAND_H */

src/main.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ static const struct command {
102102
{"readpicture", 1, 1, 0, cmd_readpicture, "<uri>", "Download a picture from the given song and write to stdout." },
103103
{"renplaylist", 2, 2, 0, cmd_renplaylist, "<file> <newfile>", "Rename a playlist"},
104104
{"repeat", 0, 1, 0, cmd_repeat, "<on|off>", "Toggle repeat mode, or specify state"},
105+
{"replace", 1, 1, 0, cmd_replace, "<file>", "Save a queue as <file>, replacing the existing one"},
105106
{"replaygain", 0, -1, 0, cmd_replaygain, "[off|track|album]", "Set or display the replay gain mode" },
106107
{"rescan", 0, -1, 2, cmd_rescan, "[<path>]", "Rescan music directory (including unchanged files)"},
107108
{"rm", 1, 1, 0, cmd_rm, "<file>", "Remove a playlist"},

0 commit comments

Comments
 (0)