int limit = 10;
int count = 0;
int res;
- dbstate states[ZPL_SIZEOF] = { 0 };
- int playing = -1;
obstack_1grow(io, '{');
write_value_json(io, "queue");
obstack_sgrow(io, ",\"items\": [");
- for (int i=ZPL_SIZEOF-1;i>=0 && count < limit;i--) {
- if (!list_names[i])
- continue;
-
- states[i].curr.listid = dblistid_get_name(tx, db, list_names[i]);
- res = dbstate_get(tx, db, states[i].curr.listid, &states[i]);
-
- // Grab the playing item as the first entry
- if (res == 0 && (states[i].state & 1) == 1 && count == 0) {
- dbscan scan;
- dblistcursor cursor = states[i].curr;
- dbfile *file = dbscan_list_entry(tx, &scan, db, &cursor);
-
- if (file && dbfile_full_path(tx, db, file)) {
- obstack_sgrow(io, count > 0 ? ",{" : "{");
- write_file_json(io, file);
-
- obstack_printf(io, ",\"listid\":\"%u\"", cursor.listid);
- obstack_printf(io, ",\"seq\":\"%u\"", cursor.seq);
-
- obstack_1grow(io, '}');
-
- playing = i;
- count += 1;
- }
- dbfile_free(file);
- dbscan_free(&scan);
- }
- }
-
for (int i=ZPL_SIZEOF-1;i>=0 && count < limit;i--) {
dbfile *file;
dbscan scan;
- dblistcursor cursor = states[i].curr;
- int scancount = 0;
+ dbstate state;
+ int listcount = 0;
+ if (!list_names[i])
+ continue;
+
+ state.curr.listid = dblistid_get_name(tx, db, list_names[i]);
+ res = dbstate_get(tx, db, state.curr.listid, &state);
loop:
- file = dbscan_list_entry(tx, &scan, db, &cursor);
+ file = dbscan_list_entry(tx, &scan, db, &state.curr);
while (count < limit && file) {
- if (dbfile_full_path(tx, db, file)
- && !(count == 1 && playing == i && scancount == 0)) {
+ if (listcount > 0 || (state.state & ZPL_STATEF_PLAYING) == 0) {
obstack_sgrow(io, count > 0 ? ",{" : "{");
write_file_json(io, file);
- obstack_printf(io, ",\"listid\":\"%u\"", cursor.listid);
- obstack_printf(io, ",\"seq\":\"%u\"", cursor.seq);
+ obstack_printf(io, ",\"listid\":\"%u\"", state.curr.listid);
+ obstack_printf(io, ",\"seq\":\"%u\"", state.curr.seq);
obstack_1grow(io, '}');
count++;
}
dbfile_free(file);
- file = dbscan_list_entry_next(&scan, &cursor);
- scancount++;
+ file = dbscan_list_entry_next(&scan, &state.curr);
+ listcount++;
}
dbfile_free(file);
res = dbscan_result(&scan);
dbscan_free(&scan);
// loop on default playlist always
- if (res == MDB_NOTFOUND) {
- if (i == 0 && cursor.seq > 0) {
- cursor.seq = 0;
- cursor.fileid = 0;
- goto loop;
- }
+ if (res == MDB_NOTFOUND && i == 0 && state.curr.seq > 0) {
+ state.curr.seq = 0;
+ state.curr.fileid = 0;
+ goto loop;
}
}
obstack_sgrow(io, "]}");
write_queue_json(db, os);
set_data_json(rep);
} else if (strcmp(req->method, "POST") == 0) {
- // TODO: enqueue
+ // TODO: enqueue? This is handles by POST /x/list/[jukebox]?f=file
int fid = param_int(req, "f", 0);
if (fid) {
// /x/list/{listid}
static int handle_list(struct ez_httprequest *req, struct ez_httpresponse *rep) {
struct obstack *os = &rep->http.conn->os;
- int lid = atoi(req->url + strlen("/x/list/"));
+ int lid = atoi(req->url + strlen("/x/list/")); // TODO: support symbolic names
int fid = param_int(req, "f", 0);
int seq = param_int(req, "s", 0); // TODO: should be in /x/list/{listid}/{seq} ?
res = dbstate_get(tx, db, state.curr.listid, &state);
if (res != 0)
continue;
- printf("%4d: ver=%08x state=%08x stamp=%016lx pos=%9.3fs lid=%4d seq=%4d fid=%5d\n",
- i, state.version, state.state, state.stamp, state.poss,
+ printf("%4d: state=%08x stamp=%016lx pos=%9.3fs lid=%4d seq=%4d fid=%5d\n",
+ i, state.state, state.stamp, state.poss,
state.curr.listid, state.curr.seq, state.curr.fileid);
}
dbindex_commit(tx);
dbtxn *tx = dbindex_begin(db, NULL, 1);
int res;
int count = 0;
- int limit = 100;
+ int limit = argc == 3 ? atoi(argv[2]) : 10;
for (int i=ZPL_SIZEOF-1;i>=0 && count < limit;i--) {
dbstate state;
dbscan scan;
dbfile *file;
+ int listcount = 0;
if (!list_names[i])
continue;
loop:
file = dbscan_list_entry(tx, &scan, db, &state.curr);
while (count < limit && file) {
- if (dbfile_full_path(tx, db, file)) {
+ if (listcount > 0 || (state.state & ZPL_STATEF_PLAYING) == 0) {
printf("%4d: fid=%4d lid=%4d seq=%4d title: %-60s %s\n", count++, file->id, state.curr.listid, state.curr.seq, file->title, file->path);
}
+
dbfile_free(file);
file = dbscan_list_entry_next(&scan, &state.curr);
+ listcount++;
}
dbfile_free(file);
res = dbscan_result(&scan);
dbscan_free(&scan);
// loop on default playlist always
- if (res == MDB_NOTFOUND) {
- if (i == 0 && state.curr.seq > 0) {
- state.curr.seq = 0;
- state.curr.fileid = 0;
- goto loop;
- }
+ if (res == MDB_NOTFOUND && i == 0 && state.curr.seq > 0) {
+ state.curr.seq = 0;
+ state.curr.fileid = 0;
+ goto loop;
}
-
}
#if 0