Skip to content

Ddedalus/spotify-interlude

Repository files navigation

Pause Spotify playback when other apps start making noise on Windows. Automatically resume playback when the other sound finishes.

This mimics default Android functionality, where background music would stop for a duration of a call or alarm and resume afterwards.

Usage

Install

pip install spotify-interlude

Set up Spotify

You'll need to obtain a Development Token from Spotify.

  1. Start by creating an account.
  2. Head to the dashboard and create an App called Interlude on your account.
  3. Copy the client ID and secret. This package will need them to control your Spotify client.
  4. Click 'Edit Settings' and set callback URL to http://localhost:9090. Interlude will start a local server at this address to perform authentication with Spotify web API.

Run Interlude for the first time

$Env:SPOTIFY_SECRET=...
$ENV:SPOTIFY_CLIENT_ID=...
interlude

On the first run, you will be redirected to an authorization page for Spotify at https://accounts.spotify.com. You need to grant necessary permissions on your Spotify account.

Start Spotify and play some music. When you try to play some sounds in Chrome, the music should stop playing.

Configure interlude

You can tweak the behaviour of interlude using command line options:

interlude --help
# Usage: interlude [OPTIONS]
# 
#   Monitor the local Spotify client and apps making foreground noise. If
#   --shortcut-path is specified, create a Windows shortcut with the same
#   options instead.
# 
# Options:
#   --spotify-secret TEXT           Secret from your Spotify App dashboard.
#                                   [env var: SPOTIFY_SECRET; required]
#   --spotify-client-id TEXT        Client Id from your Spotify App dashboard.
#                                   [env var: SPOTIFY_CLIENT_ID; required]
#   -p, --process-name TEXT         Names of the programs which should pause
#                                   Spotify when palying sound.  [default:
#                                   chrome.exe, firefox.exe, Telegram.exe]
#   -d, --device-name TEXT          Name of the Spotify device, in case you have
#                                   multiple connected simultaneously. This can
#                                   be used to pause palyback outside of this
#                                   computer.  [default: SURFACE]
#   --session-refresh-interval FLOAT
#                                   How often to scan for new foreground apps
#                                   (seconds)  [default: 5.0]
#   --warmup-duration FLOAT         Delay between end of foreground sound and
#                                   playback resume.  [default: 2.0]
#   --shortcut-path PATH            Path where a shortcut to Interlude should be
#                                   created.
#   --log-path PATH                 Write logs to this file instead of stdout
#   --log-level TEXT                Minimal level of the logs to display
#                                   [default: INFO]
#   --install-completion [bash|zsh|fish|powershell|pwsh]
#                                   Install completion for the specified shell.
#   --show-completion [bash|zsh|fish|powershell|pwsh]
#                                   Show completion for the specified shell, to
#                                   copy it or customize the installation.
#   --help                          Show this message and exit.

Create shortcut

To easily start interlude, create a shortcut with your desired settings:

interlude --shortcut-path ~/Desktop/Interlude.lnk # add other options as needed

Note: the Spotify secret and client ID will be baked into the shortcut.

Environment file

The CLI parses environment variables, so you can keep secrets etc. out of command line history.

You may find a dotenv file loader handy in PowerShell.

About

Pause Spotify playback when other apps start making noise

Resources

License

Stars

Watchers

Forks

Packages

No packages published