aboutsummaryrefslogtreecommitdiffstats
path: root/src/playlist.c
diff options
context:
space:
mode:
authorQball Cow <qball@qballcow.nl>2006-03-26 13:46:05 +0000
committerQball Cow <qball@qballcow.nl>2006-03-26 13:46:05 +0000
commit09929b6f821a38d6f6a15c555dc1bd1f40273850 (patch)
tree8a9187ee38f43b3e5ff11b367d8ebe62294ef56e /src/playlist.c
parent19021e9cc60a98c900c986c242d1816ebdddee23 (diff)
downloadmpd-09929b6f821a38d6f6a15c555dc1bd1f40273850.tar.gz
mpd-09929b6f821a38d6f6a15c555dc1bd1f40273850.tar.xz
mpd-09929b6f821a38d6f6a15c555dc1bd1f40273850.zip
Support for fetching the content of a stored playlist (patch by qball), this adds listPlaylist and listPlaylistInfo
git-svn-id: https://svn.musicpd.org/mpd/trunk@3947 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/playlist.c179
1 files changed, 106 insertions, 73 deletions
diff --git a/src/playlist.c b/src/playlist.c
index 580116260..de71f77a7 100644
--- a/src/playlist.c
+++ b/src/playlist.c
@@ -1337,7 +1337,64 @@ int savePlaylist(FILE * fp, char * utf8file) {
return 0;
}
-int loadPlaylist(FILE * fp, char * utf8file) {
+int getPlaylistCurrentSong() {
+ if(playlist.current >= 0 && playlist.current < playlist.length) {
+ return playlist.order[playlist.current];
+ }
+
+ return -1;
+}
+
+unsigned long getPlaylistVersion() {
+ return playlist.version;
+}
+
+int getPlaylistLength() {
+ return playlist.length;
+}
+
+int seekSongInPlaylist(FILE * fp, int song, float time) {
+ int i = song;
+
+ if(song<0 || song>=playlist.length) {
+ commandError(fp, ACK_ERROR_NO_EXIST,
+ "song doesn't exist: \"%i\"", song);
+ return -1;
+ }
+
+ if(playlist.random) for(i=0;song!=playlist.order[i];i++);
+
+ clearPlayerError();
+ playlist_stopOnError = 1;
+ playlist_errorCount = 0;
+
+ if(playlist_state == PLAYLIST_STATE_PLAY) {
+ if(playlist.queued>=0) {
+ lockPlaylistInteraction();
+ clearPlayerQueue();
+ unlockPlaylistInteraction();
+ }
+ }
+ else if(playPlaylistOrderNumber(fp,i)<0) return -1;
+
+ if(playlist.current!=i) {
+ if(playPlaylistOrderNumber(fp,i)<0) return -1;
+ }
+
+ return playerSeek(fp, playlist.songs[playlist.order[i]], time);
+}
+
+int seekSongInPlaylistById(FILE * fp, int id, float time) {
+ checkSongId(id);
+
+ return seekSongInPlaylist(fp, playlist.idToPosition[id], time);
+}
+
+int getPlaylistSongId(int song) {
+ return playlist.positionToId[song];
+}
+
+static int PlaylistIterFunc(FILE * fp, char * utf8file, void (*IterFunc)(FILE *fp, char *utf8_file, char **errored_File)) {
FILE * fileP;
char s[MAXPATHLEN+1];
int slength = 0;
@@ -1361,14 +1418,14 @@ int loadPlaylist(FILE * fp, char * utf8file) {
else {
free(rfile);
commandError(fp, ACK_ERROR_NO_EXIST,
- "playlist \"%s\" not found", utf8file);
+ "playlist \"%s\" not found", utf8file);
return -1;
}
while(!(fileP = fopen(actualFile,"r")) && errno==EINTR);
if(fileP==NULL) {
commandError(fp, ACK_ERROR_SYSTEM,
- "problems opening file \"%s\"", utf8file);
+ "problems opening file \"%s\"", utf8file);
return -1;
}
@@ -1391,9 +1448,9 @@ int loadPlaylist(FILE * fp, char * utf8file) {
strncat(s,temp,MAXPATHLEN-parentlen-1);
if(strlen(s)>=MAXPATHLEN) {
commandError(fp,
- ACK_ERROR_PLAYLIST_LOAD,
- "\"%s\" too long",
- temp);
+ ACK_ERROR_PLAYLIST_LOAD,
+ "\"%s\" too long",
+ temp);
free(temp);
while(fclose(fileP) && errno==EINTR);
if(erroredFile) free(erroredFile);
@@ -1404,34 +1461,20 @@ int loadPlaylist(FILE * fp, char * utf8file) {
slength = 0;
temp = fsCharsetToUtf8(s);
if(!temp) continue;
- temp = strdup(temp);
- if(commentCharFound && !getSongFromDB(temp)
- && !isRemoteUrl(temp))
+ /* Needed to make a copy? */
+ if(!commentCharFound)
{
+ temp = strdup(temp);
+ IterFunc(fp, temp, &erroredFile);
+ free(temp);
}
- else if((addToPlaylist(stderr, temp, 0))<0) {
- /* for windows compatibilit, convert slashes */
- char * temp2 = strdup(temp);
- char * p = temp2;
- while(*p) {
- if(*p=='\\') *p = '/';
- p++;
- }
- if((addToPlaylist(stderr, temp2, 0))<0) {
- if(!erroredFile) {
- erroredFile = strdup(temp);
- }
- }
- free(temp2);
- }
- free(temp);
}
else if(slength==MAXPATHLEN) {
s[slength] = '\0';
commandError(fp, ACK_ERROR_PLAYLIST_LOAD,
- "line in \"%s\" is too long", utf8file);
+ "line in \"%s\" is too long", utf8file);
ERROR("line \"%s\" in playlist \"%s\" is too long\n",
- s, utf8file);
+ s, utf8file);
while(fclose(fileP) && errno==EINTR);
if(erroredFile) free(erroredFile);
return -1;
@@ -1443,7 +1486,7 @@ int loadPlaylist(FILE * fp, char * utf8file) {
if(erroredFile) {
commandError(fp, ACK_ERROR_PLAYLIST_LOAD,
- "can't add file \"%s\"", erroredFile);
+ "can't add file \"%s\"", erroredFile);
free(erroredFile);
return -1;
}
@@ -1451,59 +1494,49 @@ int loadPlaylist(FILE * fp, char * utf8file) {
return 0;
}
-int getPlaylistCurrentSong() {
- if(playlist.current >= 0 && playlist.current < playlist.length) {
- return playlist.order[playlist.current];
- }
-
- return -1;
-}
-unsigned long getPlaylistVersion() {
- return playlist.version;
+static void PlaylistInfoPrintInfo(FILE *fp, char *utf8file, char **erroredfile) {
+ Song * song = getSongFromDB(utf8file);
+ if(song) {
+ printSongInfo(fp, song);
+ }
+ else {
+ myfprintf(fp,"file:%s\n",utf8file);
+ }
}
-
-int getPlaylistLength() {
- return playlist.length;
+static void PlaylistInfoPrint(FILE *fp, char *utf8file, char **erroredfile) {
+ myfprintf(fp,"file:%s\n",utf8file);
}
-int seekSongInPlaylist(FILE * fp, int song, float time) {
- int i = song;
-
- if(song<0 || song>=playlist.length) {
- commandError(fp, ACK_ERROR_NO_EXIST,
- "song doesn't exist: \"%i\"", song);
- return -1;
- }
-
- if(playlist.random) for(i=0;song!=playlist.order[i];i++);
-
- clearPlayerError();
- playlist_stopOnError = 1;
- playlist_errorCount = 0;
-
- if(playlist_state == PLAYLIST_STATE_PLAY) {
- if(playlist.queued>=0) {
- lockPlaylistInteraction();
- clearPlayerQueue();
- unlockPlaylistInteraction();
+static void PlaylistLoadIterFunc(FILE *fp, char *temp, char **erroredFile) {
+ if(!getSongFromDB(temp) && !isRemoteUrl(temp))
+ {
+
+ }
+ else if((addToPlaylist(stderr, temp, 0))<0) {
+ /* for windows compatibilit, convert slashes */
+ char * temp2 = strdup(temp);
+ char * p = temp2;
+ while(*p) {
+ if(*p=='\\') *p = '/';
+ p++;
}
+ if((addToPlaylist(stderr, temp2, 0))<0) {
+ if(!*erroredFile) {
+ *erroredFile = strdup(temp);
+ }
+ }
+ free(temp2);
}
- else if(playPlaylistOrderNumber(fp,i)<0) return -1;
-
- if(playlist.current!=i) {
- if(playPlaylistOrderNumber(fp,i)<0) return -1;
- }
-
- return playerSeek(fp, playlist.songs[playlist.order[i]], time);
}
-int seekSongInPlaylistById(FILE * fp, int id, float time) {
- checkSongId(id);
-
- return seekSongInPlaylist(fp, playlist.idToPosition[id], time);
+int PlaylistInfo(FILE * fp, char * utf8file, int detail) {
+ if(detail) {
+ return PlaylistIterFunc(fp, utf8file, PlaylistInfoPrintInfo);
+ }
+ return PlaylistIterFunc(fp, utf8file, PlaylistInfoPrint) ;
}
-int getPlaylistSongId(int song) {
- return playlist.positionToId[song];
+int loadPlaylist(FILE * fp, char * utf8file) {
+ return PlaylistIterFunc(fp, utf8file, PlaylistLoadIterFunc);
}