Skip to content

Commit

Permalink
Handle unknown track metadata (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebaauw committed Nov 19, 2017
1 parent 4d3fdbd commit 53d7272
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions lib/ZPAccessory.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,19 +261,20 @@ ZPAccessory.prototype.handleAVTransportEvent = function(data) {
if (data) {
this.parser.parseString(data, function(err, json) {
if (!err && json['DIDL-Lite']) {
const type = json['DIDL-Lite'].item[0].res[0]._;
const item = json['DIDL-Lite'].item[0];
const type = item.res[0]._;
switch (type.split(':')[0]) {
case 'x-rincon-stream': // Line in input.
track = json['DIDL-Lite'].item[0]['dc:title'][0]; // source
track = item['dc:title'][0]; // source
break;
case 'x-sonos-htastream': // SPDIF TV input.
track = 'TV';
const streamInfo = json['DIDL-Lite'].item[0]['r:streamInfo'][0];
const streamInfo = item['r:streamInfo'][0];
// "0": no input; "2": stereo; "18": Dolby Digital 5.1;
on = streamInfo !== "0";
break;
case 'x-sonosapi-stream': // Radio stream.
track = json['DIDL-Lite'].item[0]['r:streamContent'][0]; // info
track = item['r:streamContent'][0]; // info
if (track === '') {
if (event['r:EnqueuedTransportURIMetaData']) {
const data = event['r:EnqueuedTransportURIMetaData'][0].$.val;
Expand All @@ -289,12 +290,18 @@ ZPAccessory.prototype.handleAVTransportEvent = function(data) {
break;
case 'x-file-cifs': // Library song.
case 'x-sonos-spotify': // Spotify song.
/* falls through */
default:
track = json['DIDL-Lite'].item[0]['dc:title'][0]; // song
// track = json['DIDL-Lite'].item[0]['dc:creator'][0]; // artist
// track = json['DIDL-Lite'].item[0]['upnp:album'][0]; // album
// track = json['DIDL-Lite'].item[0].res[0].$.duration; // duration
track = item['dc:title'][0]; // song
// track = item['dc:creator'][0]; // artist
// track = item['upnp:album'][0]; // album
// track = item.res[0].$.duration; // duration
break;
default:
if (item['dc:title']) {
track = item['dc:title'][0]; // song
} else {
this.log.warn('%s: unknown track metadata %j', this.name, item);
track = '(unknown)';
}
break;
}
}
Expand Down

0 comments on commit 53d7272

Please sign in to comment.