Skip to main content

Pause Spotify playback when other apps start making noise

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spotify_interlude-0.1.2.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

spotify_interlude-0.1.2-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file spotify_interlude-0.1.2.tar.gz.

File metadata

  • Download URL: spotify_interlude-0.1.2.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.6 Linux/5.15.0-1023-azure

File hashes

Hashes for spotify_interlude-0.1.2.tar.gz
Algorithm Hash digest
SHA256 2edd2d579ffc6b958f56407b1cf2019aca2e211ebd5585315b812fbb3f8653a2
MD5 c4338ea982da0f65014793823189fc75
BLAKE2b-256 15cb7190329f0bcf5f11d1d7c42eb2f84e9a47a277ce6c021082d3cc35ef0358

See more details on using hashes here.

File details

Details for the file spotify_interlude-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: spotify_interlude-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.10.6 Linux/5.15.0-1023-azure

File hashes

Hashes for spotify_interlude-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 542fb58862b4a0015ac5bd0a10c9c891e803dfff5595fc10ace6265730d7d92c
MD5 da578b2fa9a2ef425a9bcdc0369c042b
BLAKE2b-256 e5fcd9a48f8108a24d68cb5f5b6dbcf7f87c47f5e49f1a3e745926bd832b6396

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page