From 09929b6f821a38d6f6a15c555dc1bd1f40273850 Mon Sep 17 00:00:00 2001 From: Qball Cow Date: Sun, 26 Mar 2006 13:46:05 +0000 Subject: 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 --- src/command.c | 14 +++++ src/playlist.c | 179 ++++++++++++++++++++++++++++++++++----------------------- src/playlist.h | 3 + 3 files changed, 123 insertions(+), 73 deletions(-) (limited to 'src') diff --git a/src/command.c b/src/command.c index 156e02197..8596e3791 100644 --- a/src/command.c +++ b/src/command.c @@ -53,6 +53,8 @@ #define COMMAND_CLEAR "clear" #define COMMAND_SAVE "save" #define COMMAND_LOAD "load" +#define COMMAND_LISTPLAYLIST "listPlaylist" +#define COMMAND_LISTPLAYLISTINFO "listPlaylistInfo" #define COMMAND_LSINFO "lsinfo" #define COMMAND_RM "rm" #define COMMAND_PLAYLISTINFO "playlistinfo" @@ -367,6 +369,16 @@ int handleLoad(FILE * fp, unsigned int * permission, int argArrayLength, { return loadPlaylist(fp,argArray[1]); } +int handleListPlaylist(FILE * fp, unsigned int * permission, int argArrayLength, + char ** argArray) +{ + return PlaylistInfo(fp,argArray[1],0); +} +int handleListPlaylistInfo(FILE * fp, unsigned int * permission, int argArrayLength, + char ** argArray) +{ + return PlaylistInfo(fp,argArray[1], 1); +} int handleLsInfo(FILE * fp, unsigned int * permission, int argArrayLength, char ** argArray) @@ -928,6 +940,8 @@ void initCommands() { addCommand(COMMAND_CLEAR ,PERMISSION_CONTROL, 0, 0,handleClear,NULL); addCommand(COMMAND_SAVE ,PERMISSION_CONTROL, 1, 1,handleSave,NULL); addCommand(COMMAND_LOAD ,PERMISSION_ADD, 1, 1,handleLoad,NULL); + addCommand(COMMAND_LISTPLAYLIST,PERMISSION_READ, 1, 1,handleListPlaylist,NULL); + addCommand(COMMAND_LISTPLAYLISTINFO,PERMISSION_READ, 1, 1,handleListPlaylistInfo,NULL); addCommand(COMMAND_LSINFO ,PERMISSION_READ, 0, 1,handleLsInfo,NULL); addCommand(COMMAND_RM ,PERMISSION_CONTROL, 1, 1,handleRm,NULL); addCommand(COMMAND_PLAYLISTINFO,PERMISSION_READ, 0, 1,handlePlaylistInfo,NULL); 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); } diff --git a/src/playlist.h b/src/playlist.h index 91cf2be6f..589cd5650 100644 --- a/src/playlist.h +++ b/src/playlist.h @@ -114,4 +114,7 @@ void playlistVersionChange(); int playlistChanges(FILE * fp, mpd_uint32 version); +int PlaylistInfo(FILE * fp, char * utf8file, int detail); + + #endif -- cgit v1.2.3