animebot / README.md
luci18's picture
Upload folder using huggingface_hub
e4ccb70 verified
|
Raw History Blame Contribute Delete
10.9 kB
---
title: Anime Encoder Bot
emoji: 🎬
colorFrom: blue
colorTo: purple
sdk: docker
app_port: 5000
pinned: false
---
# Anime Encoder Bot 🎬
A hybrid Telegram bot that combines **anime downloading** (via animdl) with **advanced video encoding** (via FFmpeg). Download anime episodes and encode them with H.264/H.265, custom quality settings, audio controls, and more!
## Features
### 🎬 Anime Downloading
- πŸ” **Multi-site search** - Search across all anime sites at once
- 🌐 **8+ supported sites** - GogoAnime, 9Anime, AnimePahe, Zoro, AnimixPlay, AllAnime, Nyaa, etc.
- πŸ“₯ Download specific episodes
- πŸ“₯ Direct URL downloads (yt-dlp)
- πŸ’Ύ MongoDB caching for fast re-access
- πŸ“Š Download progress tracking
- ⏳ Download queue management
- πŸ” Site-specific search - Filter by preferred source
### 🎞️ Video Encoding
- πŸŽ₯ Codecs: H.264 (libx264), H.265/HEVC (libx265)
- πŸ“Š Quality control: CRF 16-35
- ⚑ Speed presets: ultrafast to veryslow
- πŸ“ Resolution scaling: 1080p, 720p, 540p, 480p, 360p
- πŸ”Š Audio: AAC, AC3, OPUS, MP3 with bitrate control
- πŸ“ Subtitle support
- 10-bit HEVC encoding
### πŸ“ Smart Renaming with Metadata
- 🏷️ **Auto-rename** downloads and encodes
- πŸ“‹ **Pattern templates**: `{title}`, `{episode}`, `{quality}`, `{codec}`, etc.
- 🎨 **Preset patterns**: Simple, Detailed, Anime-style, With codec info
- πŸ”§ **Custom patterns**: Create your own naming scheme
- πŸ“Š **Metadata extraction**: Resolution, codec, duration from video files
### πŸ–ΌοΈ Thumbnail Generation (Customizable)
- 🎬 Auto-generate thumbnails from any video
- πŸ“Έ **Custom position** - Start (10%), Middle (50%), End (90%), etc.
- πŸ“ **User-defined resolution** - 1080p, 720p, 480p, 360p
- οΏ½ **Custom caption template** - `{filename}`, `{resolution}`, `{position}`
- πŸ“Έ **Format choice** - JPG or PNG
- πŸ–ΌοΈ Generated thumbnails sent with encoded videos
### πŸ“Š Statistics & Leaderboard
- πŸ“ˆ **User Stats** - Personal download/encode history via `/mystats`
- πŸ† **Leaderboard** - Top users by activity (all time, weekly, monthly)
- πŸ“‰ **Success Rates** - Track completion rates
- πŸ” **Favorite Anime** - Most downloaded series per user
### 🌐 Web Admin Panel
- πŸ”’ Secure login with password protection
- πŸ“Š **Dashboard** - Real-time bot statistics
- πŸ‘₯ **User Management** - View all users and their activity
- πŸ“‹ **Task Monitoring** - Track downloads and encodes
- βš™οΈ **Settings Control** - Adjust bot configuration
- πŸ† **Leaderboard View** - See top users
### 🎞️ Batch Operations
- πŸ“¦ **Batch Encode** - Queue multiple videos at once
- πŸ“₯ **Batch Download** - Download entire seasons
### βš™οΈ User Features
- πŸ”§ Per-user encoding settings
- πŸ“Š Queue status monitoring
- πŸ”„ Download + Auto-encode workflow
## Requirements
- Python 3.9+
- MongoDB (local or remote)
- FFmpeg + FFprobe
- animdl (`pip install animdl`)
- Telegram API credentials
## Installation
### 1. Clone Repository
```bash
git clone https://github.com/yourusername/anime-encoder-bot.git
cd anime-encoder-bot
```
### 2. Install Dependencies
```bash
pip install -r requirements.txt
pip install animdl # Must be installed separately
```
### 3. Install FFmpeg
**Ubuntu/Debian:**
```bash
sudo apt-get update
sudo apt-get install ffmpeg
```
**macOS:**
```bash
brew install ffmpeg
```
**Windows:** Download from [FFmpeg website](https://ffmpeg.org/download.html) and add to PATH.
### 4. Setup MongoDB
**Local:**
```bash
# Ubuntu/Debian
sudo apt-get install mongodb
sudo systemctl start mongod
# macOS
brew install mongodb-community
brew services start mongodb-community
# Docker
docker run -d -p 27017:27017 --name mongodb mongo:latest
```
**MongoDB Atlas:** Use connection string in `.env`
### 5. Configure Bot
Copy `.env.example` to `.env` and fill in your values:
```bash
cp .env.example .env
```
Edit `.env`:
```env
# Telegram API credentials - Get from https://my.telegram.org
API_ID=your_api_id
API_HASH=your_api_hash
BOT_TOKEN=your_bot_token_from_botfather
# Owner settings
OWNER_ID=your_telegram_user_id
# MongoDB
MONGO_URI=mongodb://localhost:27017/anime_encoder_bot
# Optional: Log channel
LOG_CHANNEL=-1001234567890
```
### 6. Run Bot
```bash
python -m bot.main
```
## Commands
| Command | Description |
|---------|-------------|
| `/start` | Start the bot with menu buttons |
| `/help` | Show help |
| `/sites` | List available anime sites |
| `/anime <query>` | Search all anime sites |
| `/anime <query> <site>` | Search specific site (e.g., `/anime naruto gogoanime`) |
| `/download <url> <ep>` | Download specific episode |
| `/ddl <url>` | Download from direct URL |
| `/encode` | Reply to a video to encode it |
| `/batchencode` | Reply to multiple videos to batch encode |
| `/thumb` | Reply to a video to generate thumbnail |
| `/settings` | Configure encoding & rename preferences |
| `/status` | View queue status |
| `/mystats` | View your personal statistics |
| `/stats` | Admin statistics |
## Button Interface
The bot features an intuitive **button-based interface**:
### Main Menu (via `/start`)
- πŸ” **Search Anime** - Opens search options
- 🌐 **Sites** - Lists all available anime sites
- βš™οΈ **Settings** - Configure encoding preferences
- πŸ“Š **Status** - View queue status
- ❓ **Help** - Show commands
### Search Options
- πŸ” **Search All Sites** - Search across all anime sites
- 🎯 **Search Specific Site** - Choose a site to search
### Episode Selection
- Episode buttons (1-25 shown at a time)
- πŸ“₯ **Download All** - Queue all episodes at once (limit 50)
- **Range buttons** - For series with >25 episodes (e.g., "Ep 26-50")
- ⬅️ **Previous** / ➑️ **Next** - Navigate episode ranges
### Site Filter Buttons
When searching all sites, results show filter buttons to narrow down by specific sites.
### Settings - Renaming (βš™οΈ β†’ πŸ“ Rename Pattern)
- πŸ“‹ **Pattern Presets** - Simple, Detailed, With Codec, With Site, Anime Style, Minimal
- πŸ”„ **Toggle Auto Rename** - Enable/disable automatic renaming
- ✏️ **Custom Pattern** - Create your own naming scheme
- πŸ“– **Pattern Help** - View all available variables
### Settings - Thumbnails (βš™οΈ β†’ πŸ–ΌοΈ Thumbnail Settings)
- πŸ“ **Resolution** - 1080p, 720p, 480p, 360p
- πŸ“ **Position** - Where to capture in the video (10%, 25%, 50%, 75%)
- πŸ“Έ **Format** - JPG or PNG
- πŸ’¬ **Caption Template** - Customize the thumbnail caption
### Thumbnail Caption Variables
| Variable | Description |
|----------|-------------|
| `{filename}` | Original video filename |
| `{resolution}` | Thumbnail resolution |
| `{position}` | Timestamp position (e.g., 25%) |
## Supported Sites
- **GogoAnime** - `gogoanime` (most reliable)
- **9Anime** - `9anime`
- **AnimePahe** - `animepahe`
- **Zoro.to** - `zoro`
- **AnimixPlay** - `animixplay`
- **AllAnime** - `allanime`
- **Nyaa.si** - `nyaa` (torrents)
- **Crunchyroll** - `crunchyroll` (requires auth)
## Encoding Settings
Users can customize their encoding preferences:
- **Codec**: libx264 (H.264) or libx265 (H.265/HEVC)
- **CRF**: 16-35 (lower = better quality)
- **Preset**: ultrafast to veryslow (encoding speed)
- **Resolution**: Scale to 1080p/720p/540p/480p/360p or keep original
- **Audio Codec**: AAC, AC3, OPUS, MP3
- **Audio Bitrate**: 96k-320k
## Renaming Patterns
Configure automatic file renaming in `/settings` β†’ `πŸ“ Rename Pattern`:
### Available Variables
| Variable | Description |
|----------|-------------|
| `{title}` | Anime title |
| `{episode}` | Episode number (02, 03, etc.) |
| `{season}` | Season number |
| `{quality}` | Video resolution (1920x1080) |
| `{codec}` | Video codec (H.264, HEVC) |
| `{audio_codec}` | Audio codec (AAC, AC3) |
| `{duration}` | Video duration |
| `{source_site}` | Download source site |
### Pattern Presets
- **simple**: `{title} - Ep{episode}`
- **detailed**: `{title} - S{season}E{episode} [{quality}]`
- **with_codec**: `{title} - Ep{episode} [{quality}] [{codec}]`
- **with_site**: `[{source_site}] {title} - Ep{episode} [{quality}]`
- **anime_style**: `[{studio}] {title} - {episode} [{quality}]`
### Example Output
Pattern: `{title} - Episode {episode} [{quality}]`
Result: `Attack on Titan - Episode 05 [1920x1080].mp4`
## Web Admin Panel
The bot includes a web-based admin panel for easy management.
### Running the Panel
```bash
python web_panel.py
```
Access at `http://localhost:5000`
### Default Login
- **Username**: `admin`
- **Password**: `admin` (⚠️ change in production!)
### Panel Features
- πŸ“Š **Dashboard** - Real-time bot statistics, queue status, popular anime
- πŸ‘₯ **Users** - View all users and their download/encode stats
- πŸ“‹ **Tasks** - Monitor recent downloads and encodes
- πŸ† **Leaderboard** - View top users by activity (all time/weekly/monthly)
- βš™οΈ **Settings** - View and manage bot configuration
### Environment Variables
```env
ADMIN_USERNAME=admin
ADMIN_PASSWORD_HASH=<bcrypt_hash>
FLASK_SECRET_KEY=your-secret-key
```
## Architecture
```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Telegram β”‚
β”‚ User β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜
β”‚
β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Bot Client │────▢│ Task Queue │────▢│ MongoDB β”‚
β”‚ (Pyrogram) β”‚ β”‚ β”‚ β”‚ (Queue DB) β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Workers β”‚ β”‚ FFmpeg β”‚
β”‚ - Download │────▢│ Encoder β”‚
β”‚ - Encode β”‚ β”‚ β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚
β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ animdl / β”‚
β”‚ yt-dlp β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
```
## Troubleshooting
**Bot won't start:**
- Check `.env` has all required values
- Verify MongoDB is running
- Ensure FFmpeg is installed and in PATH
**Downloads fail:**
- Check animdl installation: `animdl --version`
- Verify source site is accessible
- Check download directory permissions
**Encoding fails:**
- Verify FFmpeg installation: `ffmpeg -version`
- Check encode directory permissions
- Review `bot.log` for errors
## License
MIT License
## Credits
- [animdl](https://github.com/justfoolingaround/animdl) - Anime downloader
- [Pyrogram](https://pyrogram.org) - Telegram MTProto client
- [FFmpeg](https://ffmpeg.org) - Video encoding
- [yt-dlp](https://github.com/yt-dlp/yt-dlp) - Direct URL downloader