diff --git a/lib/ZPAccessory.js b/lib/ZPAccessory.js index 630be2c..b2de9a8 100644 --- a/lib/ZPAccessory.js +++ b/lib/ZPAccessory.js @@ -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; @@ -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; } }