Skip to content

Commit 148bc51

Browse files
committed
Allow limit when fetching queue
Fixes #493
1 parent f6d7252 commit 148bc51

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

README.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -140,22 +140,26 @@ Example of a state json:
140140
Queue
141141
-----
142142
Obtain the current queue list from a specified player. The request will accept:
143-
- No parameters
143+
- limit (optional)
144+
- offset (optional, requires limit)
145+
- detailed flag (optional, include uri in response)
144146

145-
`http://localhost:5005/living room/queue`
147+
http://localhost:5005/living room/queue
148+
http://localhost:5005/living room/queue/10 (only return top 10)
149+
http://localhost:5005/living room/queue/10/10 (return result 11-20)
150+
http://localhost:5005/living room/queue/detailed
151+
http://localhost:5005/living room/queue/10/detailed
146152

147153
Example queue response:
148154
```
149155
[
150156
{
151-
"uri": "x-sonos-spotify:spotify%3atrack%3a0AvV49z4EPz5ocYN7eKGAK?sid=9&flags=8224&sn=3",
152157
"albumArtURI": "/getaa?s=1&u=x-sonos-spotify%3aspotify%253atrack%253a0AvV49z4EPz5ocYN7eKGAK%3fsid%3d9%26flags%3d8224%26sn%3d3",
153158
"title": "No Diggity",
154159
"artist": "Blackstreet",
155160
"album": "Another Level"
156161
},
157162
{
158-
"uri": "x-sonos-spotify:spotify%3atrack%3a5OQGeJ1ceykovrykZsGhqL?sid=9&flags=8224&sn=3",
159163
"albumArtURI": "/getaa?s=1&u=x-sonos-spotify%3aspotify%253atrack%253a5OQGeJ1ceykovrykZsGhqL%3fsid%3d9%26flags%3d8224%26sn%3d3",
160164
"title": "Breathless",
161165
"artist": "The Corrs",

lib/actions/queue.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,19 @@ function simplify(items) {
1313
}
1414

1515
function queue(player, values) {
16-
const detailed = values[0] === 'detailed';
16+
const detailed = values[values.length - 1] === 'detailed';
17+
let limit;
18+
let offset;
1719

18-
const promise = player.coordinator.getQueue();
20+
if (/\d+/.test(values[0])) {
21+
limit = parseInt(values[0]);
22+
}
23+
24+
if (/\d+/.test(values[1])) {
25+
offset = parseInt(values[1]);
26+
}
27+
28+
const promise = player.coordinator.getQueue(limit, offset);
1929

2030
if (detailed) {
2131
return promise;

0 commit comments

Comments
 (0)