Unofficial personal automation that mirrors your Spotify currently playing track into Telegram profile music.
This project is a proof of concept. It does not download audio from Spotify. When a matching iTunes preview is available, the preview clip is downloaded locally, uploaded to your private Telegram cache channel, and used as the Telegram profile music document.
- Spotify OAuth PKCE login
- Reads current Spotify track with
user-read-currently-playing - Finds iTunes preview clips with artist/title matching
- Uploads previews to a private Telegram cache channel
- Calls Telegram
account.saveMusic - Supports private Telegram invite links
- Skips repeated updates for the same track
- Python 3.11+
- Spotify developer app
- Telegram API app credentials from
https://my.telegram.org/apps - A private Telegram channel for cached preview uploads
src/spotify_bridge.py- Spotify OAuth, currently-playing reads, and end-to-end syncsrc/itunes_preview.py- iTunes Search API preview lookup and matchingsrc/telegram_cache.py- Telegram cache upload, profile music save, and local mapping toolsassets/flow.webp- README flow diagram
python3 -m venv .venv
. .venv/bin/activate
pip install -r requirements.txtCopy the example environment:
cp .env.example .envThen fill in .env or export the variables in your shell:
export SPOTIFY_CLIENT_ID="your_spotify_client_id"
export TELEGRAM_API_ID="123456"
export TELEGRAM_API_HASH="your_telegram_api_hash"
export TELEGRAM_PHONE="+10000000000"
export TELEGRAM_CACHE_CHANNEL="https://t.me/+your_private_invite_hash"Do not commit .env.
Create an app in the Spotify Developer Dashboard:
https://developer.spotify.com/dashboard
Add this redirect URI exactly:
http://127.0.0.1:8888/callback
Login once:
python3 src/spotify_bridge.py spotify-loginIf your dashboard uses localhost instead, pass the same redirect URI to the CLI:
python3 src/spotify_bridge.py spotify-login \
--redirect-uri "http://localhost:8888/callback"There is also a manual fallback:
python3 src/spotify_bridge.py spotify-login --manualCreate a Telegram API app:
https://my.telegram.org/apps
Create a private Telegram channel for cached preview uploads. TELEGRAM_CACHE_CHANNEL accepts:
@channel_usernamehttps://t.me/+inviteHashhttps://t.me/joinchat/inviteHash- numeric channel id
The first Telegram command may ask for your login code and 2FA password. The session is stored locally in .telegram_preview_cache.session.
Check what Spotify reports:
python3 src/spotify_bridge.py currentSync once:
python3 -u src/spotify_bridge.py sync-onceRun continuously:
python3 -u src/spotify_bridge.py watch --interval 30If the current track is paused and you still want to sync it:
python3 -u src/spotify_bridge.py sync-once --include-pausedForce re-saving the current track:
python3 -u src/spotify_bridge.py sync-once --forceRemove a bad local Spotify-to-Telegram mapping:
python3 src/telegram_cache.py unlink \
--spotify-track-id "spotify:track:..."Runtime files are intentionally ignored by Git:
.spotify_token.json.telegram_preview_cache.session.bridge_state.jsoncache_db.jsonpreviews/
cache_db.json maps Spotify track IDs to Telegram uploaded audio documents. It may contain private channel IDs and should stay local.
iTunes preview matching is heuristic. The matcher heavily penalizes artist mismatches so tracks with the same title but different artists are not silently accepted. If no safe match exists, the sync returns itunes_preview_failed.
This is an unofficial personal automation project. It is not affiliated with Spotify, Apple, Telegram, or any rightsholder.
The project does not download music from Spotify. It uses Spotify only for currently-playing metadata. Apple iTunes previews are short preview clips fetched locally by the user when available. Do not redistribute downloaded preview files.
Review and follow:
- Spotify Developer Policy: https://developer.spotify.com/policy
- Apple iTunes Search API documentation: https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/iTuneSearchAPI/
- Telegram API documentation: https://core.telegram.org/api
MIT. See LICENSE.
