Skip to content

Instantly share code, notes, and snippets.

@jordansissel
Created December 9, 2022 08:01
Show Gist options
  • Select an option

  • Save jordansissel/b25b9f396b8d82687d50d069b4a617d1 to your computer and use it in GitHub Desktop.

Select an option

Save jordansissel/b25b9f396b8d82687d50d069b4a617d1 to your computer and use it in GitHub Desktop.

Revisions

  1. jordansissel created this gist Dec 9, 2022.
    20 changes: 20 additions & 0 deletions main.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    const { DeviceDiscovery } = require('sonos');

    DeviceDiscovery((device) => {
    //console.log('found device at ' + device.host + " - " + device.friendlyName)

    device.deviceDescription().then(descr => {
    // look for a sonos named "Sonos Roam"
    if (descr.friendlyName.match(/Sonos Roam/)) {
    console.log(descr);
    // Coheed - Vaxis II - first track
    // https://play.napster.com/track/tra.676707759?ocode=social_user&pcode=social_user&cpath=Link&rsrc=track
    //
    // I learned the song uri by playing a song and then calling currentTrack() to find the uri
    // Then I tried to modify this uri to play a known song.
    // The 'atra.<ID>' seems to be the track name. I'm not entirely sure what the remaining |v1|ALBUM|... bits are
    // For good measure, the 'alb.<NUMBER>.mp4' I inserted the album ID for the album this track is on
    device.play("x-sonos-http:ondemand_track%3a%3atra.676707759|v1|ALBUM|alb.676707757.mp4?sid=202&flags=8232&sn=1");
    }
    });
    });