Commit 08003904 authored by J. Alexander Treuman's avatar J. Alexander Treuman

Adding functions for clearing/adding to stored playlists. Commands to make

use of these functions are still being worked on. git-svn-id: https://svn.musicpd.org/mpd/trunk@5075 09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent 6d6155d7
...@@ -304,11 +304,22 @@ static int directoryAddSongToPlaylist(int fd, Song * song, void *data) ...@@ -304,11 +304,22 @@ static int directoryAddSongToPlaylist(int fd, Song * song, void *data)
return addSongToPlaylist(fd, song, 0); return addSongToPlaylist(fd, song, 0);
} }
static int directoryAddSongToStoredPlaylist(int fd, Song *song, void *data)
{
return addSongToStoredPlaylist(fd, song, (char *)data);
}
int addAllIn(int fd, char *name) int addAllIn(int fd, char *name)
{ {
return traverseAllIn(fd, name, directoryAddSongToPlaylist, NULL, NULL); return traverseAllIn(fd, name, directoryAddSongToPlaylist, NULL, NULL);
} }
int addAllInToStoredPlaylist(int fd, char *name, char *utf8file)
{
return traverseAllIn(fd, name, directoryAddSongToStoredPlaylist, NULL,
(void *)utf8file);
}
static int directoryPrintSongInfo(int fd, Song * song, void *data) static int directoryPrintSongInfo(int fd, Song * song, void *data)
{ {
return printSongInfo(fd, song); return printSongInfo(fd, song);
......
...@@ -47,6 +47,8 @@ int printAllIn(int fd, char *name); ...@@ -47,6 +47,8 @@ int printAllIn(int fd, char *name);
int addAllIn(int fd, char *name); int addAllIn(int fd, char *name);
int addAllInToStoredPlaylist(int fd, char *name, char *utf8file);
int printInfoForAllIn(int fd, char *name); int printInfoForAllIn(int fd, char *name);
int searchForSongsIn(int fd, char *name, int numItems, int searchForSongsIn(int fd, char *name, int numItems,
......
...@@ -236,6 +236,44 @@ int clearPlaylist(int fd) ...@@ -236,6 +236,44 @@ int clearPlaylist(int fd)
return 0; return 0;
} }
int clearStoredPlaylist(int fd, char *utf8file)
{
int fileD;
char *file;
char *rfile;
char *actualFile;
if (strstr(utf8file, "/")) {
commandError(fd, ACK_ERROR_ARG,
"cannot clear \"%s\", saving playlists to "
"subdirectories is not supported", utf8file);
return -1;
}
file = utf8ToFsCharset(utf8file);
rfile = xmalloc(strlen(file) + strlen(".") +
strlen(PLAYLIST_FILE_SUFFIX) + 1);
strcpy(rfile, file);
strcat(rfile, ".");
strcat(rfile, PLAYLIST_FILE_SUFFIX);
actualFile = rpp2app(rfile);
free(rfile);
while ((fileD = open(actualFile, O_WRONLY | O_TRUNC | O_CREAT)) == -1
&& errno == EINTR);
if (fileD == -1) {
commandError(fd, ACK_ERROR_SYSTEM, "problems opening file");
return -1;
}
while (close(fileD) == -1 && errno == EINTR);
return 0;
}
int showPlaylist(int fd) int showPlaylist(int fd)
{ {
int i; int i;
...@@ -590,6 +628,24 @@ int addToPlaylist(int fd, char *url, int printId) ...@@ -590,6 +628,24 @@ int addToPlaylist(int fd, char *url, int printId)
return addSongToPlaylist(fd, song, printId); return addSongToPlaylist(fd, song, printId);
} }
int addToStoredPlaylist(int fd, char *url, char *utf8file)
{
Song *song;
DEBUG("add to stored playlist: %s\n", url);
if ((song = getSongFromDB(url))) {
} else if (!(isValidRemoteUtf8Url(url) &&
(song = newSong(url, SONG_TYPE_URL, NULL)))) {
commandError(fd, ACK_ERROR_NO_EXIST,
"\"%s\" is not in the music db or is "
"not a valid url", url);
return -1;
}
return addSongToStoredPlaylist(fd, song, utf8file);
}
int addSongToPlaylist(int fd, Song * song, int printId) int addSongToPlaylist(int fd, Song * song, int printId)
{ {
int id; int id;
...@@ -642,6 +698,52 @@ int addSongToPlaylist(int fd, Song * song, int printId) ...@@ -642,6 +698,52 @@ int addSongToPlaylist(int fd, Song * song, int printId)
return 0; return 0;
} }
int addSongToStoredPlaylist(int fd, Song *song, char *utf8file)
{
FILE *fileP;
char *file;
char *rfile;
char *actualFile;
char *url;
if (strstr(utf8file, "/")) {
commandError(fd, ACK_ERROR_ARG,
"cannot add to \"%s\", saving playlists to "
"subdirectories is not supported", utf8file);
return -1;
}
file = utf8ToFsCharset(utf8file);
rfile = xmalloc(strlen(file) + strlen(".") +
strlen(PLAYLIST_FILE_SUFFIX) + 1);
strcpy(rfile, file);
strcat(rfile, ".");
strcat(rfile, PLAYLIST_FILE_SUFFIX);
actualFile = rpp2app(rfile);
free(rfile);
while (!(fileP = fopen(actualFile, "a")) && errno == EINTR);
if (fileP == NULL) {
commandError(fd, ACK_ERROR_SYSTEM, "problems opening file");
return -1;
}
url = utf8ToFsCharset(getSongUrl(song));
if (playlist_saveAbsolutePaths && song->type == SONG_TYPE_FILE)
fprintf(fileP, "%s\n", rmp2amp(url));
else
fprintf(fileP, "%s\n", url);
while (fclose(fileP) && errno == EINTR);
return 0;
}
int swapSongsInPlaylist(int fd, int song1, int song2) int swapSongsInPlaylist(int fd, int song1, int song2)
{ {
int queuedSong = -1; int queuedSong = -1;
......
...@@ -40,10 +40,16 @@ void savePlaylistState(FILE *); ...@@ -40,10 +40,16 @@ void savePlaylistState(FILE *);
int clearPlaylist(int fd); int clearPlaylist(int fd);
int clearStoredPlaylist(int fd, char *utf8file);
int addToPlaylist(int fd, char *file, int printId); int addToPlaylist(int fd, char *file, int printId);
int addToStoredPlaylist(int fd, char *file, char *utf8file);
int addSongToPlaylist(int fd, Song * song, int printId); int addSongToPlaylist(int fd, Song * song, int printId);
int addSongToStoredPlaylist(int fd, Song *song, char *utf8file);
int showPlaylist(int fd); int showPlaylist(int fd);
int deleteFromPlaylist(int fd, int song); int deleteFromPlaylist(int fd, int song);
......
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