# damantha126/youtube-dl-bot architecture

> Architecture diagram of the GitHub repository damantha126/youtube-dl-bot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/damantha126/youtube-dl-bot
- Repository: https://github.com/damantha126/youtube-dl-bot

## Overview

This is a Telegram bot for fetching YouTube media and offering downloadable audio or video formats. The main workflow accepts a YouTube URL, fetches its metadata and available formats, presents choices, downloads the selected media, and sends it back to the chat. Separate command handlers provide start and help responses; configuration supplies Telegram credentials and the request interval. The graph follows the sampled handlers and helpers. Plugin registration is visible in the entry point, but internal Pyrogram dispatch and the external service interactions are not fully shown.

Main entry points: [`plugins/youtube.py`](https://github.com/damantha126/youtube-dl-bot/blob/main/plugins/youtube.py) (YouTube URL handler), [`bot/__main__.py`](https://github.com/damantha126/youtube-dl-bot/blob/main/bot/__main__.py) (Bot entry point), [`plugins/youtube_callback_data.py`](https://github.com/damantha126/youtube-dl-bot/blob/main/plugins/youtube_callback_data.py) (Download callback handler), [`plugins/start.py`](https://github.com/damantha126/youtube-dl-bot/blob/main/plugins/start.py) (Start command)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Bot runtime"]
  node_entry["Bot entry point<br/>[__main__.py]"]
  node_config["Bot configuration<br/>[config.py]"]
  node_user_state[("User timing state<br/>[__init__.py]")]
end

subgraph group_interaction["Telegram interaction"]
  node_start["Start command<br/>[start.py]"]
  node_help["Help command<br/>[help.py]"]
  node_youtube_request["YouTube URL handler<br/>[youtube.py]"]
  node_callback_choice["Format choice handler"]
  node_callback_download["Download callback handler"]
  node_media_send["Media reply"]
end

subgraph group_media["Media processing"]
  node_youtube_info["Format and metadata lookup<br/>[ytdlfunc.py]"]
  node_download_cli["Media downloader<br/>[ytdlfunc.py]"]
  node_ffmpeg_probe["Media duration probe<br/>[ffmfunc.py]"]
  node_downloads[("Downloaded media and thumbnails")]
end

subgraph group_support["Shared support"]
  node_humanbytes["File size formatter<br/>[util.py]"]
end

node_user(("Telegram user"))
node_telegram["Telegram platform"]

node_entry -->|"loads credentials"| node_config
node_entry -->|"registers plugins"| node_start
node_entry -->|"registers plugins"| node_help
node_entry -->|"registers plugins"| node_youtube_request
node_entry -->|"registers plugins"| node_callback_choice
node_entry -->|"registers plugins"| node_callback_download
node_user -.->|"sends requests"| node_telegram
node_telegram -.->|"dispatches command"| node_start
node_telegram -.->|"dispatches command"| node_help
node_telegram -.->|"dispatches URL"| node_youtube_request
node_youtube_request -->|"reads and updates"| node_user_state
node_youtube_request -->|"reads interval"| node_config
node_youtube_request -->|"fetches formats"| node_youtube_info
node_youtube_request -->|"replies with choices"| node_telegram
node_youtube_info -->|"formats sizes"| node_humanbytes
node_telegram -.->|"dispatches selection"| node_callback_choice
node_callback_choice -->|"updates choices"| node_telegram
node_telegram -.->|"dispatches download choice"| node_callback_download
node_callback_download -->|"downloads selected media"| node_download_cli
node_callback_download -->|"gets video duration"| node_ffmpeg_probe
node_youtube_request -->|"writes thumbnail"| node_downloads
node_callback_download -->|"reads thumbnail and saves media"| node_downloads
node_callback_download -->|"schedules media reply"| node_media_send
node_media_send -->|"sends media"| node_telegram
node_start -->|"sends welcome"| node_telegram
node_help -->|"sends instructions"| node_telegram

click node_entry "https://github.com/damantha126/youtube-dl-bot/blob/main/bot/__main__.py"
click node_config "https://github.com/damantha126/youtube-dl-bot/blob/main/config.py"
click node_user_state "https://github.com/damantha126/youtube-dl-bot/blob/main/bot/__init__.py"
click node_start "https://github.com/damantha126/youtube-dl-bot/blob/main/plugins/start.py"
click node_help "https://github.com/damantha126/youtube-dl-bot/blob/main/plugins/help.py"
click node_youtube_request "https://github.com/damantha126/youtube-dl-bot/blob/main/plugins/youtube.py"
click node_callback_choice "https://github.com/damantha126/youtube-dl-bot/blob/main/plugins/youtube_callback_data.py"
click node_callback_download "https://github.com/damantha126/youtube-dl-bot/blob/main/plugins/youtube_callback_data.py"
click node_media_send "https://github.com/damantha126/youtube-dl-bot/blob/main/plugins/youtube_callback_data.py"
click node_youtube_info "https://github.com/damantha126/youtube-dl-bot/blob/main/helper/ytdlfunc.py"
click node_download_cli "https://github.com/damantha126/youtube-dl-bot/blob/main/helper/ytdlfunc.py"
click node_ffmpeg_probe "https://github.com/damantha126/youtube-dl-bot/blob/main/helper/ffmfunc.py"
click node_downloads "https://github.com/damantha126/youtube-dl-bot/blob/main/plugins/youtube_callback_data.py"
click node_humanbytes "https://github.com/damantha126/youtube-dl-bot/blob/main/utils/util.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_config,node_user_state,node_user toneBlue
class node_start,node_help,node_youtube_request,node_callback_choice,node_callback_download,node_media_send toneAmber
class node_youtube_info,node_download_cli,node_ffmpeg_probe,node_downloads toneMint
class node_humanbytes toneRose
class node_telegram toneIndigo
```

## Components

### Bot runtime

- [Bot entry point](https://github.com/damantha126/youtube-dl-bot/blob/main/bot/__main__.py): `bot/__main__.py`
- [Bot configuration](https://github.com/damantha126/youtube-dl-bot/blob/main/config.py): `config.py`
- [User timing state](https://github.com/damantha126/youtube-dl-bot/blob/main/bot/__init__.py): `bot/__init__.py`

### Telegram interaction

- [Start command](https://github.com/damantha126/youtube-dl-bot/blob/main/plugins/start.py): `plugins/start.py`
- [Help command](https://github.com/damantha126/youtube-dl-bot/blob/main/plugins/help.py): `plugins/help.py`
- [YouTube URL handler](https://github.com/damantha126/youtube-dl-bot/blob/main/plugins/youtube.py): `plugins/youtube.py`
- [Format choice handler](https://github.com/damantha126/youtube-dl-bot/blob/main/plugins/youtube_callback_data.py): `plugins/youtube_callback_data.py`
- [Download callback handler](https://github.com/damantha126/youtube-dl-bot/blob/main/plugins/youtube_callback_data.py): `plugins/youtube_callback_data.py`
- [Media reply](https://github.com/damantha126/youtube-dl-bot/blob/main/plugins/youtube_callback_data.py): `plugins/youtube_callback_data.py`

### Media processing

- [Format and metadata lookup](https://github.com/damantha126/youtube-dl-bot/blob/main/helper/ytdlfunc.py): `helper/ytdlfunc.py`
- [Media downloader](https://github.com/damantha126/youtube-dl-bot/blob/main/helper/ytdlfunc.py): `helper/ytdlfunc.py`
- [Media duration probe](https://github.com/damantha126/youtube-dl-bot/blob/main/helper/ffmfunc.py): `helper/ffmfunc.py`
- [Downloaded media and thumbnails](https://github.com/damantha126/youtube-dl-bot/blob/main/plugins/youtube_callback_data.py): `plugins/youtube_callback_data.py`

### Shared support

- [File size formatter](https://github.com/damantha126/youtube-dl-bot/blob/main/utils/util.py): `utils/util.py`

### Other components

- **Telegram user**
- **Telegram platform**

## Connections

- Bot entry point → Bot configuration: loads credentials (evidence: `bot/__main__.py`)
- Bot entry point → Start command: registers plugins (evidence: `bot/__main__.py`)
- Bot entry point → Help command: registers plugins (evidence: `bot/__main__.py`)
- Bot entry point → YouTube URL handler: registers plugins (evidence: `bot/__main__.py`)
- Bot entry point → Format choice handler: registers plugins (evidence: `bot/__main__.py`)
- Bot entry point → Download callback handler: registers plugins (evidence: `bot/__main__.py`)
- Telegram user → Telegram platform: sends requests (evidence: `README.md`)
- Telegram platform → Start command: dispatches command
- Telegram platform → Help command: dispatches command
- Telegram platform → YouTube URL handler: dispatches URL
- YouTube URL handler → User timing state: reads and updates (evidence: `plugins/youtube.py`)
- YouTube URL handler → Bot configuration: reads interval (evidence: `plugins/youtube.py`)
- YouTube URL handler → Format and metadata lookup: fetches formats (evidence: `plugins/youtube.py`)
- YouTube URL handler → Telegram platform: replies with choices (evidence: `plugins/youtube.py`)
- Format and metadata lookup → File size formatter: formats sizes (evidence: `helper/ytdlfunc.py`)
- Telegram platform → Format choice handler: dispatches selection
- Format choice handler → Telegram platform: updates choices (evidence: `plugins/youtube_callback_data.py`)
- Telegram platform → Download callback handler: dispatches download choice
- Download callback handler → Media downloader: downloads selected media (evidence: `plugins/youtube_callback_data.py`)
- Download callback handler → Media duration probe: gets video duration (evidence: `plugins/youtube_callback_data.py`)
- YouTube URL handler → Downloaded media and thumbnails: writes thumbnail (evidence: `plugins/youtube.py`)
- Download callback handler → Downloaded media and thumbnails: reads thumbnail and saves media (evidence: `plugins/youtube_callback_data.py`)
- Download callback handler → Media reply: schedules media reply (evidence: `plugins/youtube_callback_data.py`)
- Media reply → Telegram platform: sends media (evidence: `plugins/youtube_callback_data.py`)
- Start command → Telegram platform: sends welcome (evidence: `plugins/start.py`)
- Help command → Telegram platform: sends instructions (evidence: `plugins/help.py`)
