hklages / node-red-contrib-sonos-plus

A set of Node-RED nodes to control SONOS player in your local network.
MIT License
76 stars 14 forks source link

Howto? / Feature Request searchMusicLibrary for specific album #100

Closed ukmoose closed 3 years ago

ukmoose commented 3 years ago

Description

I'm trying to create an RFID tag based system for playing my ripped CD's via my SONOS system.

So what I am trying to do is query the Music Library so that based on ArtistName, AlbumName and number of tracks I can then replace the queue with the album's tracks and start it playing.

I can't get my head around how to do this with the new nodes ( or the old nodes, but I'm sticking with just the non depreciated ones). Is this possible?

What node/command (topic)/state (payload)?

node: My Sonos command: ??? state: ????

In case of a bug: Are you able to reproduce the error?

Not a bug

Versions and Infrastructure

what system: Raspberry Pi node-red-contrib-sonos-plus version: 4.1.4 - new nodes only :-) Node-RED version: 1.1.3 NodeJS version: v10.21.0

Many thanks!

ukmoose

hklages commented 3 years ago

Hi. Right now you are able to query all playlists (node mysonos, library.query.playlist).

You can play any song with node Universal, group.play.uri and topic - example: x-file-cifs://nas2019/Multimedia/Music/MyMusic/Rihanna/Diamonds/Rihanna%20-%20Diamonds.mp3

Does that help - or do you need a library.query.album or library.queue.album?

ukmoose commented 3 years ago

I don't appear to have (node mysonos, library.query.playlist).

If I send a mysonos node library.query.playlist I see the following error:

"library.query.playlist: command is invalid >>library.query.playlist :: Details: none" The library options I can see in mysonos are: 'library.export.playlist': libraryExportPlaylist, 'library.get.playlists': libraryGetPlaylists, 'library.queue.playlist': libraryQueuePlaylist,

But I'm guessing that would be quite messy, as library.get.playlists appears to only return the playlist list not the full music library as an option.

The workflow I was imagining was to use the metadata encoded on the RFID tag to form the query for: library.query.album to query the albums in the Music Library followed by library.queue.album to queue the specific album.

Or to use library.query.album to write the album UID to the RFID tag and then on reading the tag use library.queue.album to queue.

Thanks for your support and knowledge.

hklages commented 3 years ago

Hi. Do I understand it right? a) get information about an album from the RFID tag: b) browse your music library and "select" that album c) insert into queue and play all titles.

What info do you get in a)? Are the file names simple - without white space etc?

In my Music library there is a Beatle album named "1967 - 1970 (Blue Alb)" and that is stored in directory \\nas2019\MultiMedia\Music\MyMusic\Beatles\1967-1970 (Blue Alb) (Rm)

When using the SONOS app I am able to

Now I can use the following flow to play this album (I guess the same way as you would like to do):

[{"id":"abc6b0e0.81358","type":"inject","z":"55805384.a4695c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1967","payloadType":"str","x":130,"y":504,"wires":[["8ec4029b.5ccec"]]},{"id":"8ec4029b.5ccec","type":"sonos-manage-mysonos","z":"55805384.a4695c","confignode":"88e9fa70.4a53e8","compatibilityMode":false,"command":"mysonos.export.item","name":"","x":340,"y":504,"wires":[["31d2512a.16a7de","1328ec43.44a934"]]},{"id":"31d2512a.16a7de","type":"sonos-universal","z":"55805384.a4695c","confignode":"88e9fa70.4a53e8","compatibilityMode":false,"command":"group.play.export","state":"","stateType":"str","name":"","x":570,"y":504,"wires":[[]]},{"id":"1328ec43.44a934","type":"debug","z":"55805384.a4695c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":530,"y":460,"wires":[]},{"id":"88e9fa70.4a53e8","type":"sonos-config","z":"","name":"coordinator","serialnum":"5C-AA-FD-00-22-36:1","ipaddress":"192.168.178.37"}]

The debug node shows you an example of the input required for group.play.export

You can also do it direct without the metadata.

[{"id":"db68e1fc.f9196","type":"sonos-universal","z":"55805384.a4695c","confignode":"88e9fa70.4a53e8","compatibilityMode":false,"command":"group.play.export","state":"","stateType":"str","name":"","x":330,"y":600,"wires":[[]]},{"id":"3470c96b.94f0b6","type":"inject","z":"55805384.a4695c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"uri\":\"x-rincon-playlist:RINCON_949F3EC13B9901400#A:ALBUM/1967-1970%20(Blue%20Alb)%20(Rm)\",\"queue\":true}","payloadType":"json","x":130,"y":600,"wires":[["db68e1fc.f9196"]]},{"id":"88e9fa70.4a53e8","type":"sonos-config","z":"","name":"coordinator","serialnum":"5C-AA-FD-00-22-36:1","ipaddress":"192.168.178.37"}]

musiclibrary

So what is my message: Are you able to transform your "meta data from the RFID tag" to my uri-data for the input of the group.play.export?

Flow: get your rfid data --> convert your metadata to right input for export --> group.play.export --> Done :-)

hklages commented 3 years ago

There is a way to search for Album in the Sonos api - even for tracks and composer. Maybe thats what you need. I can make that available in the next release.

Do you can have any special characters (/%&#@") in your album title?

ukmoose commented 3 years ago

To answer your question from 5 days ago (life got in the way this week!), I am programming the RFID's, so what information the RFID tag contains is up to me. My current thoughts are artist/album name (inc spaces) and potentially RINCON id.

But the trouble is I have 700 CD's (already all ripped and added to iTunes and then the Music Library) so I don't really want to have to add each of them to "My Sonos" tab and without doing that your suggested flow doesn't find the album.

So yes please, a way of searching for the album name in the Music Library would allow me to create a flow that I can use to recreate the x-rincon-playlist uri to play the CD in question.

(I already have some RFID cards that I can use to group/ungroup SONOS speakers and to play our favourite Radio stations)

And yes unfortunately some of the CD album names do contain special characters ;-(

hklages commented 3 years ago

... should be available Thursday, Friday - will let you know when published.

hklages commented 3 years ago

Hi. 4.3.0 is now available. In My Sonos, library.export.album with a searchstring in payload shoud find an album in your library. The first match is returned. Special characters such as -, . / & () should work. Does it work for you?

ukmoose commented 3 years ago

Thanks I had time to test it today. It works, however, as the Album name is not unique (eg I have 2 albums with the name "Help"). You can't get the details of the second album with the same name.

Any chance of returning all hits as an array of objects?

Then by passing the artist name in the incoming message I can filter the output using JSONata in a change node after the node.

hklages commented 3 years ago

Hi. I prefer to keep the "single output" for export, as that is usually the input for the play command. As alternative you can use get.albums and specify a search string. Does it workf for your?

All documentation is now Wiki

export albums

ukmoose commented 3 years ago

Many Thanks! Using msg.searchTitle with library.export.albums allows me to find the information I need.