music.spotify

class platypush.backend.music.spotify.MusicSpotifyBackend(librespot_path: str = 'librespot', device_name: Optional[str] = None, device_type: str = 'speaker', audio_backend: str = 'alsa', audio_device: Optional[str] = None, mixer: str = 'softvol', mixer_name: str = 'PCM', mixer_card: str = 'default', mixer_index: int = 0, volume: int = 100, volume_ctrl: str = 'linear', bitrate: int = 160, autoplay: bool = False, disable_gapless: bool = False, username: Optional[str] = None, password: Optional[str] = None, client_id: Optional[str] = None, client_secret: Optional[str] = None, proxy: Optional[str] = None, ap_port: Optional[int] = None, disable_discovery: bool = False, cache_dir: Optional[str] = None, system_cache_dir: Optional[str] = None, disable_audio_cache=False, enable_volume_normalization: bool = False, normalization_method: str = 'dynamic', normalization_pre_gain: Optional[float] = None, normalization_threshold: float = - 1.0, normalization_attack: int = 5, normalization_release: int = 100, normalization_knee: float = 1.0, **kwargs)[source]

This backend uses librespot to turn Platypush into an audio client compatible with Spotify Connect and discoverable by a device running a Spotify client or app. It can be used to stream Spotify through the Platypush host. After the backend has started, you should see a new entry in the Spotify Connect devices list in your app.

Triggers:

Requires:

  • librespot. Consult the README for instructions.

__init__(librespot_path: str = 'librespot', device_name: Optional[str] = None, device_type: str = 'speaker', audio_backend: str = 'alsa', audio_device: Optional[str] = None, mixer: str = 'softvol', mixer_name: str = 'PCM', mixer_card: str = 'default', mixer_index: int = 0, volume: int = 100, volume_ctrl: str = 'linear', bitrate: int = 160, autoplay: bool = False, disable_gapless: bool = False, username: Optional[str] = None, password: Optional[str] = None, client_id: Optional[str] = None, client_secret: Optional[str] = None, proxy: Optional[str] = None, ap_port: Optional[int] = None, disable_discovery: bool = False, cache_dir: Optional[str] = None, system_cache_dir: Optional[str] = None, disable_audio_cache=False, enable_volume_normalization: bool = False, normalization_method: str = 'dynamic', normalization_pre_gain: Optional[float] = None, normalization_threshold: float = - 1.0, normalization_attack: int = 5, normalization_release: int = 100, normalization_knee: float = 1.0, **kwargs)[source]
Parameters
  • librespot_path – Librespot path/executable name (default: librespot).

  • device_name – Device name (default: same as configured Platypush device_id or hostname).

  • device_type – Device type to be shown in the icon. Available types: unknown, computer, tablet, smartphone, speaker, tv, avr (Audio/Video Receiver), stb (Set-Top Box), or audiodongle (default: speaker).

  • audio_backend – Audio backend to be used. Supported values: alsa, portaudio, pulseaudio, jackaudio, gstreamer, rodio, rodiojack, sdl (default: alsa).

  • audio_device – Output audio device. Type librespot --device ? to get a list of the available devices.

  • mixer – Mixer to be used to control the volume. Supported values: alsa or softvol (default: softvol).

  • mixer_name – Mixer name if using the ALSA mixer. Supported values: PCM or Master (default: PCM).

  • mixer_card – ALSA mixer output card, as reported by aplay -l (default: default).

  • mixer_index – ALSA card index, as reported by aplay -l (default: 0).

  • volume – Initial volume, as an integer between 0 and 100 if volume_ctrl=linear or in dB if volume_ctrl=logarithmic.

  • volume_ctrl – Volume control scale. Supported values: linear and logarithmic (default: linear).

  • bitrate – Audio bitrate. Choose 320 for maximum quality (default: 160).

  • autoplay – Play similar tracks when the queue ends (default: False).

  • disable_gapless – Disable gapless audio (default: False).

  • username – Spotify user/device username (used if you want to enable Spotify Connect remotely).

  • password – Spotify user/device password (used if you want to enable Spotify Connect remotely).

  • client_id – Spotify client ID, required if you want to retrieve track and album info through the Spotify Web API. You can generate one by creating a Spotify app here <https://developer.spotify.com/>.

  • client_secret – Spotify client secret, required if you want to retrieve track and album info through the Spotify Web API. You can generate one by creating a Spotify app here <https://developer.spotify.com/>.

  • proxy – Optional HTTP proxy configuration.

  • ap_port – Spotify AP port to be used (default: default ports, i.e. 80, 443 and 4070).

  • disable_discovery – Disable discovery mode.

  • cache_dir – Data files cache directory.

  • system_cache_dir – System cache directory - it includes audio settings and credentials.

  • disable_audio_cache – Disable audio caching (default: False).

  • enable_volume_normalization – Play all the tracks at about the same volume (default: False).

  • normalization_method – If enable_volume_normalization=True, this setting specifies the volume normalization method. Supported values: basic, dynamic (default: dynamic).

  • normalization_pre_gain – Pre-gain applied to volume normalization if enable_volume_normalization=True, expressed in dB.

  • normalization_threshold – If enable_volume_normalization=True, this setting specifies the normalization threshold (in dBFS) to prevent audio clipping (default: -1.0).

  • normalization_attack – If enable_volume_normalization=True, this setting specifies the attack time (in ms) during which the dynamic limiter is reducing the gain (default: 5).

  • normalization_release – If enable_volume_normalization=True, this setting specifies the release time (in ms) for the dynamic limiter to restore the gain (default: 100).

  • normalization_knee – Knee steepness of the dynamic limiter (default: 1.0).

on_stop()[source]

Callback invoked when the process stops

run()[source]

Starts the backend thread. To be implemented in the derived classes if the loop method isn’t defined.