aboutsummaryrefslogtreecommitdiffstats
path: root/src/playlist.c
diff options
context:
space:
mode:
authorJ. Alexander Treuman <jat@spatialrift.net>2006-11-20 15:37:58 +0000
committerJ. Alexander Treuman <jat@spatialrift.net>2006-11-20 15:37:58 +0000
commit08003904d7af58c0402b49805b9f87b3d9ebbc27 (patch)
tree4011968f22cf2a24d2841f55b90b52df782f32d1 /src/playlist.c
parent6d6155d766747ccd27ade7f0be66bff645b7a11f (diff)
downloadmpd-08003904d7af58c0402b49805b9f87b3d9ebbc27.tar.gz
mpd-08003904d7af58c0402b49805b9f87b3d9ebbc27.tar.xz
mpd-08003904d7af58c0402b49805b9f87b3d9ebbc27.zip
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
Diffstat (limited to 'src/playlist.c')
-rw-r--r--src/playlist.c102
1 files changed, 102 insertions, 0 deletions
diff --git a/src/playlist.c b/src/playlist.c
index c977d0e4f..0c0d3cf25 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -236,6 +236,44 @@ int clearPlaylist(int fd)
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 i;
@@ -590,6 +628,24 @@ int addToPlaylist(int fd, char *url, int 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 id;
@@ -642,6 +698,52 @@ int addSongToPlaylist(int fd, Song * song, int printId)
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 queuedSong = -1;