An asynchronous, high-performance Telegram music bot built with Kurigram (Pyrogram fork), Yandex.Music API, and ShazamIO.
💼 Case Study: This project represents a complete architectural refactoring and feature overhaul of a high-load music bot for a client. Originally suffering from blocking calls and frequent crashes, the codebase was rewritten from scratch into a modular, asynchronous architecture.
- 🔎 Music Search: Fast track and artist search via Yandex.Music API.
- 🎧 Audio Streaming & Downloading: High-quality MP3 downloads directly in Telegram.
- 🌊 Personal Wave ("Моя волна"): Smart recommendation engine generating personalized track lists based on user listening history and favorites.
- 🏆 Charts & New Releases: Instant access to global top charts and fresh album releases.
- 🎙️ Shazam Music Recognition: Send any video file (up to 20MB) to extract the audio stream via
FFmpegand recognize the song title using Shazam. - ⭐️ Telegram Stars Payments: Automated Premium subscription purchase workflow using native Telegram Stars (
XTR). - 👥 Referral System: Users earn extra Premium days by inviting friends via unique referral links with CAPTCHA verification.
- 📊 Live Analytics: Track total users, active Premium subscribers, total plays, and pending payments.
- 📢 Broadcast Engine: Flexible broadcast messaging tool with support for media, text formatting, and custom URL inline buttons.
- 💎 Manual Subscription Management: Grant or extend Premium access to specific users by ID or
@username. - 🔴/🟢 Bot Maintenance Mode: Emergency global kill-switch to pause service for non-admin users.
- Asynchronous I/O Pipeline: Eliminated blocking operations by converting all database, filesystem, and external API requests to native
async/await. - Database Optimization (SQLite + WAL): Built on
aiosqliteutilizing Write-Ahead Logging (WAL) mode, transaction blocks, and foreign key constraints for safe multi-thread reads. - Dual-Tier Caching System:
- User Data & FSM: Low-latency persistent Key-Value storage via
diskcache(AsyncDiskCachewrapper) ensuring instant state lookups without DB queries. - Media Caching: Automatic
file_idcaching for interface animations and static assets to save server bandwidth.
- User Data & FSM: Low-latency persistent Key-Value storage via
- Middleware Protection: Custom anti-spam throttling middleware with configurable rate limits.
YandexMusicBot/
├── background/ # Background workers (subscription expiration checkers)
├── data/
│ ├── database/ # SQLite connection wrapper, schema, and queries
│ ├── cache_manager.py# AsyncDiskCache engine and UserData models
│ └── config.py # App configuration and environment loader
├── handlers/ # Modular event handlers (admin, music, payment, common)
├── middlewares/ # Anti-spam throttling & Maintenance status gates
├── services/ # External APIs (Yandex.Music, ShazamIO, Youtube)
├── ui/ # Keyboards and UI templates
├── utils/ # CAPTCHA generator and media senders
├── create_database.py # DB table schemas and indexes generator
├── main.py # App entry point
├── .env.example
└── requirements.txt
-
Clone the repository:
git clone https://github.com/cxvimba/YandexMusicBot.git cd YandexMusicBot -
Set up virtual environment:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate pip install -r requirements.txt
-
Configure Environment: Copy
.env.exampleto.envand insert your credentials:cp .env.example .env
-
Initialize Database:
python create_database.py
-
Run the bot:
python main.py
"I ran into a serious issue: my bot was under heavy load and kept failing. Since I knew @Im_DMAR worked in software development, I asked for his help. He refactored the legacy code entirely, built an anti-spam system, and added numerous new features. I recommend him to everyone — a highly experienced programmer who knows what he is doing!"
— Michael (SoundPlus Owner)
