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
This commit is contained in:
Qball Cow 2006-03-26 13:46:05 +00:00
parent 19021e9cc6
commit 09929b6f82
3 changed files with 164 additions and 114 deletions

View File

@ -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);

View File

@ -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;
@ -1404,28 +1461,14 @@ 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)
{
}
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);
}
temp = strdup(temp);
IterFunc(fp, temp, &erroredFile);
free(temp);
}
}
else if(slength==MAXPATHLEN) {
s[slength] = '\0';
commandError(fp, ACK_ERROR_PLAYLIST_LOAD,
@ -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];
static void PlaylistInfoPrintInfo(FILE *fp, char *utf8file, char **erroredfile) {
Song * song = getSongFromDB(utf8file);
if(song) {
printSongInfo(fp, song);
}
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 {
myfprintf(fp,"file:%s\n",utf8file);
}
}
else if(playPlaylistOrderNumber(fp,i)<0) return -1;
if(playlist.current!=i) {
if(playPlaylistOrderNumber(fp,i)<0) return -1;
static void PlaylistInfoPrint(FILE *fp, char *utf8file, char **erroredfile) {
myfprintf(fp,"file:%s\n",utf8file);
}
return playerSeek(fp, playlist.songs[playlist.order[i]], time);
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);
}
}
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);
}

View File

@ -114,4 +114,7 @@ void playlistVersionChange();
int playlistChanges(FILE * fp, mpd_uint32 version);
int PlaylistInfo(FILE * fp, char * utf8file, int detail);
#endif