platypush.plugins.music.snapcast

class platypush.plugins.music.snapcast.MusicSnapcastPlugin(host='localhost', port=1705, *args, **kwargs)[source]

Plugin to interact with a [Snapcast](https://github.com/badaix/snapcast) instance, control clients mute status, volume, playback etc.

See https://github.com/badaix/snapcast/blob/master/doc/json_rpc_api/v2_0_0.md for further reference about the returned API types.

__init__(host='localhost', port=1705, *args, **kwargs)[source]
Parameters:
  • host (str) – Default Snapcast server host (default: localhost)
  • port (int) – Default Snapcast server control port (default: 1705)
delete_client(client, host=None, port=None)[source]

Delete a client from the Snapcast server

Parameters:
  • client (str) – Client name or ID
  • host (str) – Snapcast server (default: default configured host)
  • port (int) – Snapcast server port (default: default configured port)
get_backend_hosts()[source]
Returns:A dict with the Snapcast hosts configured on the backend in the format host -> port
get_playing_streams(exclude_local=False)[source]

Returns the remote streams configured in the music.snapcast backend that are currently active and unmuted.

Parameters:exclude_local (bool) – Exclude localhost connections (default: False)
Returns:dict with the host->port mapping.

Example:

{
    "hosts": {
        "server_1": 1705,
        "server_2": 1705,
        "server_3": 1705
    }
}
group_set_clients(group, clients, host=None, port=None)[source]

Sets the clients for a group on a Snapcast server

Parameters:
  • group (str) – Group name or ID
  • clients (list[str]) – List of client names or IDs
  • host (str) – Snapcast server (default: default configured host)
  • port (int) – Snapcast server port (default: default configured port)
group_set_stream(group, stream_id, host=None, port=None)[source]

Sets the active stream for a group.

Parameters:
  • group (str) – Group name or ID
  • stream_id (str) – Stream ID
  • host (str) – Snapcast server (default: default configured host)
  • port (int) – Snapcast server port (default: default configured port)
mute(client=None, group=None, mute=None, host=None, port=None)[source]

Set the mute status of a connected client or group

Parameters:
  • client (str) – Client name or ID to mute
  • group (str) – Group ID to mute
  • mute (bool) – Mute status. If not set, the mute status of the selected client/group will be toggled.
  • host (str) – Snapcast server to query (default: default configured host)
  • port (int) – Snapcast server port (default: default configured port)
set_client_name(client, name, host=None, port=None)[source]

Set/change the name of a connected client

Parameters:
  • client (str) – Current client name or ID to rename
  • name (str) – New name
  • host (str) – Snapcast server (default: default configured host)
  • port (int) – Snapcast server port (default: default configured port)
set_latency(client, latency, host=None, port=None)[source]

Set/change the latency of a connected client

Parameters:
  • client (str) – Client name or ID
  • latency (float) – New latency in milliseconds
  • host (str) – Snapcast server (default: default configured host)
  • port (int) – Snapcast server port (default: default configured port)
status(host=None, port=None, client=None, group=None)[source]

Get the status either of a Snapcast server, client or group

Parameters:
  • host (str) – Snapcast server to query (default: default configured host)
  • port (int) – Snapcast server port (default: default configured port)
  • client (str) – Client ID or name (default: None)
  • group (str) – Group ID or name (default: None)
Returns:

dict.

Example:

"output": {
    "groups": [
        {
        "clients": [
            {
            "config": {
                "instance": 1,
                "latency": 0,
                "name": "",
                "volume": {
                "muted": false,
                "percent": 96
                }
            },
            "connected": true,
            "host": {
                "arch": "x86_64",
                "ip": "YOUR_IP",
                "mac": "YOUR_MAC",
                "name": "YOUR_NAME",
                "os": "YOUR_OS"
            },
            "id": "YOUR_ID",
            "lastSeen": {
                "sec": 1546648311,
                "usec": 86011
            },
            "snapclient": {
                "name": "Snapclient",
                "protocolVersion": 2,
                "version": "0.15.0"
            }
            }
        ],
        "id": "YOUR_ID",
        "muted": false,
        "name": "",
        "stream_id": "mopidy"
        }
    ],
    "server": {
        "host": {
        "arch": "armv7l",
        "ip": "",
        "mac": "",
        "name": "YOUR_NAME",
        "os": "YOUR_OS"
        },
        "snapserver": {
        "controlProtocolVersion": 1,
        "name": "Snapserver",
        "protocolVersion": 1,
        "version": "0.15.0"
        }
    },
    "streams": [
        {
            "id": "mopidy",
            "meta": {
                "STREAM": "mopidy"
            },
            "status": "playing",
            "uri": {
                "fragment": "",
                "host": "",
                "path": "/tmp/snapfifo",
                "query": {
                "buffer_ms": "20",
                "codec": "pcm",
                "name": "mopidy",
                "sampleformat": "48000:16:2"
                },
                "raw": "pipe:////tmp/snapfifo?buffer_ms=20&codec=pcm&name=mopidy&sampleformat=48000:16:2",
                "scheme": "pipe"
            }
        }
    ]
}
volume(client, volume=None, delta=None, mute=None, host=None, port=None)[source]

Set the volume of a connected client

Parameters:
  • client (str) – Client name or ID
  • volume (int) – Absolute volume to set between 0 and 100
  • delta (int) – Relative volume change in percentage (e.g. +10 or -10)
  • mute (bool) – Set to true or false if you want to toggle the muted status
  • host (str) – Snapcast server (default: default configured host)
  • port (int) – Snapcast server port (default: default configured port)