svrooij / node-sonos-ts

:speaker: Sonos control library, use this library in your own appliction.
https://sonos-ts.svrooij.io/
MIT License
84 stars 18 forks source link

Improve parsing r:StreamContent #32

Closed cheanrod closed 4 years ago

cheanrod commented 4 years ago

This fix improves the handling of field r:StreamContent when streaming e.g. radio stations. In case of my favorite station there isn't always a parseable artist/title combination available. Instead, only the name of the radio station is included (see below).

{ '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/', item: { _id: '-1', _parentID: '-1', _restricted: 'true', res: [Object], 'r:streamContent': 'Bremen Vier', 'r:radioShowMd': 'HeuckZeug,p270647', 'upnp:albumArtURI': '/getaa?s=1&u=x-sonosapi-stream%3as25565%3fsid%3d254%26flags%3d8224%26sn%3d0', 'dc:title': 'x-sonosapi-stream:s25565?sid=254&flags=8224&sn=0', 'upnp:class': 'object.item' } } }

This is currently parsed as follows:

{
  "AlbumArtUri": "http://192.168.178.41:1400/getaa?s=1&u=x-sonosapi-stream:s25565%3fsid%3d254%26flags%3d8224%26sn%3d0",
  "Title": "x-sonosapi-stream:s25565?sid=254&flags=8224&sn=0",
  "UpnpClass": "object.item",
  "ItemId": "-1",
  "ParentId": "-1",
  "TrackUri": "x-sonosapi-stream:s25565?sid=254&flags=8224&sn=0",
  "ProtocolInfo": "sonos.com-http:*:*:*"
}

This is not nice for displaying it in my smarthome software.

The fix adds the stream content to the artist even if the content cannot be split. Additionally, 'r:radioShowMd' is parsed and added to the title. The result is this:

{
  "Artist": "Bremen Vier",
  "AlbumArtUri": "http://192.168.178.41:1400/getaa?s=1&u=x-sonosapi-stream:s25565%3fsid%3d254%26flags%3d8224%26sn%3d0",
  "Title": "HeuckZeug",
  "UpnpClass": "object.item",
  "ItemId": "-1",
  "ParentId": "-1",
  "TrackUri": "x-sonosapi-stream:s25565?sid=254&flags=8224&sn=0",
  "ProtocolInfo": "sonos.com-http:*:*:*"
}
svrooij commented 4 years ago

Thanks Sven for your second contribution!

svrooij commented 4 years ago

:tada: This PR is included in version 1.1.4 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

cheanrod commented 4 years ago

Thanks for fast merge!