/
/
1"""Constants for the Spotify provider."""
2
3from __future__ import annotations
4
5# Configuration Keys
6CONF_CLIENT_ID = "client_id"
7CONF_REFRESH_TOKEN_DEPRECATED = "refresh_token" # Legacy key for migration, will be removed
8CONF_REFRESH_TOKEN_GLOBAL = "refresh_token_global" # Token authenticated with MA's client ID
9CONF_REFRESH_TOKEN_DEV = "refresh_token_dev" # Token authenticated with user's custom client ID
10CONF_SYNC_PODCAST_PROGRESS = "sync_podcast_progress"
11CONF_SYNC_AUDIOBOOK_PROGRESS = "sync_audiobook_progress"
12CONF_LIBRESPOT_CREDENTIALS = "librespot_credentials" # librespot's reusable stored credential
13CONF_ACCOUNT_ID = "account_id" # Spotify user id this instance serves (one instance per account)
14
15# Playback backend selection; configs predating the choice default to librespot
16CONF_PLAYBACK_BACKEND = "playback_backend"
17BACKEND_LIBRESPOT = "librespot"
18BACKEND_SOLOIST = "soloist"
19
20# Soloist-specific values collected by the setup flow (see CONF_PLAYBACK_BACKEND)
21CONF_SOLOIST_API_KEY = "soloist_api_key"
22CONF_SOLOIST_CONSENT = "soloist_download_consent"
23# a session paired by the setup flow, as a directory relative to the storage
24# path; adopted into the per-instance data dir on the next provider (re)load
25CONF_SOLOIST_SESSION_DIR = "soloist_session_dir"
26SOLOIST_DATA_DIR_NAME = "soloist-data"
27SOLOIST_PAIRING_DIR = "spotify/pairing"
28# the engine names its per-account state dir "<username>-user", which is where a
29# paired session records which Spotify account it belongs to
30SOLOIST_USER_DIR_SUFFIX = "-user"
31# Streaming quality, only meaningful on the soloist backend: librespot hands over
32# Spotify's own ~320 kbps Ogg stream untouched and has nothing to choose.
33CONF_AUDIO_QUALITY = "audio_quality"
34# Whether Spotify's own loudness normalization is used instead of MA's. Only
35# meaningful on the soloist backend: librespot hands over the untouched file.
36CONF_SPOTIFY_NORMALIZATION = "spotify_normalization"
37# The playback session registers under this name, so it shows up as a device in
38# the user's Spotify apps for as long as Music Assistant is playing.
39SOLOIST_DEVICE_NAME = "Music Assistant"
40
41# Librespot playback authorization
42#
43# Spotify's login5 endpoint only accepts a stored credential that was minted with the same
44# client id librespot presents, which is always Spotify's own "keymaster" id. A credential
45# minted with MA's (or a user's) client id is rejected, so the playback credential has to be
46# obtained separately from the Web API tokens.
47KEYMASTER_CLIENT_ID = "65b708073fc0480ea92a077233ca87bd"
48LIBRESPOT_SCOPE = ["streaming"]
49# keymaster accepts loopback redirect URIs only, so the browser flow cannot use MA's hosted
50# callback. Music Assistant serves the loopback target itself, which works when the browser
51# runs on the same host; otherwise the browser lands on a dead URL that the user pastes back.
52LIBRESPOT_REDIRECT_PORT = 5588
53LIBRESPOT_REDIRECT_PATH = "/login"
54LIBRESPOT_REDIRECT_URI = f"http://127.0.0.1:{LIBRESPOT_REDIRECT_PORT}{LIBRESPOT_REDIRECT_PATH}"
55LOOPBACK_WAIT_TIMEOUT = 30 # seconds before offering the manual paste instead
56# name advertised to the Spotify app while pairing; also shown in the setup flow instructions
57PAIRING_DEVICE_NAME = "Music Assistant Pairing"
58PAIRING_TIMEOUT = 300 # seconds the pairing step waits for the user to pick the device
59CHECK_AUTH_TIMEOUT = 30 # seconds
60CREDENTIALS_FILE = "credentials.json"
61
62# OAuth Settings
63SCOPE = [
64 "playlist-read-private",
65 "playlist-read-collaborative",
66 "playlist-modify-public",
67 "playlist-modify-private",
68 "user-follow-modify",
69 "user-follow-read",
70 "user-library-read",
71 "user-library-modify",
72 "user-read-private",
73 "user-read-email",
74 "user-top-read",
75 "app-remote-control",
76 "streaming",
77 "user-read-playback-state",
78 "user-modify-playback-state",
79 "user-read-currently-playing",
80 "user-read-playback-position",
81 "user-read-recently-played",
82]
83
84# Other Constants
85LIKED_SONGS_FAKE_PLAYLIST_ID_PREFIX = "liked_songs"
86