Overview
Themedia_types package handles downloading, processing, and sending media to users. It provides unified interfaces for videos, images (slideshows), and music with support for different delivery modes and storage.
Core Modules
send_video.py
Handles video delivery to Telegram.send_video_result()
Location: media_types/send_video.py:11
Sends TikTok videos to users or inline messages.
targed_id- Chat ID (int) or inline message ID (str)video_info- VideoInfo object with video data and metadatalang- User’s language codefile_mode- If True, send as document; if False, send as videoinline_message- If True, edit inline message (requires storage upload)reply_to_message_id- Message ID to reply touser_id,username,full_name- User info for storage caption
- Automatic thumbnail generation (videos > 60s in normal mode, > 30s in inline)
- File mode vs. media mode
- Inline message editing via storage channel
- Music button attachment
- Streaming support
send_music.py
Extracts and sends TikTok audio tracks.send_music_result()
Location: media_types/send_music.py:9
Sends music/audio extracted from TikTok videos.
query_msg- Message to reply tomusic_info- MusicInfo object with audio data and metadatalang- User’s language codegroup_chat- If True, disables notification
- Downloads cover art as thumbnail
- Sets audio metadata (title, performer, duration)
- Supports both direct bytes and URL downloads
- Silent notifications in group chats
send_images.py
Processes and sends TikTok slideshows (image carousels).send_image_result()
Location: media_types/send_images.py:42
Downloads, processes, and sends slideshow images.
user_msg- Message to reply tovideo_info- VideoInfo object with image URLslang- User’s language codefile_mode- If True, send as documents; if False, send as photosimage_limit- Max images to send (None for all, 10 for groups)client- TikTokClient instance for downloading
bool- True if images were converted/processed, False otherwise
- Parallel image downloads
- Automatic format conversion (HEIC/WEBP → JPEG)
- Batching (10 images per media group)
- Processing status message
- Retry with proxy rotation
- Music button attachment
download_images_parallel()
Location: media_types/send_images.py:31
Downloads multiple images concurrently.
storage.py
Manages media storage channel for inline message editing.Why Storage Channel?
Telegram requiresfile_id to edit inline messages - you cannot upload new files directly. The storage channel receives uploads and provides file IDs for inline edits.
upload_video_to_storage()
Location: media_types/storage.py:64
file_id string or None if upload fails
upload_photo_to_storage()
Location: media_types/storage.py:33
image_processing.py
Image format detection and conversion utilities.Key Constants
detect_image_format()
Detects image format from bytes (magic number detection).
convert_image_to_jpeg_optimized()
Converts non-native formats to JPEG with optimization.
ensure_native_format()
Ensures image is in Telegram-supported format.
ui.py
UI components for media messages.music_button()
Location: media_types/ui.py:7
Creates inline button to extract music.
result_caption()
Location: media_types/ui.py:13
Generates caption for sent media.
errors.py
Centralized error message handling.get_error_message()
Location: media_types/errors.py:29
Maps exceptions to localized error messages.
register_error_mapping()
Location: media_types/errors.py:25
Registers custom error mappings.
Media Delivery Flow
Video Delivery
Slideshow Delivery
Music Delivery
File Mode vs. Media Mode
File Mode (file_mode=True):
- Sends as document
- Preserves original quality
- No compression
- Larger file sizes
file_mode=False):
- Sends as video/photo
- Telegram compression applied
- Smaller file sizes
- Streaming support for videos
Best Practices
- Always close VideoInfo after processing slideshows
- Use storage channel for inline message edits
- Limit images to 10 in group chats
- Convert non-native formats in photo mode
- Add delays between media group batches
- Handle download failures gracefully
- Generate thumbnails for long videos
- Use music buttons for video results

