Created
June 6, 2022 17:29
-
-
Save Wunst/ba88304900a1f13c41f20f5eeaea874a to your computer and use it in GitHub Desktop.
Node.js application that reorders the queue of a Sonos smart speaker so that "Ecstasy" by Lou Reed is always the last track
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Sonos } from "sonos"; | |
const host = "192.168.1.32"; | |
const port = 1400; | |
/** | |
* Prüft ob ein Element der Wiedergabeliste "Ecstasy" von Lou Reed ist | |
*/ | |
function isEcstasy(item) { | |
return item.uri == "x-sonos-spotify:spotify%3atrack%3a3RGStGuuUNSftwmTz4b3hm?sid=9&flags=8232&sn=3"; | |
} | |
// Wrapper erzeugen | |
let sonos = new Sonos(host, port); | |
setInterval(async function () { | |
// Queue vom Gerät abfragen | |
let queue = await sonos.getQueue(); | |
let count = queue.total; | |
let items = queue.items; | |
// Ecstasy an das Ende der Liste verschieben | |
for (let i = 0; i < count-1; i++) { | |
if (isEcstasy(items[i])) { | |
sonos.reorderTracksInQueue(i+1, 1, count); | |
sonos.reorderTracksInQueue(count, 1, count-1); | |
} | |
} | |
}, 5000 /* ms */); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment