Skip to content

murodovdev/Spotify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

70 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎧 TrackFlow

A fast, multi-source music bot for Telegram.

Send a Spotify, YouTube, or social-media link β€” or just type a song name β€” and TrackFlow finds the best audio, tags it, and delivers it in seconds.

Python aiogram Deploy on Railway License: MIT


Overview

TrackFlow is a self-hostable Telegram bot that turns links and search queries into high-quality, fully-tagged audio files. It reads metadata from Spotify, finds the closest matching source on YouTube (the same approach as spotdl), downloads and transcodes it with yt-dlp + FFmpeg, and caches the result so the next request for the same track is instant.

It also recognizes music from voice/video clips, downloads audio from YouTube and social-media video links, and ships with a full admin control panel.

Note

Spotify does not serve audio directly. TrackFlow uses Spotify only for metadata (title, artist, album, cover, duration) and sources the audio from YouTube Music. Intended for personal use β€” respect the copyright laws in your jurisdiction.

Features

  • πŸ”— Link detection β€” paste a Spotify track, album, playlist, or artist link and TrackFlow resolves it automatically.
  • πŸ” Text search β€” type a song name; the search engine finds and returns the best match.
  • ▢️ YouTube & video links β€” extract audio from YouTube, or download videos from popular social platforms.
  • 🎀 Music recognition β€” forward a voice note, audio, or video clip and TrackFlow identifies the track (Shazam-powered).
  • ❀️ Liked Songs β€” connect your Spotify account via OAuth and bulk-download your library.
  • ⭐ Favorites, history & playlists β€” personal library management inside the chat.
  • ⚑ Instant cache β€” Telegram file_id caching means a previously downloaded track is re-sent in about a second.
  • πŸš€ Parallel downloads β€” albums and playlists are processed several tracks at a time.
  • 🏷 Full metadata β€” ID3 tags, embedded cover art, and duration on every file.
  • 🎚 Quality control β€” choose 128 / 320 kbps, apply audio effects, and edit metadata.
  • 🎯 Recommendations β€” a "similar songs" engine built on ListenBrainz, Deezer, local audio analysis, and (optionally) Last.fm.
  • 🌍 Multi-language β€” Uzbek, English, and Russian UI.
  • πŸ›‘ Admin panel β€” roles, bans, broadcasts, maintenance mode, live logs, and usage dashboards.

Supported platforms

Source Capability
Spotify Track / album / playlist / artist links, text search, Liked Songs (OAuth)
YouTube / YouTube Music Audio extraction from links, primary audio source for search
Social video platforms Video download + "Find Music" recognition
Local media Recognize audio/voice/video clips sent to the bot

Tech stack

Layer Technology
Language Python 3.12 (asyncio, uvloop on Linux)
Bot framework aiogram 3
Web / OAuth server aiohttp
Media yt-dlp + FFmpeg, mutagen
Storage SQLite via aiosqlite
Config pydantic-settings
Security cryptography (Fernet token encryption)
Recognition shazamio
Analysis NumPy (audio feature extraction)
Deployment Docker, Railway

Quick start (local)

Prerequisites: Python 3.12+, FFmpeg, and a Telegram bot token from @BotFather.

# 1. Install FFmpeg
#    Windows:  winget install ffmpeg
#    macOS:    brew install ffmpeg
#    Debian:   sudo apt install ffmpeg

# 2. Clone and enter the project
git clone https://github.com/murodovdev/Spotify.git trackflow
cd trackflow

# 3. Create a virtual environment and install dependencies
python -m venv .venv
source .venv/bin/activate        # Windows: .venv\Scripts\activate
pip install -r requirements.txt

# 4. Configure environment
cp .env.example .env             # Windows: copy .env.example .env
#    Edit .env and set BOT_TOKEN (Spotify keys are optional β€” see below)

# 5. Run
python -m bot.main

The bot starts polling immediately and launches a local OAuth server on http://127.0.0.1:8080 (used only for the Spotify "Connect account" flow).

Environment variables

Only BOT_TOKEN is required. Spotify credentials unlock link resolution and Liked Songs; without them the bot automatically falls back to embed mode (metadata from public open.spotify.com/embed pages, YouTube-based search).

Variable Required Description
BOT_TOKEN βœ… Telegram bot token from @BotFather.
SPOTIFY_CLIENT_ID Spotify app client ID (enables full API + Liked Songs).
SPOTIFY_CLIENT_SECRET Spotify app client secret.
SPOTIFY_REDIRECT_URI OAuth callback. Auto-derived if left blank.
ADMIN_ID Telegram user ID granted owner/admin access.
ENCRYPTION_KEY Fernet key for encrypting stored tokens. Derived from BOT_TOKEN if blank.
DB_PATH SQLite path. Auto: /data/bot.db on Railway, data/bot.db locally.
PORT OAuth web server port (default 8080).
MAX_DOWNLOADS Max concurrent downloads (default 4).
LASTFM_API_KEY Optional β€” strengthens the recommendation engine.
YOUTUBE_COOKIES / _B64 / _FILE Optional YouTube cookies to bypass bot checks. See Configuration.

See docs/CONFIGURATION.md for the full reference, including how to obtain Spotify credentials and export YouTube cookies.

Deployment

TrackFlow is built to run on Railway with a persistent volume and zero extra infrastructure. A one-page walkthrough β€” including the critical volume setup that keeps user data across redeploys β€” is in docs/DEPLOYMENT.md.

# Container build works anywhere Docker runs:
docker build -t trackflow .
docker run --env-file .env -p 8080:8080 -v "$(pwd)/data:/data" trackflow

Bot commands

Command Description
/start Main menu
/liked Download your Spotify Liked Songs
/favorites Your saved favorites
/settings Quality (128 / 320 kbps) and language
/help Usage help
/admin Admin control panel (authorized users only)

Architecture

bot/
β”œβ”€β”€ main.py            # Entry point: polling loop + OAuth web server + lifecycle
β”œβ”€β”€ config.py          # Environment-based settings (pydantic)
β”œβ”€β”€ i18n.py            # Localized strings (UZ / EN / RU)
β”œβ”€β”€ keyboards.py       # Inline keyboards
β”œβ”€β”€ security.py        # Token encryption helpers
β”œβ”€β”€ handlers/          # Telegram update handlers (links, search, library, video, …)
β”œβ”€β”€ services/          # Core logic
β”‚   β”œβ”€β”€ spotify.py     #   Async Spotify Web API client (metadata, OAuth, Liked)
β”‚   β”œβ”€β”€ search_engine.py #  Query β†’ best-match resolution
β”‚   β”œβ”€β”€ matcher.py     #   Pick the closest YouTube source for a track
β”‚   β”œβ”€β”€ downloader.py  #   yt-dlp β†’ MP3 β†’ ID3 tags + cover art
β”‚   β”œβ”€β”€ queue.py       #   Caching, parallel downloads, progress, cancellation
β”‚   β”œβ”€β”€ recognizer.py  #   Shazam-based music recognition
β”‚   β”œβ”€β”€ recommender.py #   "Similar songs" engine
β”‚   β”œβ”€β”€ video_dl.py    #   Social-media video downloads
β”‚   └── audio_*.py     #   Effects and analysis
β”œβ”€β”€ db/                # SQLite layer (users, file_id cache, history, tokens)
β”œβ”€β”€ admin/             # Admin control panel (roles, bans, broadcast, dashboard)
└── web/oauth.py       # Spotify OAuth callback + /health endpoint

For a deeper tour of the request lifecycle and data flow, see docs/ARCHITECTURE.md.

Contributing

Contributions are welcome. Please read CONTRIBUTING.md for the development setup, coding style, and pull-request workflow.

License

Released under the MIT License.

About

🎧 Fast multi-source music bot for Telegram β€” Spotify/YouTube links & text search β†’ tagged audio in seconds. Recognition, playlists, favorites, instant caching.

Topics

Resources

License

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Contributors