node-sonos-http-api icon indicating copy to clipboard operation
node-sonos-http-api copied to clipboard

Only Read Playlist?

Open emufan opened this issue 4 years ago • 6 comments

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 avatar Aug 07 '20 07:08 emufan

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?

emufan avatar Aug 12 '20 12:08 emufan

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).

jishi avatar Aug 26 '20 12:08 jishi

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?

emufan avatar Sep 01 '20 07:09 emufan

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.

Frank-Bemelman avatar Jul 02 '22 14:07 Frank-Bemelman

Wow. Thanks. Will try this.

emufan avatar Jul 02 '22 16:07 emufan

@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?

emufan avatar Jul 03 '22 13:07 emufan