Skip to content
This repository was archived by the owner on Feb 27, 2026. It is now read-only.

iytdl/iytdl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

49 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

iYTDL Logo

iYTDL

Async Inline YouTube-DL for Pyrogram-based Telegram Bots

PyPI Version Downloads CI License: GPLv3 Code Style: Black Python 3.8+

A production-ready Python library that wraps yt-dlp with an async, inline-friendly interface for Pyrogram Telegram bots β€” search, download, and upload media from 1000+ sites directly inside Telegram.


Highlights

Feature Details
⚑ Fully Async Built on asyncio, aiohttp, and aiosqlite β€” non-blocking from search to upload
πŸ—ƒοΈ Smart Caching SHA-1 hashed SQLite cache eliminates duplicate downloads and speeds up repeat queries
🌐 1000+ Sites Powered by yt-dlp β€” YouTube, Dailymotion, Vimeo, SoundCloud, Twitter, and many more
πŸŽ›οΈ Quality Selector Inline buttons let users pick video resolution (144p β†’ 1440p) or audio bitrate (128–320 kbps)
πŸ“€ Telegram Upload Uploads audio/video to Telegram with real-time progress bars, metadata, and thumbnails
πŸ”Œ External Downloader Optional Aria2c integration for faster, resumable downloads
πŸ–ΌοΈ Thumbnails Auto-fetches best thumbnail, uploads to Telegraph, and embeds album art for audio
🧹 Context Manager async with iYTDL(...) as ytdl: β€” clean resource management out of the box

Architecture

src/iytdl/
β”œβ”€β”€ main.py             # iYTDL β€” primary class (inherits Extractor + Downloader + Uploader)
β”œβ”€β”€ extractors.py       # yt-dlp format extraction & inline button generation
β”œβ”€β”€ downloader.py       # async video/audio downloading with progress hooks
β”œβ”€β”€ upload_lib/
β”‚   β”œβ”€β”€ uploader.py     # Telegram upload with progress tracking
β”‚   β”œβ”€β”€ progress.py     # upload progress bar renderer
β”‚   └── functions.py    # media metadata helpers (ffprobe, thumbnails)
β”œβ”€β”€ sql_cache.py        # aiosqlite-backed search/URL cache
β”œβ”€β”€ formatter.py        # search result β†’ Telegram message formatter
β”œβ”€β”€ processes.py        # cancellable download/upload process manager
β”œβ”€β”€ types/              # SearchResult, ExternalDownloader, Aria2c dataclasses
β”œβ”€β”€ constants.py        # URLs, regex patterns
β”œβ”€β”€ exceptions.py       # NoResultFoundError, DownloadFailedError
└── utils.py            # run_sync, humanbytes, time_formater, telegraph upload

Quick Start

Installation

pip install iytdl

Minimal Example

from iytdl import iYTDL

async def main():
    async with iYTDL(log_group_id=LOG_GROUP_ID, cache_path="cache") as ytdl:

        # πŸ” Search YouTube
        result = await ytdl.search("never gonna give you up")
        print(result.msg)

        # πŸ”— Parse any supported URL
        result = await ytdl.parse("https://www.youtube.com/watch?v=dQw4w9WgXcQ")

        # ⬇️ Download video
        key = await ytdl.download(
            url="https://www.youtube.com/watch?v=dQw4w9WgXcQ",
            uid="mp4",
            downtype="video",
            update=message,  # Pyrogram Message or CallbackQuery
        )

        # πŸ“€ Upload to Telegram
        await ytdl.upload(client, key, "video", message)

API Reference

iYTDL β€” Main Class

iYTDL(
    log_group_id: Union[int, str],          # Telegram chat ID for uploading media
    session: Optional[ClientSession],        # aiohttp session (auto-created if None)
    silent: bool = False,                    # suppress yt-dlp stdout
    download_path: str = "downloads",        # local download directory
    cache_path: str = "",                    # SQLite cache directory
    delete_media: bool = False,              # auto-cleanup after upload
    external_downloader: Optional[ExternalDownloader] = None,  # e.g. Aria2c(...)
    ffmpeg_location: str = "ffmpeg",         # custom ffmpeg path
)

Core Methods

Method Description
search(query) Search YouTube, returns paginated SearchResult with inline buttons
parse(search_query, extract=True) Auto-detect: YouTube URL β†’ extract, generic URL β†’ extract, text β†’ search
next_result(key, index) Navigate cached search results (pagination)
extract_info_from_key(key) Get download buttons for a cached URL/video ID
download(url, uid, downtype, update) Download media with live progress bar in Telegram
upload(client, key, downtype, update) Upload downloaded media to Telegram with progress
get_download_button(yt_id) Generate quality-selection inline keyboard for a YouTube video
listview(key) Grid view of all cached search results
paste_to_tg(title, content) Paste content to Telegraph
get_ytthumb(yt_id) Fetch best available YouTube thumbnail

Callback Patterns (for CallbackQueryHandler)

# Pagination (Back / Next)
r"^yt_(back|next)\|(?P<key>[\w-]{5,11})\|(?P<pg>\d+)$"

# List all results
r"^yt_listall\|(?P<key>[\w-]{5,11})$"

# Extract info
r"^yt_extract_info\|(?P<key>[\w-]{5,11})$"

# Download (generic + YouTube)
r"yt_(?P<mode>gen|dl)\|(?P<key>[\w-]+)\|(?P<choice>[\w-]+)\|(?P<dl_type>a|v)$"

# Cancel download/upload
r"^yt_cancel\|(?P<process_id>[\w\.]+)$"

External Downloader (Aria2c)

from iytdl.types.external_downloader import Aria2c

async with iYTDL(
    log_group_id=LOG_GROUP_ID,
    external_downloader=Aria2c(executable_path="/usr/bin/aria2c"),
    cache_path="cache",
) as ytdl:
    ...

Requirements

Dependency Purpose
Python β‰₯ 3.8 Runtime
yt-dlp Media extraction & download engine
Pyrogram Telegram Bot framework
FFmpeg Audio/video post-processing
Aria2c (optional) External download accelerator

Development

git clone https://github.com/iytdl/iytdl.git
cd iytdl
poetry install

Run tests:

pytest tests/

Pre-commit hooks:

pre-commit install

Build wheel:

chmod +x scripts/install.sh && ./scripts/install.sh

Screenshots

Live Demo Bot: @iytdl_bot


πŸ“Š Download Stats

View Download Stats Dashboard

Total Downloads Monthly Downloads Weekly Downloads


Real-World Usage

YouTube.py β€” Full bot module built with iYTDL


Tech Stack


License

This project is licensed under the GNU General Public License v3.0.


Built with ❀️ by Himanshu

About

A production-ready Python library that wraps yt-dlp with an async, inline-friendly interface for Pyrogram Telegram bots

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Contributors