Skip to content

Commit

Permalink
feat(spotify): multi-user connect device
Browse files Browse the repository at this point in the history
  • Loading branch information
phts committed Feb 9, 2024
1 parent 3ca9f74 commit b6172fe
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 25 deletions.
9 changes: 8 additions & 1 deletion spotify/UIConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
},
"saveButton": {
"label": "TRANSLATE.SAVE",
"data": ["bitrate", "debug", "normalisation_pregain", "icon"]
"data": ["bitrate", "debug", "normalisation_pregain", "icon", "shared_device"]
},
"content": [
{
Expand Down Expand Up @@ -178,6 +178,13 @@
"label": "Set Top Box"
}
]
},
{
"id": "shared_device",
"element": "switch",
"doc": "TRANSLATE.SHARED_DEVICE_DOC",
"label": "TRANSLATE.SHARED_DEVICE",
"value": false
}
]
}
Expand Down
17 changes: 9 additions & 8 deletions spotify/config.yml.tmpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
log_level: trace
device_name: "${device_name}"
server_port: 9879
audio_device: "volumio"
device_type: "${device_type}"
bitrate: ${bitrate_number}
external_volume: ${external_volume}
normalisation_pregain: ${normalisation_pregain}
log_level: trace
device_name: "${device_name}"
server_port: 9879
audio_device: "volumio"
device_type: "${device_type}"
bitrate: ${bitrate_number}
external_volume: ${external_volume}
normalisation_pregain: ${normalisation_pregain}
zeroconf_enabled: ${zeroconf_enabled}
3 changes: 2 additions & 1 deletion spotify/i18n/strings_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"VOLSPOTCONNECTCONF": "Spotify Configuration",
"VOLSPOTCONNECTACCOUNT": "Spotify account",
"HIGHBITRATE": "Stream bitrate",
"SHAREDDEVICE": "Multi-user device",
"SHARED_DEVICE": "Share this device across the network",
"SHARED_DEVICE_DOC": "If enabled, any Spotify user in the same local network may connect to this device. Otherwise, only user signed-in in Volumio may use Connect mode.",
"INITVOL": "Initial volume",
"DESCINITVOL": "Spotify volume when starts",
"VOLNORM": "Normalisation volume",
Expand Down
2 changes: 1 addition & 1 deletion spotify/i18n/strings_it.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"VOLSPOTCONNECTCONF": "Configurazione di Spotify",
"VOLSPOTCONNECTACCOUNT": "Account Spotify",
"HIGHBITRATE": "Stream bitrate",
"SHAREDDEVICE": "Dispositivo multi-utente",
"SHARED_DEVICE": "Dispositivo multi-utente",
"INITVOL": "Volume iniziale",
"DESCINITVOL": "Volume iniziale di riproduzione",
"VOLNORM": "Normalizzazione del volume di ascolto",
Expand Down
2 changes: 1 addition & 1 deletion spotify/i18n/strings_nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"VOLSPOTCONNECTCONF": "Spotify Configuratie",
"VOLSPOTCONNECTACCOUNT": "Spotify account",
"HIGHBITRATE": "Stream bitrate",
"SHAREDDEVICE": "Apparaat voor meerdere gebruikers",
"SHARED_DEVICE": "Apparaat voor meerdere gebruikers",
"INITVOL": "Initieel volume",
"DESCINITVOL": "Beginnend Spotify volume",
"VOLNORM": "Genormaliseerde volume",
Expand Down
29 changes: 17 additions & 12 deletions spotify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ ControllerSpotify.prototype.getUIConfig = function () {
__dirname + '/UIConfig.json',
)
.then(function (uiconf) {
let credentials_type = self.config.get('credentials_type', 'zeroconf');
let credentials_type = self.config.get('credentials_type', null);
if (self.loggedInUserId !== undefined && credentials_type === 'spotify_token') {
uiconf.sections[1].content[0].hidden = true;
uiconf.sections[1].content[1].hidden = false;
Expand All @@ -125,6 +125,8 @@ ControllerSpotify.prototype.getUIConfig = function () {
uiconf.sections[2].content[3].value.value = icon;
uiconf.sections[2].content[3].value.label = self.getLabelForSelect(uiconf.sections[2].content[3].options, icon);

uiconf.sections[2].content[4].value = self.config.get('shared_device', false);

defer.resolve(uiconf);
})
.fail(function (error) {
Expand Down Expand Up @@ -725,27 +727,28 @@ ControllerSpotify.prototype.createConfigFile = function () {
externalVolume = false;
}
let normalisationPregain = self.config.get('normalisation_pregain', '1.0');
const sharedDevice = self.config.get('shared_device', false);

let conf = template
.replace('${device_name}', devicename)
.replace('${bitrate_number}', selectedBitrate)
.replace('${device_type}', icon)
.replace('${external_volume}', externalVolume)
.replace('${normalisation_pregain}', normalisationPregain);
.replace('${normalisation_pregain}', normalisationPregain)
.replace('${zeroconf_enabled}', sharedDevice);

let credentials_type = self.config.get('credentials_type', 'zeroconf');
let credentials_type = self.config.get('credentials_type', null);
let logged_user_id = self.config.get('logged_user_id', '');
let access_token = self.config.get('access_token', '');

if (credentials_type === 'spotify_token' && logged_user_id !== '' && access_token !== '') {
conf += 'credentials: ' + os.EOL;
conf += ' type: spotify_token' + os.EOL;
conf += ' spotify_token:' + os.EOL;
conf += ' username: "' + logged_user_id + '"' + os.EOL;
conf += ' access_token: "' + access_token + '"';
} else {
conf += 'credentials: ' + os.EOL;
conf += ' type: zeroconf' + os.EOL;
conf += `\
credentials:
type: spotify_token
spotify_token:
username: "${logged_user_id}"
access_token: "${access_token}"
`;
}

fs.writeFile(configFileDestinationPath, conf, (err) => {
Expand Down Expand Up @@ -793,6 +796,7 @@ ControllerSpotify.prototype.saveGoLibrespotSettings = function (data) {
if (data.normalisation_pregain && data.normalisation_pregain.value !== undefined) {
self.config.set('normalisation_pregain', data.normalisation_pregain.value);
}
self.config.set('shared_device', !!data.shared_device);

self.selectedBitrate = self.config.get('bitrate_number', '320').toString();
self.initializeLibrespotDaemon();
Expand Down Expand Up @@ -946,7 +950,8 @@ ControllerSpotify.prototype.resetSpotifyCredentials = function () {
self.config.set('logged_user_id', '');
self.config.set('access_token', '');
self.config.set('refresh_token', '');
self.config.set('credentials_type', 'zeroconf');
self.config.set('credentials_type', null);
self.config.set('shared_device', false);

if (self.spotifyApi) {
self.spotifyApi.resetCredentials();
Expand Down
2 changes: 1 addition & 1 deletion spotify/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ if [ -d $VOLSPOTCONNECT2_PATH ]; then
fi

DAEMON_BASE_URL=https://github.com/devgianlu/go-librespot/releases/download/v
VERSION=0.0.10
VERSION=0.0.13
DAEMON_ARCHIVE=go-librespot_linux_$ARCH.tar.gz
DAEMON_DOWNLOAD_URL=$DAEMON_BASE_URL$VERSION/$DAEMON_ARCHIVE
DAEMON_DOWNLOAD_PATH=/home/volumio/$DAEMON_ARCHIVE
Expand Down

0 comments on commit b6172fe

Please sign in to comment.