# spotify_monitor
Tool for real-time monitoring of **Spotify friends' music activity feed**.
✨ If you're interested in tracking changes to Spotify users' profiles including their playlists, take a look at another tool I've developed: [spotify_profile_monitor](https://github.com/misiektoja/spotify_profile_monitor).
🛠️ If you're looking for debug tools to get Spotify Web Player access tokens and extract secret keys: [click here](#debugging-tools)
<a id="features"></a>
## Features
- Real-time tracking of songs listened by Spotify users (including detection when user gets online & offline)
- Possibility to automatically play songs listened by the tracked user in your local Spotify client
- Information about the duration the user listened to a song and whether the song was skipped
- Information about the context of the listened song (playlist/artist/album) with clickable URLs
- Email notifications for various events (user becomes active/inactive, specific or all songs, songs on loop, errors)
- Saving all listened songs with timestamps to the CSV file
- Clickable Spotify, Apple Music, YouTube Music and Genius Lyrics search URLs printed in the console & included in email notifications
- Displaying basic statistics for the user's playing session (duration, time span, number of listened and skipped songs, songs on loop)
- Support for two different methods to get a Spotify access token (`sp_dc cookie`, `desktop client`)
- Possibility to control the running copy of the script via signals
<p align="center">
<img src="https://raw.githubusercontent.com/misiektoja/spotify_monitor/refs/heads/main/assets/spotify_monitor.png" alt="spotify_monitor_screenshot" width="90%"/>
</p>
<a id="table-of-contents"></a>
## Table of Contents
1. [Requirements](#requirements)
2. [Installation](#installation)
* [Install from PyPI](#install-from-pypi)
* [Manual Installation](#manual-installation)
3. [Quick Start](#quick-start)
4. [Configuration](#configuration)
* [Configuration File](#configuration-file)
* [Spotify access token source](#spotify-access-token-source)
* [Spotify sp_dc Cookie](#spotify-sp_dc-cookie)
* [Spotify Desktop Client](#spotify-desktop-client)
* [Following the Monitored User](#following-the-monitored-user)
* [How to Get a Friend's User URI ID](#how-to-get-a-friends-user-uri-id)
* [SMTP Settings](#smtp-settings)
* [Storing Secrets](#storing-secrets)
5. [Usage](#usage)
* [Monitoring Mode](#monitoring-mode)
* [Listing Mode](#listing-mode)
* [Email Notifications](#email-notifications)
* [CSV Export](#csv-export)
* [Automatic Playback of Listened Tracks in the Spotify Client](#automatic-playback-of-listened-tracks-in-the-spotify-client)
* [Check Intervals](#check-intervals)
* [Signal Controls (macOS/Linux/Unix)](#signal-controls-macoslinuxunix)
* [Coloring Log Output with GRC](#coloring-log-output-with-grc)
6. [Debugging Tools](#debugging-tools)
* [Access Token Retrieval via sp_dc Cookie and TOTP](#access-token-retrieval-via-sp_dc-cookie-and-totp)
* [Secret Key Extraction from Spotify Web Player Bundles](#secret-key-extraction-from-spotify-web-player-bundles)
7. [Change Log](#change-log)
8. [License](#license)
<a id="requirements"></a>
## Requirements
* Python 3.6 or higher
* Libraries: `requests`, `python-dateutil`, `urllib3`, `pyotp`, `python-dotenv`, `wcwidth`
Tested on:
* **macOS**: Ventura, Sonoma, Sequoia
* **Linux**: Raspberry Pi OS (Bullseye, Bookworm), Ubuntu 24, Rocky Linux 8.x/9.x, Kali Linux 2024/2025
* **Windows**: 10, 11
It should work on other versions of macOS, Linux, Unix and Windows as well.
<a id="installation"></a>
## Installation
<a id="install-from-pypi"></a>
### Install from PyPI
```sh
pip install spotify_monitor
```
<a id="manual-installation"></a>
### Manual Installation
Download the *[spotify_monitor.py](https://raw.githubusercontent.com/misiektoja/spotify_monitor/refs/heads/main/spotify_monitor.py)* file to the desired location.
Install dependencies via pip:
```sh
pip install requests python-dateutil urllib3 pyotp python-dotenv wcwidth
```
Alternatively, from the downloaded *[requirements.txt](https://raw.githubusercontent.com/misiektoja/spotify_monitor/refs/heads/main/requirements.txt)*:
```sh
pip install -r requirements.txt
```
<a id="quick-start"></a>
## Quick Start
- Grab your [Spotify sp_dc cookie](#spotify-sp_dc-cookie) and track the `spotify_user_uri_id` music activities:
```sh
spotify_monitor <spotify_user_uri_id> -u "your_sp_dc_cookie_value"
```
Or if you installed [manually](#manual-installation):
```sh
python3 spotify_monitor.py <spotify_user_uri_id> -u "your_sp_dc_cookie_value"
```
To get the list of all supported command-line arguments / flags:
```sh
spotify_monitor --help
```
<a id="configuration"></a>
## Configuration
<a id="configuration-file"></a>
### Configuration File
Most settings can be configured via command-line arguments.
If you want to have it stored persistently, generate a default config template and save it to a file named `spotify_monitor.conf`:
```sh
spotify_monitor --generate-config > spotify_monitor.conf
```
Edit the `spotify_monitor.conf` file and change any desired configuration options (detailed comments are provided for each).
<a id="spotify-access-token-source"></a>
### Spotify access token source
The tool supports two methods for obtaining a Spotify access token.
It can be configured via the `TOKEN_SOURCE` configuration option or the `--token-source` flag.
**Recommended: `cookie`**
Uses the `sp_dc` cookie to retrieve a token from the Spotify web endpoint. This method is easy to set up and recommended for most users.
**Alternative: `client`**
Uses captured credentials from the Spotify desktop client and a Protobuf-based login flow. It's more complex to set up and intended for advanced users who want a long-lasting token with the broadest possible access.
If no method is specified, the tool defaults to the `cookie` method.
**Important**: It is strongly recommended to use a separate Spotify account with this tool. It does not rely on the official Spotify Web API for core features (like fetching friend activity), as it is not supported by the public API. That said, while I've never encountered any issues on my own accounts, I can't guarantee that Spotify won't impose restrictions in the future - you've been warned.
<a id="spotify-sp_dc-cookie"></a>
#### Spotify sp_dc Cookie
This is the default method used to obtain a Spotify access token.
- Log in to [https://open.spotify.com/](https://open.spotify.com/) in your web browser.
- Locate and copy the value of the `sp_dc` cookie.
- Use your web browser's dev console or **Cookie-Editor** by cgagnier to extract it easily: [https://cookie-editor.com/](https://cookie-editor.com/)
- Provide the `SP_DC_COOKIE` secret using one of the following methods:
- Pass it at runtime with `-u` / `--spotify-dc-cookie`
- Set it as an [environment variable](#storing-secrets) (e.g. `export SP_DC_COOKIE=...`)
- Add it to [.env file](#storing-secrets) (`SP_DC_COOKIE=...`) for persistent use
- Fallback: hard-code it in the code or config file
If your `sp_dc` cookie expires, the tool will notify you via the console and email. In that case, you'll need to grab the new `sp_dc` cookie value.
If you store the `SP_DC_COOKIE` in a dotenv file you can update its value and send a `SIGHUP` signal to reload the file with the new `sp_dc` cookie without restarting the tool. More info in [Storing Secrets](#storing-secrets) and [Signal Controls (macOS/Linux/Unix)](#signal-controls-macoslinuxunix).
> **NOTE:** secrets used for TOTP generation (`SECRET_CIPHER_DICT`) expire every two days, that's why since v2.4 the tool fetches it from remote URL (see `SECRET_CIPHER_DICT_URL`); you can also run the [spotify_monitor_secret_grabber](https://github.com/misiektoja/spotify_monitor/blob/dev/debug/spotify_monitor_secret_grabber.py) and extract it by yourself (see [Secret Key Extraction from Spotify Web Player Bundles](#secret-key-extraction-from-spotify-web-player-bundles) for more info).
<a id="spotify-desktop-client"></a>
#### Spotify Desktop Client
This is the alternative method used to obtain a Spotify access token which simulates a login from the real Spotify desktop app using credentials intercepted from a real session.
- Run an intercepting proxy of your choice (like [Proxyman](https://proxyman.com) - the trial version is sufficient)
- Enable SSL traffic decryption for `spotify.com` domain
- in Proxyman: click **Tools → SSL Proxying List → + button → Add Domain → paste `*.spotify.com` → Add**
- Launch the Spotify desktop client, then switch to your intercepting proxy (like Proxyman) and look for POST requests to `https://login5.spotify.com/v3/login`
- If you don't see this request, try following steps (stop once it works):
- restart the Spotify desktop client
- log out from the Spotify desktop client and log back in
- point Spotify at the intercepting proxy directly in its settings, i.e. in **Spotify → Settings → Proxy Settings**, set:
- **proxy type**: `HTTP`
- **host**: `127.0.0.1` (IP/FQDN of your proxy, for Proxyman use the IP you see at the top bar)
- **port**: `9090` (port of your proxy, for Proxyman use the port you see at the top bar)
- restart the app; since QUIC (HTTP/3) requires raw UDP and can't tunnel over HTTP CONNECT, Spotify will downgrade to TCP-only HTTP/2 or 1.1, which intercepting proxy can decrypt
- block Spotify's UDP port 443 at the OS level with a firewall of your choice - this prevents QUIC (HTTP/3), forcing TLS over TCP and letting intercepting proxy perform MITM
- try an older version of the Spotify desktop client
- Export the login request body (a binary Protobuf payload) to a file (e.g. ***login-request-body-file***)
- In Proxyman: **right click the request → Export → Request Body → Save File**.
<p align="center">
<img src="https://raw.githubusercontent.com/misiektoja/spotify_monitor/refs/heads/main/assets/proxyman_export_protobuf.png" alt="proxyman_export_protobuf" width="80%"/>
</p>
- Run the tool with `--token-source client -w <path-to-login-request-body-file>`:
```sh
spotify_monitor --token-source client -w <path-to-login-request-body-file> <spotify_user_uri_id>
```
If successful, the tool will automatically extract the necessary fields and begin monitoring.
Instead of using the `-w` flag each time, you can persist the Protobuf login request file path by setting the `LOGIN_REQUEST_BODY_FILE` configuration option.
The same applies to `--token-source client` flag - you can persist it via `TOKEN_SOURCE` configuration option set to `client`.
The tool will automatically refresh both the access token and client token using the intercepted refresh token.
If your refresh token expires, the tool will notify you via the console and email. In that case, you'll need to re-export the login request body.
If you re-export the login request body to the same file name, you can send a `SIGHUP` signal to reload the file with the new refresh token without restarting the tool. More info in [Signal Controls (macOS/Linux/Unix)](#signal-controls-macoslinuxunix).
Advanced options are available for further customization - refer to the configuration file comments. However, the default settings are suitable for most users and modifying other values is generally NOT recommended.
<a id="following-the-monitored-user"></a>
### Following the Monitored User
To monitor a user's activity, you must follow them from the Spotify account associated with the `sp_dc` cookie.
Additionally, the user must have sharing of listening activity enabled in their Spotify client settings. Without this, no activity data will be visible.
<a id="how-to-get-a-friends-user-uri-id"></a>
### How to Get a Friend's User URI ID
The easiest way is via the Spotify desktop or mobile client:
- go to your friend's profile
- click the **three dots** (•••) or press the **Share** button
- copy the link to the profile
You'll get a URL like: [https://open.spotify.com/user/spotify_user_uri_id?si=tracking_id](https://open.spotify.com/user/spotify_user_uri_id?si=tracking_id)
Extract the part between `/user/` and `?si=` - in this case: `spotify_user_uri_id`
Use that as the user URI ID (`spotify_user_uri_id`) in the tool.
Alternatively you can list all user URI IDs of accounts you follow by using [Listing mode](#listing-mode).
<a id="smtp-settings"></a>
### SMTP Settings
If you want to use email notifications functionality, configure SMTP settings in the `spotify_monitor.conf` file.
Verify your SMTP settings by using `--send-test-email` flag (the tool will try to send a test email notification):
```sh
spotify_monitor --send-test-email
```
<a id="storing-secrets"></a>
### Storing Secrets
It is recommended to store secrets like `SP_DC_COOKIE`, `REFRESH_TOKEN` or `SMTP_PASSWORD` as either an environment variable or in a dotenv file.
Set the needed environment variables using `export` on **Linux/Unix/macOS/WSL** systems:
```sh
export SP_DC_COOKIE="your_sp_dc_cookie_value"
export REFRESH_TOKEN="your_spotify_app_refresh_token"
export SMTP_PASSWORD="your_smtp_password"
```
On **Windows Command Prompt** use `set` instead of `export` and on **Windows PowerShell** use `$env`.
Alternatively store them persistently in a dotenv file (recommended):
```ini
SP_DC_COOKIE="your_sp_dc_cookie_value"
REFRESH_TOKEN="your_spotify_app_refresh_token"
SMTP_PASSWORD="your_smtp_password"
```
By default the tool will auto-search for dotenv file named `.env` in current directory and then upward from it.
You can specify a custom file with `DOTENV_FILE` or `--env-file` flag:
```sh
spotify_monitor <spotify_user_uri_id> --env-file /path/.env-spotify_monitor
```
You can also disable `.env` auto-search with `DOTENV_FILE = "none"` or `--env-file none`:
```sh
spotify_monitor <spotify_user_uri_id> --env-file none
```
As a fallback, you can also store secrets in the configuration file or source code.
<a id="usage"></a>
## Usage
<a id="monitoring-mode"></a>
### Monitoring Mode
To monitor specific user activity, just type [Spotify user URI ID](#how-to-get-a-friends-user-uri-id) as a command-line argument (`spotify_user_uri_id` in the example below):
```sh
spotify_monitor <spotify_user_uri_id>
```
If you use the default method to obtain a Spotify access token (`cookie`) and have not set `SP_DC_COOKIE` secret, you can use `-u` flag:
```sh
spotify_monitor <spotify_user_uri_id> -u "your_sp_dc_cookie_value"
```
By default, the tool looks for a configuration file named `spotify_monitor.conf` in:
- current directory
- home directory (`~`)
- script directory
If you generated a configuration file as described in [Configuration](#configuration), but saved it under a different name or in a different directory, you can specify its location using the `--config-file` flag:
```sh
spotify_monitor <spotify_user_uri_id> --config-file /path/spotify_monitor_new.conf
```
The tool runs until interrupted (`Ctrl+C`). Use `tmux` or `screen` for persistence.
You can monitor multiple Spotify friends by running multiple copies of the script.
The tool automatically saves its output to `spotify_monitor_<user_uri_id/file_suffix>.log` file. The log file name can be changed via `SP_LOGFILE` configuration option and its suffix via `FILE_SUFFIX` / `-y` flag. Logging can be disabled completely via `DISABLE_LOGGING` / `-d` flag.
Keep in mind that monitoring reports the listened track AFTER the user finishes listening to it. This is how activities are reported by Spotify.
<a id="listing-mode"></a>
### Listing Mode
There is also another mode of the tool which displays various requested information.
If you want to display a list of all the friends you follow with their recently listened tracks (`-l` flag):
```sh
spotify_monitor -l
```
It also displays your friend's Spotify username (often the user's first and last name) and user URI ID (often a string of random characters). The latter should be used as a tool's command-line argument to monitor the user.
<p align="center">
<img src="https://raw.githubusercontent.com/misiektoja/spotify_monitor/refs/heads/main/assets/spotify_monitor_listing.png" alt="spotify_monitor_listing" width="90%"/>
</p>
To get basic information about the Spotify access token owner (`-v` flag):
```sh
spotify_monitor -v
```
<a id="email-notifications"></a>
### Email Notifications
To enable email notifications when a user becomes active:
- set `ACTIVE_NOTIFICATION` to `True`
- or use the `-a` flag
```sh
spotify_monitor <spotify_user_uri_id> -a
```
To be informed when a user gets inactive:
- set `INACTIVE_NOTIFICATION` to `True`
- or use the `-i` flag
```sh
spotify_monitor <spotify_user_uri_id> -i
```
To get email notifications when a monitored track/playlist/album plays:
- set `TRACK_NOTIFICATION` to `True`
- or use the `-t` flag
For that feature you also need to create a file with a list of songs you want to track (one track, album or playlist per line). Specify the file using the `MONITOR_LIST_FILE` or `-s` flag:
```sh
spotify_monitor <spotify_user_uri_id> -t -s spotify_tracks_spotify_user_uri_id
```
Example file `spotify_tracks_spotify_user_uri_id`:
```
we fell in love in october
Like a Stone
Half Believing
Something Changed
I Will Be There
```
You can comment out specific lines with # if needed.
To enable email notifications for every song listened by the user:
- set `SONG_NOTIFICATION` to `True`
- or use the `-j` flag
```sh
spotify_monitor <spotify_user_uri_id> -j
```
To be notified when a user listens to the same song on loop:
- set `SONG_ON_LOOP_NOTIFICATION` to `True`
- or use the `-x` flag
```sh
spotify_monitor <spotify_user_uri_id> -x
```
To disable sending an email on errors (enabled by default):
- set `ERROR_NOTIFICATION` to `False`
- or use the `-e` flag
```sh
spotify_monitor <spotify_user_uri_id> -e
```
Make sure you defined your SMTP settings earlier (see [SMTP settings](#smtp-settings)).
Example email:
<p align="center">
<img src="https://raw.githubusercontent.com/misiektoja/spotify_monitor/refs/heads/main/assets/spotify_monitor_email_notifications.png" alt="spotify_monitor_email_notifications" width="80%"/>
</p>
<a id="csv-export"></a>
### CSV Export
If you want to save all listened songs to a CSV file, set `CSV_FILE` or use `-b` flag:
```sh
spotify_monitor <spotify_user_uri_id> -b spotify_tracks_user_uri_id.csv
```
The file will be automatically created if it does not exist.
<a id="automatic-playback-of-listened-tracks-in-the-spotify-client"></a>
### Automatic Playback of Listened Tracks in the Spotify Client
If you want the tool to automatically play the tracks listened to by the user in your local Spotify client:
- set `TRACK_SONGS` to `True`
- or use the `-g` flag
```sh
spotify_monitor <spotify_user_uri_id> -g
```
Your Spotify client needs to be installed and running for this feature to work.
The tool fully supports automatic playback on **Linux** and **macOS**. This means it will automatically play the changed track and can also pause or play the indicated track once the user becomes inactive (see the `SP_USER_GOT_OFFLINE_TRACK_ID` configuration option).
For **Windows**, it works in a semi-automatic way: if you have the Spotify client running and you are not listening to any song, then the first track will play automatically. However, subsequent tracks will be located in the client, but you will need to press the play button manually.
You can change the playback method per platform using the corresponding configuration option.
For **macOS** set `SPOTIFY_MACOS_PLAYING_METHOD` to one of the following values:
- "**apple-script**" (recommended, **default**)
- "trigger-url"
For **Linux** set `SPOTIFY_LINUX_PLAYING_METHOD` to one of the following values:
- "**dbus-send**" (most common one, **default**)
- "qdbus" (try if dbus-send does not work)
- "trigger-url"
For **Windows** set `SPOTIFY_WINDOWS_PLAYING_METHOD` to one of the following values:
- "**start-uri**" (recommended, **default**)
- "spotify-cmd"
- "trigger-url"
The recommended defaults should work for most people.
Note: monitoring reports the listened track after the user finishes listening to it. This is how activities are reported by Spotify. It means you will be one song behind the monitored user and if the song currently listened to by the tracked user is longer than the previous one, then the previously listened song might be played in your Spotify client on repeat (and if shorter it might be changed in the middle of the currently played song).
For real-time playback tracking of a user's music activities, ask your friend to connect their Spotify account with [Last.fm](https://www.last.fm/). Then use my other tool: [lastfm_monitor](https://github.com/misiektoja/lastfm_monitor).
<a id="check-intervals"></a>
### Check Intervals
If you want to customize the polling interval, use `-c` flag (or `SPOTIFY_CHECK_INTERVAL` configuration option):
```sh
spotify_monitor <spotify_user_uri_id> -c 20
```
If you want to change the time required to mark the user as inactive (the timer starts from the last reported track), use `-o` flag (or `SPOTIFY_INACTIVITY_CHECK` configuration option):
```sh
spotify_monitor <spotify_user_uri_id> -o 900
```
<a id="signal-controls-macoslinuxunix"></a>
### Signal Controls (macOS/Linux/Unix)
The tool has several signal handlers implemented which allow to change behavior of the tool without a need to restart it with new configuration options / flags.
List of supported signals:
| Signal | Description |
| ----------- | ----------- |
| USR1 | Toggle email notifications when user gets active/inactive (-a, -i) |
| USR2 | Toggle email notifications for every song (-j) |
| CONT | Toggle email notifications for tracked songs (-t) |
| PIPE | Toggle email notifications when user plays song on loop (-x) |
| TRAP | Increase the inactivity check timer (by 30 seconds) (-o) |
| ABRT | Decrease the inactivity check timer (by 30 seconds) (-o) |
| HUP | Reload secrets from .env file and token source credentials from Protobuf files |
Send signals with `kill` or `pkill`, e.g.:
```sh
pkill -USR1 -f "spotify_monitor <spotify_user_uri_id>"
```
As Windows supports limited number of signals, this functionality is available only on Linux/Unix/macOS.
<a id="coloring-log-output-with-grc"></a>
### Coloring Log Output with GRC
You can use [GRC](https://github.com/garabik/grc) to color logs.
Add to your GRC config (`~/.grc/grc.conf`):
```
# monitoring log file
.*_monitor_.*\.log
conf.monitor_logs
```
Now copy the [conf.monitor_logs](https://raw.githubusercontent.com/misiektoja/spotify_monitor/refs/heads/main/grc/conf.monitor_logs) to your `~/.grc/` and log files should be nicely colored when using `grc` tool.
Example:
```sh
grc tail -F -n 100 spotify_monitor_<user_uri_id/file_suffix>.log
```
<a id="debugging-tools"></a>
## Debugging Tools
To help with troubleshooting and development, two debug utilities are available in the [debug](https://github.com/misiektoja/spotify_monitor/tree/dev/debug) directory.
<a id="access-token-retrieval-via-sp_dc-cookie-and-totp"></a>
### Access Token Retrieval via sp_dc Cookie and TOTP
The [spotify_monitor_totp_test](https://github.com/misiektoja/spotify_monitor/blob/dev/debug/spotify_monitor_totp_test.py) tool retrieves a Spotify access token using a Web Player `sp_dc` cookie and TOTP parameters.
Download from [here](https://github.com/misiektoja/spotify_monitor/blob/dev/debug/spotify_monitor_totp_test.py) or:
```sh
wget https://raw.githubusercontent.com/misiektoja/spotify_monitor/refs/heads/dev/debug/spotify_monitor_totp_test.py
```
Install requirements:
```sh
pip install requests python-dateutil pyotp
```
Run:
```sh
python3 spotify_monitor_totp_test.py --sp-dc "your_sp_dc_cookie_value"
```
You should get a valid Spotify access token, example output:
<p align="center">
<img src="https://raw.githubusercontent.com/misiektoja/spotify_monitor/refs/heads/main/assets/spotify_monitor_totp_test.png" alt="spotify_monitor_totp_test" width="100%"/>
</p>
> **NOTE:** secrets used for TOTP generation (`SECRET_CIPHER_DICT`) expire every two days; you can either run the [spotify_monitor_secret_grabber](https://github.com/misiektoja/spotify_monitor/blob/dev/debug/spotify_monitor_secret_grabber.py) and extract it by yourself (see [here](#secret-key-extraction-from-spotify-web-player-bundles) for more info) or you can pass `--fetch-secrets` flag in [spotify_monitor_totp_test](https://github.com/misiektoja/spotify_monitor/blob/dev/debug/spotify_monitor_totp_test.py) (available since v1.6). There is also a [Thereallo1026/spotify-secrets](https://github.com/Thereallo1026/spotify-secrets) repo which offers JSON files that are automatically updated with current secrets.
<a id="secret-key-extraction-from-spotify-web-player-bundles"></a>
### Secret Key Extraction from Spotify Web Player Bundles
The [spotify_monitor_secret_grabber](https://github.com/misiektoja/spotify_monitor/blob/dev/debug/spotify_monitor_secret_grabber.py) tool automatically extracts secret keys used for TOTP generation in Spotify Web Player JavaScript bundles.
Download from [here](https://github.com/misiektoja/spotify_monitor/blob/dev/debug/spotify_monitor_secret_grabber.py) or:
```sh
wget https://raw.githubusercontent.com/misiektoja/spotify_monitor/refs/heads/dev/debug/spotify_monitor_secret_grabber.py
```
Install requirements:
```sh
pip install playwright
playwright install
```
Run:
```sh
python3 spotify_monitor_secret_grabber.py
```
You should get output similar to below:
<p align="center">
<img src="https://raw.githubusercontent.com/misiektoja/spotify_monitor/refs/heads/main/assets/spotify_monitor_secret_grabber.png" alt="spotify_monitor_secret_grabber" width="100%"/>
</p>
You can now update the secrets used for TOTP generation (for example `SECRET_CIPHER_DICT` in `spotify_monitor_totp_test`, `spotify_monitor` and `spotify_profile_monitor`).
> **NOTE:** you can also use [Thereallo1026/spotify-secrets](https://github.com/Thereallo1026/spotify-secrets) repo which offers JSON files that are automatically updated with current secrets (its secret extraction code is based on `spotify_monitor_secret_grabber`).
<a id="change-log"></a>
## Change Log
See [RELEASE_NOTES.md](https://github.com/misiektoja/spotify_monitor/blob/main/RELEASE_NOTES.md) for details.
<a id="license"></a>
## License
Licensed under GPLv3. See [LICENSE](https://github.com/misiektoja/spotify_monitor/blob/main/LICENSE).
Raw data
{
"_id": null,
"home_page": null,
"name": "spotify-monitor",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "spotify, monitoring, tracking, real-time, friend-activity, osint",
"author": null,
"author_email": "Michal Szymanski <misiektoja-pypi@rm-rf.ninja>",
"download_url": "https://files.pythonhosted.org/packages/39/75/01f0952dbb0d9cc8482b3cb01d60d137555ef3ed3b7e315e43a4f3fc1fe6/spotify_monitor-2.4.tar.gz",
"platform": null,
"description": "# spotify_monitor\n\nTool for real-time monitoring of **Spotify friends' music activity feed**.\n\n\u2728 If you're interested in tracking changes to Spotify users' profiles including their playlists, take a look at another tool I've developed: [spotify_profile_monitor](https://github.com/misiektoja/spotify_profile_monitor).\n\n\ud83d\udee0\ufe0f If you're looking for debug tools to get Spotify Web Player access tokens and extract secret keys: [click here](#debugging-tools)\n\n<a id=\"features\"></a>\n## Features\n\n- Real-time tracking of songs listened by Spotify users (including detection when user gets online & offline)\n- Possibility to automatically play songs listened by the tracked user in your local Spotify client\n- Information about the duration the user listened to a song and whether the song was skipped\n- Information about the context of the listened song (playlist/artist/album) with clickable URLs\n- Email notifications for various events (user becomes active/inactive, specific or all songs, songs on loop, errors)\n- Saving all listened songs with timestamps to the CSV file\n- Clickable Spotify, Apple Music, YouTube Music and Genius Lyrics search URLs printed in the console & included in email notifications\n- Displaying basic statistics for the user's playing session (duration, time span, number of listened and skipped songs, songs on loop)\n- Support for two different methods to get a Spotify access token (`sp_dc cookie`, `desktop client`)\n- Possibility to control the running copy of the script via signals\n\n<p align=\"center\">\n <img src=\"https://raw.githubusercontent.com/misiektoja/spotify_monitor/refs/heads/main/assets/spotify_monitor.png\" alt=\"spotify_monitor_screenshot\" width=\"90%\"/>\n</p>\n\n<a id=\"table-of-contents\"></a>\n## Table of Contents\n\n1. [Requirements](#requirements)\n2. [Installation](#installation)\n * [Install from PyPI](#install-from-pypi)\n * [Manual Installation](#manual-installation)\n3. [Quick Start](#quick-start)\n4. [Configuration](#configuration)\n * [Configuration File](#configuration-file)\n * [Spotify access token source](#spotify-access-token-source)\n * [Spotify sp_dc Cookie](#spotify-sp_dc-cookie)\n * [Spotify Desktop Client](#spotify-desktop-client)\n * [Following the Monitored User](#following-the-monitored-user)\n * [How to Get a Friend's User URI ID](#how-to-get-a-friends-user-uri-id)\n * [SMTP Settings](#smtp-settings)\n * [Storing Secrets](#storing-secrets)\n5. [Usage](#usage)\n * [Monitoring Mode](#monitoring-mode)\n * [Listing Mode](#listing-mode)\n * [Email Notifications](#email-notifications)\n * [CSV Export](#csv-export)\n * [Automatic Playback of Listened Tracks in the Spotify Client](#automatic-playback-of-listened-tracks-in-the-spotify-client)\n * [Check Intervals](#check-intervals)\n * [Signal Controls (macOS/Linux/Unix)](#signal-controls-macoslinuxunix)\n * [Coloring Log Output with GRC](#coloring-log-output-with-grc)\n6. [Debugging Tools](#debugging-tools)\n * [Access Token Retrieval via sp_dc Cookie and TOTP](#access-token-retrieval-via-sp_dc-cookie-and-totp)\n * [Secret Key Extraction from Spotify Web Player Bundles](#secret-key-extraction-from-spotify-web-player-bundles)\n7. [Change Log](#change-log)\n8. [License](#license)\n\n<a id=\"requirements\"></a>\n## Requirements\n\n* Python 3.6 or higher\n* Libraries: `requests`, `python-dateutil`, `urllib3`, `pyotp`, `python-dotenv`, `wcwidth`\n\nTested on:\n\n* **macOS**: Ventura, Sonoma, Sequoia\n* **Linux**: Raspberry Pi OS (Bullseye, Bookworm), Ubuntu 24, Rocky Linux 8.x/9.x, Kali Linux 2024/2025\n* **Windows**: 10, 11\n\nIt should work on other versions of macOS, Linux, Unix and Windows as well.\n\n<a id=\"installation\"></a>\n## Installation\n\n<a id=\"install-from-pypi\"></a>\n### Install from PyPI\n\n```sh\npip install spotify_monitor\n```\n\n<a id=\"manual-installation\"></a>\n### Manual Installation\n\nDownload the *[spotify_monitor.py](https://raw.githubusercontent.com/misiektoja/spotify_monitor/refs/heads/main/spotify_monitor.py)* file to the desired location.\n\nInstall dependencies via pip:\n\n```sh\npip install requests python-dateutil urllib3 pyotp python-dotenv wcwidth\n```\n\nAlternatively, from the downloaded *[requirements.txt](https://raw.githubusercontent.com/misiektoja/spotify_monitor/refs/heads/main/requirements.txt)*:\n\n```sh\npip install -r requirements.txt\n```\n\n<a id=\"quick-start\"></a>\n## Quick Start\n\n- Grab your [Spotify sp_dc cookie](#spotify-sp_dc-cookie) and track the `spotify_user_uri_id` music activities:\n\n\n```sh\nspotify_monitor <spotify_user_uri_id> -u \"your_sp_dc_cookie_value\"\n```\n\nOr if you installed [manually](#manual-installation):\n\n```sh\npython3 spotify_monitor.py <spotify_user_uri_id> -u \"your_sp_dc_cookie_value\"\n```\n\nTo get the list of all supported command-line arguments / flags:\n\n```sh\nspotify_monitor --help\n```\n\n<a id=\"configuration\"></a>\n## Configuration\n\n<a id=\"configuration-file\"></a>\n### Configuration File\n\nMost settings can be configured via command-line arguments.\n\nIf you want to have it stored persistently, generate a default config template and save it to a file named `spotify_monitor.conf`:\n\n```sh\nspotify_monitor --generate-config > spotify_monitor.conf\n\n```\n\nEdit the `spotify_monitor.conf` file and change any desired configuration options (detailed comments are provided for each).\n\n<a id=\"spotify-access-token-source\"></a>\n### Spotify access token source\n\nThe tool supports two methods for obtaining a Spotify access token.\n\nIt can be configured via the `TOKEN_SOURCE` configuration option or the `--token-source` flag. \n\n**Recommended: `cookie`** \n\nUses the `sp_dc` cookie to retrieve a token from the Spotify web endpoint. This method is easy to set up and recommended for most users.\n\n**Alternative: `client`** \n\nUses captured credentials from the Spotify desktop client and a Protobuf-based login flow. It's more complex to set up and intended for advanced users who want a long-lasting token with the broadest possible access.\n\nIf no method is specified, the tool defaults to the `cookie` method.\n\n**Important**: It is strongly recommended to use a separate Spotify account with this tool. It does not rely on the official Spotify Web API for core features (like fetching friend activity), as it is not supported by the public API. That said, while I've never encountered any issues on my own accounts, I can't guarantee that Spotify won't impose restrictions in the future - you've been warned.\n\n<a id=\"spotify-sp_dc-cookie\"></a>\n#### Spotify sp_dc Cookie\n\nThis is the default method used to obtain a Spotify access token.\n\n- Log in to [https://open.spotify.com/](https://open.spotify.com/) in your web browser.\n\n- Locate and copy the value of the `sp_dc` cookie.\n - Use your web browser's dev console or **Cookie-Editor** by cgagnier to extract it easily: [https://cookie-editor.com/](https://cookie-editor.com/)\n\n- Provide the `SP_DC_COOKIE` secret using one of the following methods:\n - Pass it at runtime with `-u` / `--spotify-dc-cookie`\n - Set it as an [environment variable](#storing-secrets) (e.g. `export SP_DC_COOKIE=...`)\n - Add it to [.env file](#storing-secrets) (`SP_DC_COOKIE=...`) for persistent use\n - Fallback: hard-code it in the code or config file\n\nIf your `sp_dc` cookie expires, the tool will notify you via the console and email. In that case, you'll need to grab the new `sp_dc` cookie value.\n\nIf you store the `SP_DC_COOKIE` in a dotenv file you can update its value and send a `SIGHUP` signal to reload the file with the new `sp_dc` cookie without restarting the tool. More info in [Storing Secrets](#storing-secrets) and [Signal Controls (macOS/Linux/Unix)](#signal-controls-macoslinuxunix).\n\n> **NOTE:** secrets used for TOTP generation (`SECRET_CIPHER_DICT`) expire every two days, that's why since v2.4 the tool fetches it from remote URL (see `SECRET_CIPHER_DICT_URL`); you can also run the [spotify_monitor_secret_grabber](https://github.com/misiektoja/spotify_monitor/blob/dev/debug/spotify_monitor_secret_grabber.py) and extract it by yourself (see [Secret Key Extraction from Spotify Web Player Bundles](#secret-key-extraction-from-spotify-web-player-bundles) for more info).\n\n<a id=\"spotify-desktop-client\"></a>\n#### Spotify Desktop Client\n\nThis is the alternative method used to obtain a Spotify access token which simulates a login from the real Spotify desktop app using credentials intercepted from a real session.\n\n- Run an intercepting proxy of your choice (like [Proxyman](https://proxyman.com) - the trial version is sufficient)\n\n- Enable SSL traffic decryption for `spotify.com` domain\n - in Proxyman: click **Tools \u2192 SSL Proxying List \u2192 + button \u2192 Add Domain \u2192 paste `*.spotify.com` \u2192 Add**\n\n- Launch the Spotify desktop client, then switch to your intercepting proxy (like Proxyman) and look for POST requests to `https://login5.spotify.com/v3/login`\n\n- If you don't see this request, try following steps (stop once it works):\n - restart the Spotify desktop client\n - log out from the Spotify desktop client and log back in\n - point Spotify at the intercepting proxy directly in its settings, i.e. in **Spotify \u2192 Settings \u2192 Proxy Settings**, set:\n - **proxy type**: `HTTP`\n - **host**: `127.0.0.1` (IP/FQDN of your proxy, for Proxyman use the IP you see at the top bar)\n - **port**: `9090` (port of your proxy, for Proxyman use the port you see at the top bar)\n - restart the app; since QUIC (HTTP/3) requires raw UDP and can't tunnel over HTTP CONNECT, Spotify will downgrade to TCP-only HTTP/2 or 1.1, which intercepting proxy can decrypt\n - block Spotify's UDP port 443 at the OS level with a firewall of your choice - this prevents QUIC (HTTP/3), forcing TLS over TCP and letting intercepting proxy perform MITM\n - try an older version of the Spotify desktop client\n\n- Export the login request body (a binary Protobuf payload) to a file (e.g. ***login-request-body-file***)\n - In Proxyman: **right click the request \u2192 Export \u2192 Request Body \u2192 Save File**.\n\n<p align=\"center\">\n <img src=\"https://raw.githubusercontent.com/misiektoja/spotify_monitor/refs/heads/main/assets/proxyman_export_protobuf.png\" alt=\"proxyman_export_protobuf\" width=\"80%\"/>\n</p>\n\n- Run the tool with `--token-source client -w <path-to-login-request-body-file>`:\n\n```sh\nspotify_monitor --token-source client -w <path-to-login-request-body-file> <spotify_user_uri_id>\n```\n\nIf successful, the tool will automatically extract the necessary fields and begin monitoring.\n\nInstead of using the `-w` flag each time, you can persist the Protobuf login request file path by setting the `LOGIN_REQUEST_BODY_FILE` configuration option.\n\nThe same applies to `--token-source client` flag - you can persist it via `TOKEN_SOURCE` configuration option set to `client`.\n\nThe tool will automatically refresh both the access token and client token using the intercepted refresh token.\n\nIf your refresh token expires, the tool will notify you via the console and email. In that case, you'll need to re-export the login request body. \n\nIf you re-export the login request body to the same file name, you can send a `SIGHUP` signal to reload the file with the new refresh token without restarting the tool. More info in [Signal Controls (macOS/Linux/Unix)](#signal-controls-macoslinuxunix).\n\nAdvanced options are available for further customization - refer to the configuration file comments. However, the default settings are suitable for most users and modifying other values is generally NOT recommended.\n\n<a id=\"following-the-monitored-user\"></a>\n### Following the Monitored User\n\nTo monitor a user's activity, you must follow them from the Spotify account associated with the `sp_dc` cookie.\n\nAdditionally, the user must have sharing of listening activity enabled in their Spotify client settings. Without this, no activity data will be visible.\n\n<a id=\"how-to-get-a-friends-user-uri-id\"></a>\n### How to Get a Friend's User URI ID\n\nThe easiest way is via the Spotify desktop or mobile client:\n- go to your friend's profile\n- click the **three dots** (\u2022\u2022\u2022) or press the **Share** button\n- copy the link to the profile\n\nYou'll get a URL like: [https://open.spotify.com/user/spotify_user_uri_id?si=tracking_id](https://open.spotify.com/user/spotify_user_uri_id?si=tracking_id)\n\nExtract the part between `/user/` and `?si=` - in this case: `spotify_user_uri_id`\n\nUse that as the user URI ID (`spotify_user_uri_id`) in the tool.\n\nAlternatively you can list all user URI IDs of accounts you follow by using [Listing mode](#listing-mode).\n\n<a id=\"smtp-settings\"></a>\n### SMTP Settings\n\nIf you want to use email notifications functionality, configure SMTP settings in the `spotify_monitor.conf` file. \n\nVerify your SMTP settings by using `--send-test-email` flag (the tool will try to send a test email notification):\n\n```sh\nspotify_monitor --send-test-email\n```\n\n<a id=\"storing-secrets\"></a>\n### Storing Secrets\n\nIt is recommended to store secrets like `SP_DC_COOKIE`, `REFRESH_TOKEN` or `SMTP_PASSWORD` as either an environment variable or in a dotenv file.\n\nSet the needed environment variables using `export` on **Linux/Unix/macOS/WSL** systems:\n\n```sh\nexport SP_DC_COOKIE=\"your_sp_dc_cookie_value\"\nexport REFRESH_TOKEN=\"your_spotify_app_refresh_token\"\nexport SMTP_PASSWORD=\"your_smtp_password\"\n```\n\nOn **Windows Command Prompt** use `set` instead of `export` and on **Windows PowerShell** use `$env`.\n\nAlternatively store them persistently in a dotenv file (recommended):\n\n```ini\nSP_DC_COOKIE=\"your_sp_dc_cookie_value\"\nREFRESH_TOKEN=\"your_spotify_app_refresh_token\"\nSMTP_PASSWORD=\"your_smtp_password\"\n```\n\nBy default the tool will auto-search for dotenv file named `.env` in current directory and then upward from it. \n\nYou can specify a custom file with `DOTENV_FILE` or `--env-file` flag:\n\n```sh\nspotify_monitor <spotify_user_uri_id> --env-file /path/.env-spotify_monitor\n```\n\n You can also disable `.env` auto-search with `DOTENV_FILE = \"none\"` or `--env-file none`:\n\n```sh\nspotify_monitor <spotify_user_uri_id> --env-file none\n```\n\nAs a fallback, you can also store secrets in the configuration file or source code.\n\n<a id=\"usage\"></a>\n## Usage\n\n<a id=\"monitoring-mode\"></a>\n### Monitoring Mode\n\nTo monitor specific user activity, just type [Spotify user URI ID](#how-to-get-a-friends-user-uri-id) as a command-line argument (`spotify_user_uri_id` in the example below):\n\n```sh\nspotify_monitor <spotify_user_uri_id>\n```\n\nIf you use the default method to obtain a Spotify access token (`cookie`) and have not set `SP_DC_COOKIE` secret, you can use `-u` flag:\n\n```sh\nspotify_monitor <spotify_user_uri_id> -u \"your_sp_dc_cookie_value\"\n```\n\nBy default, the tool looks for a configuration file named `spotify_monitor.conf` in:\n - current directory \n - home directory (`~`)\n - script directory \n\n If you generated a configuration file as described in [Configuration](#configuration), but saved it under a different name or in a different directory, you can specify its location using the `--config-file` flag:\n\n\n```sh\nspotify_monitor <spotify_user_uri_id> --config-file /path/spotify_monitor_new.conf\n```\n\nThe tool runs until interrupted (`Ctrl+C`). Use `tmux` or `screen` for persistence.\n\nYou can monitor multiple Spotify friends by running multiple copies of the script.\n\nThe tool automatically saves its output to `spotify_monitor_<user_uri_id/file_suffix>.log` file. The log file name can be changed via `SP_LOGFILE` configuration option and its suffix via `FILE_SUFFIX` / `-y` flag. Logging can be disabled completely via `DISABLE_LOGGING` / `-d` flag.\n\nKeep in mind that monitoring reports the listened track AFTER the user finishes listening to it. This is how activities are reported by Spotify.\n\n<a id=\"listing-mode\"></a>\n### Listing Mode\n\nThere is also another mode of the tool which displays various requested information.\n\nIf you want to display a list of all the friends you follow with their recently listened tracks (`-l` flag):\n\n```sh\nspotify_monitor -l\n```\n\nIt also displays your friend's Spotify username (often the user's first and last name) and user URI ID (often a string of random characters). The latter should be used as a tool's command-line argument to monitor the user.\n\n<p align=\"center\">\n <img src=\"https://raw.githubusercontent.com/misiektoja/spotify_monitor/refs/heads/main/assets/spotify_monitor_listing.png\" alt=\"spotify_monitor_listing\" width=\"90%\"/>\n</p>\n\nTo get basic information about the Spotify access token owner (`-v` flag):\n\n```sh\nspotify_monitor -v\n```\n\n<a id=\"email-notifications\"></a>\n### Email Notifications\n\nTo enable email notifications when a user becomes active:\n- set `ACTIVE_NOTIFICATION` to `True`\n- or use the `-a` flag\n\n```sh\nspotify_monitor <spotify_user_uri_id> -a\n```\n\nTo be informed when a user gets inactive:\n- set `INACTIVE_NOTIFICATION` to `True`\n- or use the `-i` flag\n\n```sh\nspotify_monitor <spotify_user_uri_id> -i\n```\n\nTo get email notifications when a monitored track/playlist/album plays:\n- set `TRACK_NOTIFICATION` to `True`\n- or use the `-t` flag\n\nFor that feature you also need to create a file with a list of songs you want to track (one track, album or playlist per line). Specify the file using the `MONITOR_LIST_FILE` or `-s` flag:\n\n```sh\nspotify_monitor <spotify_user_uri_id> -t -s spotify_tracks_spotify_user_uri_id\n```\n\nExample file `spotify_tracks_spotify_user_uri_id`:\n\n```\nwe fell in love in october\nLike a Stone\nHalf Believing\nSomething Changed\nI Will Be There\n```\n\nYou can comment out specific lines with # if needed.\n\nTo enable email notifications for every song listened by the user:\n- set `SONG_NOTIFICATION` to `True`\n- or use the `-j` flag\n\n```sh\nspotify_monitor <spotify_user_uri_id> -j\n```\n\nTo be notified when a user listens to the same song on loop:\n- set `SONG_ON_LOOP_NOTIFICATION` to `True`\n- or use the `-x` flag\n\n```sh\nspotify_monitor <spotify_user_uri_id> -x\n```\n\nTo disable sending an email on errors (enabled by default):\n- set `ERROR_NOTIFICATION` to `False`\n- or use the `-e` flag\n\n```sh\nspotify_monitor <spotify_user_uri_id> -e\n```\n\nMake sure you defined your SMTP settings earlier (see [SMTP settings](#smtp-settings)).\n\nExample email:\n\n<p align=\"center\">\n <img src=\"https://raw.githubusercontent.com/misiektoja/spotify_monitor/refs/heads/main/assets/spotify_monitor_email_notifications.png\" alt=\"spotify_monitor_email_notifications\" width=\"80%\"/>\n</p>\n\n<a id=\"csv-export\"></a>\n### CSV Export\n\nIf you want to save all listened songs to a CSV file, set `CSV_FILE` or use `-b` flag:\n\n```sh\nspotify_monitor <spotify_user_uri_id> -b spotify_tracks_user_uri_id.csv\n```\n\nThe file will be automatically created if it does not exist.\n\n<a id=\"automatic-playback-of-listened-tracks-in-the-spotify-client\"></a>\n### Automatic Playback of Listened Tracks in the Spotify Client\n\nIf you want the tool to automatically play the tracks listened to by the user in your local Spotify client:\n- set `TRACK_SONGS` to `True`\n- or use the `-g` flag\n\n```sh\nspotify_monitor <spotify_user_uri_id> -g\n```\n\nYour Spotify client needs to be installed and running for this feature to work.\n\nThe tool fully supports automatic playback on **Linux** and **macOS**. This means it will automatically play the changed track and can also pause or play the indicated track once the user becomes inactive (see the `SP_USER_GOT_OFFLINE_TRACK_ID` configuration option).\n\nFor **Windows**, it works in a semi-automatic way: if you have the Spotify client running and you are not listening to any song, then the first track will play automatically. However, subsequent tracks will be located in the client, but you will need to press the play button manually. \n\nYou can change the playback method per platform using the corresponding configuration option.\n\nFor **macOS** set `SPOTIFY_MACOS_PLAYING_METHOD` to one of the following values:\n- \"**apple-script**\" (recommended, **default**)\n- \"trigger-url\"\n\nFor **Linux** set `SPOTIFY_LINUX_PLAYING_METHOD` to one of the following values:\n- \"**dbus-send**\" (most common one, **default**)\n- \"qdbus\" (try if dbus-send does not work)\n- \"trigger-url\"\n\nFor **Windows** set `SPOTIFY_WINDOWS_PLAYING_METHOD` to one of the following values:\n- \"**start-uri**\" (recommended, **default**)\n- \"spotify-cmd\"\n- \"trigger-url\"\n\nThe recommended defaults should work for most people.\n\nNote: monitoring reports the listened track after the user finishes listening to it. This is how activities are reported by Spotify. It means you will be one song behind the monitored user and if the song currently listened to by the tracked user is longer than the previous one, then the previously listened song might be played in your Spotify client on repeat (and if shorter it might be changed in the middle of the currently played song).\n\nFor real-time playback tracking of a user's music activities, ask your friend to connect their Spotify account with [Last.fm](https://www.last.fm/). Then use my other tool: [lastfm_monitor](https://github.com/misiektoja/lastfm_monitor).\n\n<a id=\"check-intervals\"></a>\n### Check Intervals\n\nIf you want to customize the polling interval, use `-c` flag (or `SPOTIFY_CHECK_INTERVAL` configuration option):\n\n```sh\nspotify_monitor <spotify_user_uri_id> -c 20\n```\n\nIf you want to change the time required to mark the user as inactive (the timer starts from the last reported track), use `-o` flag (or `SPOTIFY_INACTIVITY_CHECK` configuration option):\n\n```sh\nspotify_monitor <spotify_user_uri_id> -o 900\n```\n\n<a id=\"signal-controls-macoslinuxunix\"></a>\n### Signal Controls (macOS/Linux/Unix)\n\nThe tool has several signal handlers implemented which allow to change behavior of the tool without a need to restart it with new configuration options / flags.\n\nList of supported signals:\n\n| Signal | Description |\n| ----------- | ----------- |\n| USR1 | Toggle email notifications when user gets active/inactive (-a, -i) |\n| USR2 | Toggle email notifications for every song (-j) |\n| CONT | Toggle email notifications for tracked songs (-t) |\n| PIPE | Toggle email notifications when user plays song on loop (-x) |\n| TRAP | Increase the inactivity check timer (by 30 seconds) (-o) |\n| ABRT | Decrease the inactivity check timer (by 30 seconds) (-o) |\n| HUP | Reload secrets from .env file and token source credentials from Protobuf files |\n\nSend signals with `kill` or `pkill`, e.g.:\n\n```sh\npkill -USR1 -f \"spotify_monitor <spotify_user_uri_id>\"\n```\n\nAs Windows supports limited number of signals, this functionality is available only on Linux/Unix/macOS.\n\n<a id=\"coloring-log-output-with-grc\"></a>\n### Coloring Log Output with GRC\n\nYou can use [GRC](https://github.com/garabik/grc) to color logs.\n\nAdd to your GRC config (`~/.grc/grc.conf`):\n\n```\n# monitoring log file\n.*_monitor_.*\\.log\nconf.monitor_logs\n```\n\nNow copy the [conf.monitor_logs](https://raw.githubusercontent.com/misiektoja/spotify_monitor/refs/heads/main/grc/conf.monitor_logs) to your `~/.grc/` and log files should be nicely colored when using `grc` tool.\n\nExample:\n\n```sh\ngrc tail -F -n 100 spotify_monitor_<user_uri_id/file_suffix>.log\n```\n\n<a id=\"debugging-tools\"></a>\n## Debugging Tools\n\nTo help with troubleshooting and development, two debug utilities are available in the [debug](https://github.com/misiektoja/spotify_monitor/tree/dev/debug) directory.\n\n<a id=\"access-token-retrieval-via-sp_dc-cookie-and-totp\"></a>\n### Access Token Retrieval via sp_dc Cookie and TOTP\n\nThe [spotify_monitor_totp_test](https://github.com/misiektoja/spotify_monitor/blob/dev/debug/spotify_monitor_totp_test.py) tool retrieves a Spotify access token using a Web Player `sp_dc` cookie and TOTP parameters. \n\nDownload from [here](https://github.com/misiektoja/spotify_monitor/blob/dev/debug/spotify_monitor_totp_test.py) or:\n\n```sh\nwget https://raw.githubusercontent.com/misiektoja/spotify_monitor/refs/heads/dev/debug/spotify_monitor_totp_test.py\n```\n\nInstall requirements:\n\n```sh\npip install requests python-dateutil pyotp\n```\n\nRun:\n\n```sh\npython3 spotify_monitor_totp_test.py --sp-dc \"your_sp_dc_cookie_value\"\n```\n\nYou should get a valid Spotify access token, example output:\n\n<p align=\"center\">\n <img src=\"https://raw.githubusercontent.com/misiektoja/spotify_monitor/refs/heads/main/assets/spotify_monitor_totp_test.png\" alt=\"spotify_monitor_totp_test\" width=\"100%\"/>\n</p>\n\n> **NOTE:** secrets used for TOTP generation (`SECRET_CIPHER_DICT`) expire every two days; you can either run the [spotify_monitor_secret_grabber](https://github.com/misiektoja/spotify_monitor/blob/dev/debug/spotify_monitor_secret_grabber.py) and extract it by yourself (see [here](#secret-key-extraction-from-spotify-web-player-bundles) for more info) or you can pass `--fetch-secrets` flag in [spotify_monitor_totp_test](https://github.com/misiektoja/spotify_monitor/blob/dev/debug/spotify_monitor_totp_test.py) (available since v1.6). There is also a [Thereallo1026/spotify-secrets](https://github.com/Thereallo1026/spotify-secrets) repo which offers JSON files that are automatically updated with current secrets.\n\n<a id=\"secret-key-extraction-from-spotify-web-player-bundles\"></a>\n### Secret Key Extraction from Spotify Web Player Bundles\n\nThe [spotify_monitor_secret_grabber](https://github.com/misiektoja/spotify_monitor/blob/dev/debug/spotify_monitor_secret_grabber.py) tool automatically extracts secret keys used for TOTP generation in Spotify Web Player JavaScript bundles. \n\nDownload from [here](https://github.com/misiektoja/spotify_monitor/blob/dev/debug/spotify_monitor_secret_grabber.py) or:\n\n```sh\nwget https://raw.githubusercontent.com/misiektoja/spotify_monitor/refs/heads/dev/debug/spotify_monitor_secret_grabber.py\n```\n\nInstall requirements:\n\n```sh\npip install playwright\nplaywright install\n```\n\nRun:\n\n```sh\npython3 spotify_monitor_secret_grabber.py\n```\n\nYou should get output similar to below:\n\n<p align=\"center\">\n <img src=\"https://raw.githubusercontent.com/misiektoja/spotify_monitor/refs/heads/main/assets/spotify_monitor_secret_grabber.png\" alt=\"spotify_monitor_secret_grabber\" width=\"100%\"/>\n</p>\n\nYou can now update the secrets used for TOTP generation (for example `SECRET_CIPHER_DICT` in `spotify_monitor_totp_test`, `spotify_monitor` and `spotify_profile_monitor`).\n\n> **NOTE:** you can also use [Thereallo1026/spotify-secrets](https://github.com/Thereallo1026/spotify-secrets) repo which offers JSON files that are automatically updated with current secrets (its secret extraction code is based on `spotify_monitor_secret_grabber`).\n\n<a id=\"change-log\"></a>\n## Change Log\n\nSee [RELEASE_NOTES.md](https://github.com/misiektoja/spotify_monitor/blob/main/RELEASE_NOTES.md) for details.\n\n<a id=\"license\"></a>\n## License\n\nLicensed under GPLv3. See [LICENSE](https://github.com/misiektoja/spotify_monitor/blob/main/LICENSE).\n",
"bugtrack_url": null,
"license": null,
"summary": "Tool implementing real-time tracking of Spotify friends music activity",
"version": "2.4",
"project_urls": {
"Changelog": "https://github.com/misiektoja/spotify_monitor/blob/main/RELEASE_NOTES.md",
"Homepage": "https://github.com/misiektoja/spotify_monitor",
"Source": "https://github.com/misiektoja/spotify_monitor"
},
"split_keywords": [
"spotify",
" monitoring",
" tracking",
" real-time",
" friend-activity",
" osint"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "7ec9328cfbe580f97eb8eb16d36a1373399fa2d65cb45e58528edc9e46fe6dd5",
"md5": "c623b86e4cc09cb97346fb72c4bab32b",
"sha256": "88d86e4e28dd75ee3623d392d2cd817d728bbfe53e94f69cf96162de43f939c9"
},
"downloads": -1,
"filename": "spotify_monitor-2.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c623b86e4cc09cb97346fb72c4bab32b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 55181,
"upload_time": "2025-07-13T23:36:24",
"upload_time_iso_8601": "2025-07-13T23:36:24.777536Z",
"url": "https://files.pythonhosted.org/packages/7e/c9/328cfbe580f97eb8eb16d36a1373399fa2d65cb45e58528edc9e46fe6dd5/spotify_monitor-2.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "397501f0952dbb0d9cc8482b3cb01d60d137555ef3ed3b7e315e43a4f3fc1fe6",
"md5": "fa8c41d6a85ce32c2a6274b8eaa6d31a",
"sha256": "2e833f70483c631fe5604108ef685d2b232a114166c239b11e93485f6a11b36b"
},
"downloads": -1,
"filename": "spotify_monitor-2.4.tar.gz",
"has_sig": false,
"md5_digest": "fa8c41d6a85ce32c2a6274b8eaa6d31a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 61383,
"upload_time": "2025-07-13T23:36:26",
"upload_time_iso_8601": "2025-07-13T23:36:26.300465Z",
"url": "https://files.pythonhosted.org/packages/39/75/01f0952dbb0d9cc8482b3cb01d60d137555ef3ed3b7e315e43a4f3fc1fe6/spotify_monitor-2.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-13 23:36:26",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "misiektoja",
"github_project": "spotify_monitor",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "requests",
"specs": []
},
{
"name": "python-dateutil",
"specs": []
},
{
"name": "urllib3",
"specs": []
},
{
"name": "pyotp",
"specs": []
},
{
"name": "python-dotenv",
"specs": []
},
{
"name": "wcwidth",
"specs": []
}
],
"lcname": "spotify-monitor"
}