/
/
/
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. Deliberately
39# not plain "Music Assistant": that is what the Spotify Connect provider calls
40# its own (permanently advertised) device by default, and picking the wrong one
41# of two identically named entries is exactly what ends this session badly.
42SOLOIST_DEVICE_NAME = "Music Assistant Playback"
43
44# Librespot playback authorization
45#
46# Spotify's login5 endpoint only accepts a stored credential that was minted with the same
47# client id librespot presents, which is always Spotify's own "keymaster" id. A credential
48# minted with MA's (or a user's) client id is rejected, so the playback credential has to be
49# obtained separately from the Web API tokens.
50KEYMASTER_CLIENT_ID = "65b708073fc0480ea92a077233ca87bd"
51LIBRESPOT_SCOPE = ["streaming"]
52# keymaster accepts loopback redirect URIs only, so the browser flow cannot use MA's hosted
53# callback. Music Assistant serves the loopback target itself, which works when the browser
54# runs on the same host; otherwise the browser lands on a dead URL that the user pastes back.
55LIBRESPOT_REDIRECT_PORT = 5588
56LIBRESPOT_REDIRECT_PATH = "/login"
57LIBRESPOT_REDIRECT_URI = f"http://127.0.0.1:{LIBRESPOT_REDIRECT_PORT}{LIBRESPOT_REDIRECT_PATH}"
58LOOPBACK_WAIT_TIMEOUT = 30 # seconds before offering the manual paste instead
59# name advertised to the Spotify app while pairing; also shown in the setup flow instructions
60PAIRING_DEVICE_NAME = "Music Assistant Pairing"
61PAIRING_TIMEOUT = 300 # seconds the pairing step waits for the user to pick the device
62CHECK_AUTH_TIMEOUT = 30 # seconds
63CREDENTIALS_FILE = "credentials.json"
64
65# OAuth Settings
66SCOPE = [
67 "playlist-read-private",
68 "playlist-read-collaborative",
69 "playlist-modify-public",
70 "playlist-modify-private",
71 "user-follow-modify",
72 "user-follow-read",
73 "user-library-read",
74 "user-library-modify",
75 "user-read-private",
76 "user-read-email",
77 "user-top-read",
78 "app-remote-control",
79 "streaming",
80 "user-read-playback-state",
81 "user-modify-playback-state",
82 "user-read-currently-playing",
83 "user-read-playback-position",
84 "user-read-recently-played",
85]
86
87# Other Constants
88LIKED_SONGS_FAKE_PLAYLIST_ID_PREFIX = "liked_songs"
89