jishi / node-sonos-http-api

An HTTP API bridge for Sonos easing automation. Hostable on any node.js capable device, like a raspberry pi or similar.
http://jishi.github.io/node-sonos-http-api/
MIT License
1.84k stars 462 forks source link

Music search and play #772

Closed emufan closed 3 years ago

emufan commented 4 years ago

Currently I'm struggeling to find out how to play a defined song from my library. Perhaps a matter of fuzza or of syntax or ... but most of the times it finds more different songs and put them in the queue.

What is the right syntax if Artist is "Benjamin Blümchen" and title is "Auf dem Baum", if I compare to the example in the description /Playroom/musicsearch/library/album/red+hot+chili+peppers+the+getaway

/Kitchen/musicsearch/library/song/Benjamin Blümchen+Auf dem Baum /Kitchen/musicsearch/library/song/Benjamin+Blümchen+Auf+dem+Baum /Kitchen/musicsearch/library/song/Benjamin%20Bl%C3%BCmchen+Auf%20dem%20Baum /Kitchen/musicsearch/library/song/Benjamin+Bl%C3%BCmchen+Auf+dem+Baum

In general, every version is working without an error, but does not return the unique song, but a queue with songs: Auf der Baustelle Auf dem Baum Auf dem Rummel ... or with a song, completeley not related to the search team in single cases. Or from another album or the wrong file from the same album if in different versions on an album or ...

Artist and title are taken as is from qeue or playlist. How to make this work? Or is there a bug in musicsearch? Or a better way to play a given song from the library (without to have a single playlist for each single song).

Or is there a track ID, which I don't get back at the moment with state and queue and with wich I can play a specific file?

emufan commented 4 years ago

Hm, no feedback?

In the meantime, this info what I figured out for all, who have the same question in the feature and struggling with the ambiguously documentation.

For library muscisearch:

After changing all this (threshold lower, only search in artist+title field, Etc. the result was much better, but not good enough (see info about wrong results on equal searches. And as I have the ID already, for me it does not make sense to take from a defined song only artist, title, etc., then search again in a fuzzy list and hope, that it will return the right one.

So I modified musicsearch with a new service playuri, Which plays directly the given ID/URI.

// .then(() => player.coordinator.addURIToQueue(tracks.queueTracks[0].uri, tracks.queueTracks[0].metadata, true, nextTrackNo)) .then(() => player.coordinator.addURIToQueue(thwplayuri, '', true, nextTrackNo))

So this is working now. But I wonder, if there was/is already such a function?

And I wonder, where are the results in not passing the metadata? It is working without them, but what is missing with ignoring/not having them iat this point of time (in standard musicsearch, this is taken from the library,json.

Thyraz commented 4 years ago

I'm also searching for something like that, because node-sonos-http-api is amazing using Spotify, but I also have some albums in the local library that I need to be able to play.

Searching with an exact artist and an exact album/track name (and not a fuzzy mix of the combination of both) would be great.

Any chance that something like this could be implemented? the search query could be something like mentioned above: /musicsearch/library/artist:the+artist+name+album:the+album+name

Playing a specific item with a known ID would also be nice.

jishi commented 4 years ago

Not passing metadata for a single track (from library) would probably result in no artist or title being present when playing it (or in the queue). But for playlists and such, it doesn't seem to have any effect.

The problem with searching for a specific track is that you might always get multiple hits. Searching like this usually need user interaction (showing list, then selecting a certain track) which is outside of scope for most people (because the use it mostly for automation).

Thyraz commented 4 years ago

Sure, searching always might get ducplicates. But this is also true for the other musicsearch entry points in your software like with sportify.

Wouldn't it definitely improve the ability to get the correct search result when it would be possible to set one string that is only searched in the artist field and another string that is only searched in the album field?

Currently for local library searches you might end up with an album that has the name of the artist instead of the requested album title.

emufan commented 4 years ago

Not passing metadata for a single track (from library) would probably result in no artist or title being present when playing it (or in the queue).

This was my expecation. Or something like this. But everything is there without metadata: artist, album, links to artist and album, etc. etc. That was the question, where the missing pieces are, if it is (on the first view) working without.

Searching with an exact artist and an exact album/track name (and not a fuzzy mix of the combination of both) would be great. Any chance that something like this could be implemented?

For me, yes. Two ways:

  1. Update fuse.js or figure out, what is happening there, because with right threshhold setting it should find perfect maches only. But it currently not the case. Have a look at library.json and my explanation above.

  2. Instead of searching via fuse.js in library.json, it should be possible to loop/filter/whatever directly through library.json (with perhaps other "columns" and do a kind like SELECT SINGLE *, because as 1- ist currently not working.

the search query could be something like mentioned above: /musicsearch/library/artist:the+artist+name+album:the+album+name

Not possible with fuse-approach but would be possible with approach 2. But not needed, if 1. will give only perfect matches as wnated/expected with distance and threshholds.

Playing a specific item with a known ID would also be nice.

Implemented this locally. See above.

Thyraz commented 4 years ago

Ok, I updated to the current fuse.js version and modified libraryDef.js to be compatible with it. Seems to be working fine so far, when searching with full artist and album name.

Will do more tests on how reliable it is.

If this works without problems, I will also adjust the other modules that use fuse.js for the newer version and create a pull request.

Thyraz commented 3 years ago

I have a fork with the changes here: https://github.com/Thyraz/node-sonos-http-api

Works perfectly since months here and I always get the expected search results when offering the full search terms. So updating fuse.js really seems to do the trick. :)

Are you still using it @emufan, so you could test it too before I submit a Pull Request to @jishi?

mochi-co commented 3 years ago

If this works well still please open a PR @Thyraz 👍🏻

Thyraz commented 3 years ago

PR is merged, so this issue can be closed...