Skip to content

Commit ce064fa

Browse files
committed
Add action for the BBC Sounds service
1 parent 9d77d36 commit ce064fa

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

lib/actions/bbcSounds.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
function getMetadata(station) {
4+
return `<DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/">
5+
<item id="83207${station}" parentID="L" restricted="true"><dc:title>BBC Sounds</dc:title><upnp:class>object.item.audioItem.audioBroadcast</upnp:class>
6+
<desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON83207_</desc></item></DIDL-Lite>`;
7+
}
8+
9+
function getUri(station) {
10+
return `x-sonosapi-hls:stations%7eplayable%7e%7e${station}%7e%7eurn%3abbc%3aradio%3anetwork%3a${station}?sid=325&flags=288&sn=10`;
11+
}
12+
13+
/**
14+
* @link https://gist.github.com/bpsib/67089b959e4fa898af69fea59ad74bc3 Stream names can be found here
15+
*/
16+
function bbcSounds(player, values) {
17+
const action = values[0];
18+
const station = encodeURIComponent(values[1]);
19+
20+
if (!station) {
21+
return Promise.reject('Expected BBC Sounds station name.');
22+
}
23+
24+
const metadata = getMetadata(station);
25+
const uri = getUri(station);
26+
27+
if (action === 'play') {
28+
return player.coordinator.setAVTransport(uri, metadata).then(() => player.coordinator.play());
29+
} else if (action === 'set') {
30+
return player.coordinator.setAVTransport(uri, metadata);
31+
}
32+
33+
return Promise.reject('BBC Sounds only handles the {play} & {set} actions.');
34+
}
35+
36+
module.exports = function (api) {
37+
api.registerAction('bbcsounds', bbcSounds);
38+
}

0 commit comments

Comments
 (0)