svrooij / node-sonos-ts

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

MetadataHelper should force string and do some basic string replacement (html decode) #88

Closed hklages closed 3 years ago

hklages commented 3 years ago

When I play Artist Adele, Album 19 from Music library the following code (end also the full AVTransport service code):

coordinator.Events.on(SonosEvents.CurrentTrackMetadata, (data) => {
      console.log('Current track metadata %s', JSON.stringify(data, null, 2))
})

produces an "Album" property of type number - see console.log:

Current track metadata
{
  "Album":19,
  "Artist":"Adele",
  "AlbumArtUri":"http://192.168.178.37:1400/getaa?u=x-file-cifs:%2f%2fnas2019%2fMultimedia%2fMusic%2fMyMusic%2fAdele%2f19%2fAdele%20-%20Right%20as%20Rain.mp3&v=35",
  "Title":"Right as Rain",
  "UpnpClass":"object.item.audioItem.musicTrack",
  "Duration":"0:03:17",
  "ItemId":"-1",
  "ParentId":"-1",
  "TrackUri":"x-file-cifs://nas2019/Multimedia/Music/MyMusic/Adele/19/Adele - Right as Rain.mp3",
  "ProtocolInfo":"x-file-cifs:*:audio/mpeg:*"
}

In addition it would be good if you could decode Album, Title, etc. Currently I do it with:

decodeHtml: (htmlData) => {
    debug('method >>%s', 'decodeHtml')
    const decoded = String(htmlData).replace(/<|>|&|'|"/g, (substring) => {
      switch (substring) {
      case '&lt;': return '<'
      case '&gt;': return '>'
      case '&amp;': return '&'
      case '&apos;': return '`'
      case '&quot;': return '"'
      }
    })

    return decoded
  },

You see the work around - using String to convert the number to string. Without that it throws error "replace is not a function" as 19 is number.

Wish you a Merry Christmas, Happy New Year. Keep healthy!

svrooij commented 3 years ago

This bug is related to the MetaDataHelper for anyone who want to give it a go. Probably an easy fix.

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 2.2.0-beta.7 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

svrooij commented 3 years ago

@hklages I did something wrong with the git branch, so the above version is actually 2.3.0-beta.1 I changed the metadata helper it should now always return a string and do some html decoding.

can you check if this version solves the Adele 19 issue and the &pos; in titles?

hklages commented 3 years ago

I could only install 2.2.0-beta.7.

Album with numbers return now string so Adele album 19 is ok.

Decoding remains a problem: Album and also title

{"Album":"Bob Dylan&apos;s Greatest Hits","Artist":"Bob Dylan","AlbumArtUri":"http://192.168.178.37:1400/getaa?s=1&u=x-sonosapi-hls-static:catalog%2ftracks%2fB00GQW0DA8%2f%3fsid%3d201%26flags%3d0%26sn%3d19","Title":"Blowin&amp;apos; in the Wind","UpnpClass":"object.item.audioItem.musicTrack","Duration":"0:02:47","ItemId":"-1","ParentId":"-1","TrackUri":"x-sonosapi-hls-static:catalog/tracks/B00GQW0DA8/?sid=201&flags=0&sn=19","ProtocolInfo":"sonos.com-http::application/x-mpegURL:"}

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 2.3.0-beta.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 2.3.0-beta.3 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 2.3.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: