Adeptive / SoundTouch-NodeJS

Bose SoundTouch Node JS API
Apache License 2.0
34 stars 22 forks source link

episodeSelector functionality added #10

Open theovassiliou opened 6 years ago

theovassiliou commented 6 years ago

added a new functionality called episode selector.

Motivation

It is not so uncommon that you would like to randomly select a content from your soundtouch location. In our household, the kids have a demand to have on a specific preset a regularly changing audio book available, but without having to take a computer, phone or tablet into their hands. Other application areas could be to rotate through a list of internet radio stations.

Requirement 1

In order to store a content on a given preset we must be able to reference the content. Soundtouch uses a combination of source, sourceAccount and location information to reference this information. We are using a music libary on a NAS. From this content there is a relatively small amount of content that we want to select from. In our case some 200 episodes. Therefore you should be able to create this pool of content with the information required by the SoundTouch system. For this I created the episodeCollector.js script.

Usage

 node episodeCollector.js

Will start a service that listens to update from a specific device as named in collectorSettings.json. Select the named device in your SoundTouch-app and select a new content. This content will be added todata-store/libraryContent.json. The file will be created if not existent. Select all content in the SoundTouch-App one by one that you would like to add to the libaryContent. If selecting the same content multple times, only one reference will be created in libraryContent.

Requirement 2

We need a functionality where we can trigger an action that

Because of the limitations of the SoundTouch-API it is not possible to store a content directly for a preset. Therefore we introduced the following REST-call

/:deviceName/auto/episodeSelector/:presetKey?

In order to program a preset we

Just to make it a little bit safe, we reduce the volume on the device and restore the original volume afterwards.

The function returns a JSON object of the following format:

{
    "album": "035 Und Der Hoehlenmensch",
    "entry": "0$1$18$3340$19925$20556",
    "source": "STORED_MUSIC",
    "sourceAccount": "55076f6e-6b79-1d65-a4eb-00089bea8bd7/0",
    "presetKey": 6
}

or 416 - Range not satisfied error code with

{
    "message": "presetKey should be between 1 and 6"
}

Requirement 3

After a while we did not know exactly what content is stored in the libraryContent. Therefore we introduced a REST-call

 /auto/getAllEpisodes

which returns a list of all episodes as a json object of the format:

{
    "0$1$18$3340$19925$21162": {
        "source": "STORED_MUSIC",
        "sourceAccount": "55076f6e-6b79-1d65-a4eb-00089bea8bd7/0",
        "name": "001 - Und der Super Papagei"
    },

Final remarks

As a result we have been able to create a small framework to have some content available for selection as preset. By exposing this functionality via a REST-API we are able to regularly change the content of presets for example via a cron-job or similar.

As I believe this could be usefull for other too, I propose this pull request. It should be automatically mergeable

Tested with

I tested this with Soundtouch system consisting of 6 Boses, stored media and internet radio presets.

NOTE

In order to programm a preset we have a push and HOLD the key for a while. A small extension was required in api.js