bencevans / node-sonos

🔈 Sonos Media Player Interface/Client
https://www.npmjs.com/package/sonos
MIT License
703 stars 147 forks source link

getFavorites() returns fewer entries due to wrong User-Agent #540

Open jordansissel opened 1 year ago

jordansissel commented 1 year ago

When calling getFavorites(), in my test, node-sonos gives me two (2) results. In the macOS Sonos app, I show four (4) entries.

Expected Behavior

It should return the same items as the Sonos app has.

Current Behavior

It omits (due to some weirdness in Sonos UPnP?) certain records.

Possible Solution

const axios = require("axios");
axios.defaults.headers.common['User-Agent'] = "Linux UPnP/1.0 Sonos/70.4-35282 (MDCR_Mac14,2)"

This sets the default 'User-Agent' header on all axios requests.

I discovered this by sniffing traffic between the Sonos app and my network and comparing the results, then trying to change one thing at a time to see what improved the outcome.

Sample code or executed example

      device.getFavorites()
        .then(result => { console.log(`Total (default): ${result.total}`) })
        .then(() => {
            const axios = require("axios");
            axios.defaults.headers.common['User-Agent'] = "Linux UPnP/1.0 Sonos/70.4-35282 (MDCR_Mac14,2)"
            return device.getFavorites()
        }).then(result => { console.log(`Total (after setting user-agent): ${result.total}`) })
Total (default): 2
Total (after setting user-agent): 4

Versions (and Environment)

Node version: v19.2.0 node-sonos version: 1.14.1 OS: macOS