Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseUrl_Update #97

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
28 changes: 22 additions & 6 deletions MMM-Sonos.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,24 @@ Module.register('MMM-Sonos', {
const roomName = this.getRoomName(item)
if (roomName !== '') {
const currentTrack = item.coordinator.state.currentTrack
let nextTrack = currentTrack
// Check for Spotify, Amazon Radio & Apple Music - nextTrack could be empty which is a Pain
if (currentTrack.uri.includes('spotify')) {
// do nothing leave as it is
} else if (currentTrack.type !== 'radio' && item.coordinator.state.nextTrack.uri !== '') { // Handling Amazon radio lists & Apple Radio
nextTrack = item.coordinator.state.nextTrack
}
// Get baseUrl from either nextTrack.absoluteAlbumArtUri or currentTrack - just the http://xxx.xxx.xxx.xxx:4000 - based on which Source - this is really a pain
const baseUrl = nextTrack.absoluteAlbumArtUri.split('/').slice(0, 3).join('/')
let artist = currentTrack.artist
let track = currentTrack.title
let cover = currentTrack.absoluteAlbumArtUri
// var streamInfo = currentTrack.streamInfo;
// var type = currentTrack.type;

// Get the correct Album Art from albumArtUri - might be with http might be just /getaaa
let cover = currentTrack.albumArtUri
// Check if http ist in cover and adjust with baseUrl if needed
if (!cover.startsWith('http')) {
// If not, prepend the base URL
cover = baseUrl + cover
}
// clean data
artist = artist ? artist.trim() : ''
track = track ? track.trim() : ''
Expand All @@ -71,11 +83,15 @@ Module.register('MMM-Sonos', {
track = ''
}

// Check playback state and only assign album art if playing
const playbackState = item.coordinator.state.playbackState
cover = (playbackState === 'PLAYING') ? cover : ''

roomList.push({
name: roomName,
state: this.isInTVMode(artist, track, cover) ? 'TV' : item.coordinator.state.playbackState,
artist: artist,
track: track,
artist,
track,
albumArt: cover
})
}
Expand Down
52 changes: 31 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"request": "2.88.2"
},
"devDependencies": {
"eslint": "8.57.0",
"eslint": "^8.57.0",
"eslint-config-standard": "17.1.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-node": "11.1.0",
Expand Down