mirror of
https://github.com/owntone/owntone-server.git
synced 2025-03-20 12:34:18 -04:00
Add getPlaylistItems rpc function
This commit is contained in:
parent
f2ff609742
commit
c33eade8ba
@ -9,11 +9,12 @@
|
|||||||
|
|
||||||
#include "err.h"
|
#include "err.h"
|
||||||
#include "db-memory.h"
|
#include "db-memory.h"
|
||||||
|
#include "mp3-scanner.h"
|
||||||
#include "webserver.h"
|
#include "webserver.h"
|
||||||
|
|
||||||
/* Forwards */
|
/* Forwards */
|
||||||
void xml_get_playlists(WS_CONNINFO *pwsc);
|
void xml_get_playlists(WS_CONNINFO *pwsc);
|
||||||
void xml_get_playlistinfo(WS_CONNINFO *pwsc);
|
void xml_get_playlistitems(WS_CONNINFO *pwsc);
|
||||||
char *xml_entity_encode(char *original);
|
char *xml_entity_encode(char *original);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,8 +33,9 @@ void xml_handle(WS_CONNINFO *pwsc) {
|
|||||||
if(strcasecmp(method,"getPlaylists") == 0) {
|
if(strcasecmp(method,"getPlaylists") == 0) {
|
||||||
xml_get_playlists(pwsc);
|
xml_get_playlists(pwsc);
|
||||||
return;
|
return;
|
||||||
} else if(strcasecmp(method,"getPlaylistInfo") == 0) {
|
} else if(strcasecmp(method,"getPlaylistItems") == 0) {
|
||||||
xml_get_playlistinfo(pwsc);
|
xml_get_playlistitems(pwsc);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ws_returnerror(pwsc,500,"Invalid method");
|
ws_returnerror(pwsc,500,"Invalid method");
|
||||||
@ -48,23 +50,25 @@ void xml_get_playlists(WS_CONNINFO *pwsc) {
|
|||||||
int playlistid;
|
int playlistid;
|
||||||
char *temp;
|
char *temp;
|
||||||
|
|
||||||
ws_addresponseheader(pwsc,"Content-type","text/xml");
|
ws_addresponseheader(pwsc,"Content-Type","text/xml; charset=utf-8");
|
||||||
ws_writefd(pwsc,"HTTP/1.0 200 OK\r\n");
|
ws_writefd(pwsc,"HTTP/1.0 200 OK\r\n");
|
||||||
ws_emitheaders(pwsc);
|
ws_emitheaders(pwsc);
|
||||||
|
|
||||||
ws_writefd(pwsc,"<?xml version=\"1.0\" standalone=\"yes\" encoding=\"UTF-8\"?>\n");
|
ws_writefd(pwsc,"<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
|
||||||
ws_writefd(pwsc,"<playlists>\n");
|
ws_writefd(pwsc,"<playlists>");
|
||||||
|
|
||||||
/* enumerate all the playlists */
|
/* enumerate all the playlists */
|
||||||
henum=db_playlist_enum_begin();
|
henum=db_playlist_enum_begin();
|
||||||
while(henum) {
|
while(henum) {
|
||||||
playlistid=db_playlist_enum(&henum);
|
playlistid=db_playlist_enum(&henum);
|
||||||
ws_writefd(pwsc," <item>\n");
|
ws_writefd(pwsc,"<item>");
|
||||||
ws_writefd(pwsc," <id>%d</id>\n",playlistid);
|
ws_writefd(pwsc,"<id>%d</id>",playlistid);
|
||||||
temp=xml_entity_encode(db_get_playlist_name(playlistid));
|
temp=xml_entity_encode(db_get_playlist_name(playlistid));
|
||||||
ws_writefd(pwsc," <name>%s</name>\n",temp);
|
ws_writefd(pwsc,"<name>%s</name>",temp);
|
||||||
if(temp) free(temp);
|
if(temp) free(temp);
|
||||||
ws_writefd(pwsc," </item>\n");
|
ws_writefd(pwsc,"<smart>%d</smart>",db_get_playlist_is_smart(playlistid));
|
||||||
|
ws_writefd(pwsc,"<entries>%d</entries>",db_get_playlist_entry_count(playlistid));
|
||||||
|
ws_writefd(pwsc," </item>");
|
||||||
}
|
}
|
||||||
|
|
||||||
ws_writefd(pwsc,"</playlists>\n");
|
ws_writefd(pwsc,"</playlists>\n");
|
||||||
@ -76,9 +80,42 @@ void xml_get_playlists(WS_CONNINFO *pwsc) {
|
|||||||
/**
|
/**
|
||||||
* return xml file of playlist info
|
* return xml file of playlist info
|
||||||
*/
|
*/
|
||||||
void xml_get_playlistinfo(WS_CONNINFO *pwsc) {
|
void xml_get_playlistitems(WS_CONNINFO *pwsc) {
|
||||||
|
char *playlistnum;
|
||||||
|
int playlistid;
|
||||||
|
ENUMHANDLE henum;
|
||||||
|
unsigned long int itemid;
|
||||||
|
char *temp;
|
||||||
|
MP3FILE *current;
|
||||||
|
|
||||||
|
if((playlistnum=ws_getvar(pwsc,"playlistid")) == NULL) {
|
||||||
|
ws_returnerror(pwsc,500,"no playlistid specified");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ws_addresponseheader(pwsc,"Content-Type","text/xml; charset=utf-8");
|
||||||
ws_writefd(pwsc,"HTTP/1.0 200 OK\r\n");
|
ws_writefd(pwsc,"HTTP/1.0 200 OK\r\n");
|
||||||
ws_emitheaders(pwsc);
|
ws_emitheaders(pwsc);
|
||||||
|
|
||||||
|
playlistid=atoi(playlistnum);
|
||||||
|
|
||||||
|
ws_writefd(pwsc,"<playlist>");
|
||||||
|
|
||||||
|
henum=db_playlist_items_enum_begin(playlistid);
|
||||||
|
while((itemid=db_playlist_items_enum(&henum)) != -1) {
|
||||||
|
current=db_find(itemid);
|
||||||
|
if(0 != current) {
|
||||||
|
ws_writefd(pwsc,"<item>%lu</item>",itemid);
|
||||||
|
temp=xml_entity_encode(current->title);
|
||||||
|
ws_writefd(pwsc,"<name>%s</name>",temp);
|
||||||
|
free(temp);
|
||||||
|
db_dispose(current);
|
||||||
|
free(current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ws_writefd(pwsc,"</playlist>");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user