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:
parent
19021e9cc6
commit
09929b6f82
@ -53,6 +53,8 @@
|
|||||||
#define COMMAND_CLEAR "clear"
|
#define COMMAND_CLEAR "clear"
|
||||||
#define COMMAND_SAVE "save"
|
#define COMMAND_SAVE "save"
|
||||||
#define COMMAND_LOAD "load"
|
#define COMMAND_LOAD "load"
|
||||||
|
#define COMMAND_LISTPLAYLIST "listPlaylist"
|
||||||
|
#define COMMAND_LISTPLAYLISTINFO "listPlaylistInfo"
|
||||||
#define COMMAND_LSINFO "lsinfo"
|
#define COMMAND_LSINFO "lsinfo"
|
||||||
#define COMMAND_RM "rm"
|
#define COMMAND_RM "rm"
|
||||||
#define COMMAND_PLAYLISTINFO "playlistinfo"
|
#define COMMAND_PLAYLISTINFO "playlistinfo"
|
||||||
@ -367,6 +369,16 @@ int handleLoad(FILE * fp, unsigned int * permission, int argArrayLength,
|
|||||||
{
|
{
|
||||||
return loadPlaylist(fp,argArray[1]);
|
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,
|
int handleLsInfo(FILE * fp, unsigned int * permission, int argArrayLength,
|
||||||
char ** argArray)
|
char ** argArray)
|
||||||
@ -928,6 +940,8 @@ void initCommands() {
|
|||||||
addCommand(COMMAND_CLEAR ,PERMISSION_CONTROL, 0, 0,handleClear,NULL);
|
addCommand(COMMAND_CLEAR ,PERMISSION_CONTROL, 0, 0,handleClear,NULL);
|
||||||
addCommand(COMMAND_SAVE ,PERMISSION_CONTROL, 1, 1,handleSave,NULL);
|
addCommand(COMMAND_SAVE ,PERMISSION_CONTROL, 1, 1,handleSave,NULL);
|
||||||
addCommand(COMMAND_LOAD ,PERMISSION_ADD, 1, 1,handleLoad,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_LSINFO ,PERMISSION_READ, 0, 1,handleLsInfo,NULL);
|
||||||
addCommand(COMMAND_RM ,PERMISSION_CONTROL, 1, 1,handleRm,NULL);
|
addCommand(COMMAND_RM ,PERMISSION_CONTROL, 1, 1,handleRm,NULL);
|
||||||
addCommand(COMMAND_PLAYLISTINFO,PERMISSION_READ, 0, 1,handlePlaylistInfo,NULL);
|
addCommand(COMMAND_PLAYLISTINFO,PERMISSION_READ, 0, 1,handlePlaylistInfo,NULL);
|
||||||
|
161
src/playlist.c
161
src/playlist.c
@ -1337,7 +1337,64 @@ int savePlaylist(FILE * fp, char * utf8file) {
|
|||||||
return 0;
|
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;
|
FILE * fileP;
|
||||||
char s[MAXPATHLEN+1];
|
char s[MAXPATHLEN+1];
|
||||||
int slength = 0;
|
int slength = 0;
|
||||||
@ -1404,28 +1461,14 @@ int loadPlaylist(FILE * fp, char * utf8file) {
|
|||||||
slength = 0;
|
slength = 0;
|
||||||
temp = fsCharsetToUtf8(s);
|
temp = fsCharsetToUtf8(s);
|
||||||
if(!temp) continue;
|
if(!temp) continue;
|
||||||
temp = strdup(temp);
|
/* Needed to make a copy? */
|
||||||
if(commentCharFound && !getSongFromDB(temp)
|
if(!commentCharFound)
|
||||||
&& !isRemoteUrl(temp))
|
|
||||||
{
|
{
|
||||||
}
|
temp = strdup(temp);
|
||||||
else if((addToPlaylist(stderr, temp, 0))<0) {
|
IterFunc(fp, temp, &erroredFile);
|
||||||
/* 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);
|
free(temp);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if(slength==MAXPATHLEN) {
|
else if(slength==MAXPATHLEN) {
|
||||||
s[slength] = '\0';
|
s[slength] = '\0';
|
||||||
commandError(fp, ACK_ERROR_PLAYLIST_LOAD,
|
commandError(fp, ACK_ERROR_PLAYLIST_LOAD,
|
||||||
@ -1451,59 +1494,49 @@ int loadPlaylist(FILE * fp, char * utf8file) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getPlaylistCurrentSong() {
|
|
||||||
if(playlist.current >= 0 && playlist.current < playlist.length) {
|
static void PlaylistInfoPrintInfo(FILE *fp, char *utf8file, char **erroredfile) {
|
||||||
return playlist.order[playlist.current];
|
Song * song = getSongFromDB(utf8file);
|
||||||
|
if(song) {
|
||||||
|
printSongInfo(fp, song);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
return -1;
|
myfprintf(fp,"file:%s\n",utf8file);
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
static void PlaylistInfoPrint(FILE *fp, char *utf8file, char **erroredfile) {
|
||||||
|
myfprintf(fp,"file:%s\n",utf8file);
|
||||||
|
}
|
||||||
|
|
||||||
if(playlist.random) for(i=0;song!=playlist.order[i];i++);
|
static void PlaylistLoadIterFunc(FILE *fp, char *temp, char **erroredFile) {
|
||||||
|
if(!getSongFromDB(temp) && !isRemoteUrl(temp))
|
||||||
|
{
|
||||||
|
|
||||||
clearPlayerError();
|
}
|
||||||
playlist_stopOnError = 1;
|
else if((addToPlaylist(stderr, temp, 0))<0) {
|
||||||
playlist_errorCount = 0;
|
/* for windows compatibilit, convert slashes */
|
||||||
|
char * temp2 = strdup(temp);
|
||||||
if(playlist_state == PLAYLIST_STATE_PLAY) {
|
char * p = temp2;
|
||||||
if(playlist.queued>=0) {
|
while(*p) {
|
||||||
lockPlaylistInteraction();
|
if(*p=='\\') *p = '/';
|
||||||
clearPlayerQueue();
|
p++;
|
||||||
unlockPlaylistInteraction();
|
}
|
||||||
|
if((addToPlaylist(stderr, temp2, 0))<0) {
|
||||||
|
if(!*erroredFile) {
|
||||||
|
*erroredFile = strdup(temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(playPlaylistOrderNumber(fp,i)<0) return -1;
|
free(temp2);
|
||||||
|
|
||||||
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) {
|
int PlaylistInfo(FILE * fp, char * utf8file, int detail) {
|
||||||
checkSongId(id);
|
if(detail) {
|
||||||
|
return PlaylistIterFunc(fp, utf8file, PlaylistInfoPrintInfo);
|
||||||
return seekSongInPlaylist(fp, playlist.idToPosition[id], time);
|
}
|
||||||
|
return PlaylistIterFunc(fp, utf8file, PlaylistInfoPrint) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getPlaylistSongId(int song) {
|
int loadPlaylist(FILE * fp, char * utf8file) {
|
||||||
return playlist.positionToId[song];
|
return PlaylistIterFunc(fp, utf8file, PlaylistLoadIterFunc);
|
||||||
}
|
}
|
||||||
|
@ -114,4 +114,7 @@ void playlistVersionChange();
|
|||||||
|
|
||||||
int playlistChanges(FILE * fp, mpd_uint32 version);
|
int playlistChanges(FILE * fp, mpd_uint32 version);
|
||||||
|
|
||||||
|
int PlaylistInfo(FILE * fp, char * utf8file, int detail);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user