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

Only Read Playlist? #771

Open emufan opened 4 years ago

emufan commented 4 years ago

Hi!

Is there a way to only read a given Sonos library playlist (with return of the JSON like the queue) instead of directly replacing the queue and play?

Background: I'm going to have a simple music select UI for my sun. And instead of hardcoding the files, I want to have a playlist, which I can maintain and then read and display the files.

Thanks and best regards emufan

emufan commented 4 years ago

O.k. via a new created service getplaylist and dummy-player in the basement, I did it currently now this way:

'use strict';

function getplaylist(player, values) {

  const playlistName = decodeURIComponent(values[0]);

  let limit;
  let offset;
  var thwqueue;

  return player.coordinator.clearQueue()
               .then(() => player.coordinator.replaceWithPlaylist(playlistName))
               .then(() => player.coordinator.getQueue(limit, offset))

               .then((queue) => {
                 thwqueue = queue;
               })

               .then(() => player.coordinator.clearQueue())

               .then(() => {
                 return thwqueue;
               });
}

module.exports = function (api) {
  api.registerAction('getplaylist', getplaylist);
};

But I wonder, how this is possible to get this output from without such +1-player-work-around?

jishi commented 4 years ago

Hi, sorry for the late reply. I'm having negative free time at the moment but I do read all issues filed.

There is actually implementation for retrieving playlists, or rather, a generic implementation of the UPnP Browse call. In the context of playlists, sending the string "SQ:" gives you a list of stored playlists.

This call also gives you the possibility to search for tracks via artist, title etc from your local library. Just from top of mind, I think it is something like:

A:TRACKS A:ALBUMARTIST

I mostly figured this out by inspecting the traffic from the desktop-controller to the players. Would make sense to implement helper functions in sonos-discovery that hides these implementation details but it hasn't been a priority because most people move onto streaming services.

You can call the player.browse('SQ:') or player.browseAll('SQ:') to try it out in an action, the first one is paginated, and the second one is not (will get all entries).

emufan commented 4 years ago

Thanks a lot for the direction. Sas the this.getAnyPlayer().browseAll('SQ:'); in your discovery services already. But stopped there and currently stooping there, because, then I have the playlists (with some preview), but not the content of the given playlist. And I only need to know the content as per reading the queue.

Do you have one or two hints in this direction?

Frank-Bemelman commented 2 years ago

If you use SQ: you will get the playlists with perhaps up to four songs. If you use SQ:1 you get the playlist with all songs in it.

emufan commented 2 years ago

Wow. Thanks. Will try this.

emufan commented 2 years ago

@Frank-Bemelman Grr. Too long in the past. I'm not getting anything to work with this, Do you perhaps some hint or short example, how to get the content, if I have the player as above?