Add DAAP logic for the Radio item

This commit is contained in:
ejurgensen 2015-03-16 23:33:42 +01:00
parent 46e4214b39
commit e5a1495b49
3 changed files with 61 additions and 17 deletions

View File

@ -296,7 +296,7 @@ static __thread sqlite3 *hdl;
/* Forward */
static int
db_pl_count_items(int id);
db_pl_count_items(int id, int streams_only);
static int
db_smartpl_count_items(const char *smartpl_query);
@ -1696,6 +1696,7 @@ db_query_fetch_pl(struct query_params *qp, struct db_playlist_info *dbpli)
int id;
int type;
int nitems;
int nstreams;
int i;
int ret;
@ -1747,11 +1748,13 @@ db_query_fetch_pl(struct query_params *qp, struct db_playlist_info *dbpli)
{
case PL_PLAIN:
id = sqlite3_column_int(qp->stmt, 0);
nitems = db_pl_count_items(id);
nitems = db_pl_count_items(id, 0);
nstreams = db_pl_count_items(id, 1);
break;
case PL_SMART:
nitems = db_smartpl_count_items(dbpli->query);
nstreams = 0;
break;
default:
@ -1759,13 +1762,21 @@ db_query_fetch_pl(struct query_params *qp, struct db_playlist_info *dbpli)
return -1;
}
dbpli->items = qp->buf;
ret = snprintf(qp->buf, sizeof(qp->buf), "%d", nitems);
if ((ret < 0) || (ret >= sizeof(qp->buf)))
dbpli->items = qp->buf1;
ret = snprintf(qp->buf1, sizeof(qp->buf1), "%d", nitems);
if ((ret < 0) || (ret >= sizeof(qp->buf1)))
{
DPRINTF(E_LOG, L_DB, "Could not convert items, buffer too small\n");
DPRINTF(E_LOG, L_DB, "Could not convert item count, buffer too small\n");
strcpy(qp->buf, "0");
strcpy(qp->buf1, "0");
}
dbpli->streams = qp->buf2;
ret = snprintf(qp->buf2, sizeof(qp->buf2), "%d", nstreams);
if ((ret < 0) || (ret >= sizeof(qp->buf2)))
{
DPRINTF(E_LOG, L_DB, "Could not convert stream count, buffer too small\n");
strcpy(qp->buf2, "0");
}
return 0;
@ -2775,14 +2786,19 @@ db_pl_get_count(void)
}
static int
db_pl_count_items(int id)
db_pl_count_items(int id, int streams_only)
{
#define Q_TMPL "SELECT COUNT(*) FROM playlistitems pi JOIN files f" \
" ON pi.filepath = f.path WHERE f.disabled = 0 AND pi.playlistid = %d;"
#define Q_TMPL_STREAMS "SELECT COUNT(*) FROM playlistitems pi JOIN files f" \
" ON pi.filepath = f.path WHERE f.disabled = 0 AND f.data_kind = 1 AND pi.playlistid = %d;"
char *query;
int ret;
query = sqlite3_mprintf(Q_TMPL, id);
if (!streams_only)
query = sqlite3_mprintf(Q_TMPL, id);
else
query = sqlite3_mprintf(Q_TMPL_STREAMS, id);
if (!query)
{
@ -2796,6 +2812,7 @@ db_pl_count_items(int id)
return ret;
#undef Q_TMPL_STREAMS
#undef Q_TMPL
}
@ -3013,7 +3030,8 @@ db_pl_fetch_byquery(char *query)
switch (pli->type)
{
case PL_PLAIN:
pli->items = db_pl_count_items(pli->id);
pli->items = db_pl_count_items(pli->id, 0);
pli->streams = db_pl_count_items(pli->id, 1);
break;
case PL_SMART:

View File

@ -74,7 +74,8 @@ struct query_params {
/* Private query context, keep out */
sqlite3_stmt *stmt;
char buf[32];
char buf1[32];
char buf2[32];
};
struct pairing_info {
@ -175,6 +176,7 @@ struct playlist_info {
char *title; /* playlist name as displayed in iTunes (minm) */
enum pl_type type; /* see PL_ types */
uint32_t items; /* number of items (mimc) */
uint32_t streams; /* number of internet streams */
char *query; /* where clause if type 1 (MSPS) */
uint32_t db_timestamp; /* time last updated */
uint32_t disabled;
@ -192,6 +194,7 @@ struct db_playlist_info {
char *title;
char *type;
char *items;
char *streams;
char *query;
char *db_timestamp;
char *disabled;

View File

@ -69,6 +69,7 @@ extern struct event_base *evbase_httpd;
/* Update requests refresh interval in seconds */
#define DAAP_UPDATE_REFRESH 0
#define DAAP_DB_RADIO 2
struct uri_map {
regex_t preg;
@ -1172,7 +1173,7 @@ daap_reply_dblist(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
evbuffer_add_buffer(content, item);
evbuffer_free(item);
// Add second db entry for radio with dbid = 2
// Add second db entry for radio with dbid = DAAP_DB_RADIO
item = evbuffer_new();
if (!item)
{
@ -1182,12 +1183,12 @@ daap_reply_dblist(struct evhttp_request *req, struct evbuffer *evbuf, char **uri
return -1;
}
dmap_add_int(item, "miid", 2);
dmap_add_long(item, "mper", 2);
dmap_add_int(item, "miid", DAAP_DB_RADIO);
dmap_add_long(item, "mper", DAAP_DB_RADIO);
dmap_add_int(item, "mdbk", 0x64);
dmap_add_int(item, "aeCs", 0);
dmap_add_string(item, "minm", "Radio");
count = 3; // TODO Get count of radio streams
count = db_pl_get_count(); // TODO This counts too much, should only include stream playlists
dmap_add_int(item, "mimc", count);
dmap_add_int(item, "mctc", 0);
dmap_add_int(item, "aeMk", 1); // com.apple.itunes.extended-media-kind (OR of all in library)
@ -1549,11 +1550,13 @@ daap_reply_playlists(struct evhttp_request *req, struct evbuffer *evbuf, char **
const struct dmap_field **meta;
const char *param;
char **strval;
int database;
int nmeta;
int npls;
int32_t plid;
int32_t pltype;
int32_t plitems;
int32_t plstreams;
int32_t plparent;
int i;
int ret;
@ -1562,6 +1565,14 @@ daap_reply_playlists(struct evhttp_request *req, struct evbuffer *evbuf, char **
if (!s)
return -1;
ret = safe_atoi32(uri[1], &database);
if (ret < 0)
{
dmap_send_error(req, "aply", "Invalid database ID");
return -1;
}
ret = evbuffer_expand(evbuf, 61);
if (ret < 0)
{
@ -1654,8 +1665,20 @@ daap_reply_playlists(struct evhttp_request *req, struct evbuffer *evbuf, char **
if (safe_atoi32(dbpli.items, &plitems) != 0)
continue;
/* Don't add empty smart playlists */
if ((plid > 1) && (pltype == 1) && (plitems == 0))
plstreams = 0;
if (safe_atoi32(dbpli.streams, &plstreams) != 0)
continue;
/* Database DAAP_DB_RADIO is radio, so for that db skip playlists without
* streams and for other databases skip playlists which are just streams
*/
if ((database == DAAP_DB_RADIO) && (plstreams == 0))
continue;
if ((database != DAAP_DB_RADIO) && (plstreams == plitems))
continue;
/* Don't add empty playlists */
if ((plid > 1) && (plitems == 0))
continue;
npls++;