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.83k stars 462 forks source link

musicsearch/library not working #861

Closed holyibis closed 1 year ago

holyibis commented 1 year ago

I now succesfully installed node-sonos-http-api to use as api for Sonos-Kids-Controller. Unfortunately I cannot get it to work. I have boiled the issue down to musicsearch/library not working, that the Sonos Kidsplayer completely relies on for local library usage. musicsearch/spotify works fine (only I do not have a Spotify account, but the command is sent to Sonos correctly).

Requesting http://sonos-http-api:5005/Children/musicsearch/library/song/any+search gets the following 500 response:

{"status":"error","error":"Cannot read properties of undefined (reading 'tracks')","stack":"TypeError: Cannot read properties of undefined (reading 'tracks')\n at /app/lib/music_services/libraryDef.js:233:41\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"}

If anyone can provide me any support in solving this I would be more than thankful! I don't really know where to start to fix this, and want to finish this project for my daughters.

jishi commented 1 year ago

I think there is a pre-load action you need to do before your library becomes searchable, have you done that? It doesn't seem to be documented, but you should try and invoke

/playerName/musicsearch/library/load

And you should get a library.json somewhere in the install path.

This was not my code so I'm not sure exactly how it works.

ashenshugarRET commented 1 year ago

Hello,

Have you set up your local music library in the sonos app (https://support.sonos.com/en-ie/article/add-your-music-library-to-sonos)? I've tested the musicsearch functionality with my local library and it works for me, the first search didn't play music as it loaded the library but after that, it worked perfectly.

holyibis commented 1 year ago

I found the issue, the actual error was not thrown via HTTP, but shown in the server logs:

sonos-http-api | 2022-12-15T19:05:49.227Z INFO Presets loaded: {} sonos-http-api | 2022-12-15T19:05:50.507Z INFO http server listening on 0.0.0.0 port 5005 sonos-http-api | 2022-12-15T19:05:54.926Z INFO Loading Library sonos-http-api | 2022-12-15T19:05:54.928Z INFO Tracks returned: 0, Total matches: 1 sonos-http-api | 2022-12-15T19:05:54.958Z INFO Tracks returned: 1, Total matches: 1 sonos-http-api | ERROR: {"errno":-13,"code":"EACCES","syscall":"open","path":"/app/cache/library.json"} sonos-http-api | 2022-12-15T19:05:54.963Z ERROR Error when recursively trying to load library using browse() sonos-http-api | Error: EACCES: permission denied, open '/app/cache/library.json' sonos-http-api | 2022-12-15T19:05:54.965Z ERROR sonos-http-api | TypeError: Cannot read properties of undefined (reading 'tracks') sonos-http-api | at /app/lib/music_services/libraryDef.js:233:41 sonos-http-api | at process.processTicksAndRejections (node:internal/process/task_queues:95:5) sonos-http-api | (node:18) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.

The server (running in a docker container) was not able to create app/cache/library.json. I created the file manually and gave it chmod 777 (just to see if this would solve it) and now it is working in the way @ashenshugarRET mentioned.

Thanks a lot for the very quick info!