# xrontrix10/telegram-leecher architecture

> Architecture diagram of the GitHub repository xrontrix10/telegram-leecher, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/xrontrix10/telegram-leecher
- Repository: https://github.com/xrontrix10/telegram-leecher

## Overview

##### Project Type & Purpose
- This is a Pyrogram-based Telegram Bot designed to run inside a Google Colab notebook.
- It automates downloading files/folders from a variety of sources (direct links, Google Drive, Telegram, YouTube, etc.), optionally converts or zips them, then uploads them to Telegram chats or Google Drive.

##### File Structure & Architectural Patterns
- Top-level entrypoints:
- main.py – likely parses command-line or notebook arguments and launches the bot.
- colab_leecher/__main__.py – makes the package executable (python ‑m colab_leecher).
- Subpackages:
- downloader/ – a “download strategy” layer with one module per source (aria2, gdrive, mega, telegram, terabox, ytdl) and manager.py to pick the right strategy.
- uploader/ – handles uploads (currently Telegram).
- utility/ – cross-cutting services (converters, zipping/splitting, task_manager, handler for commands, shared variables).
- No persistent database; uses in-memory or file-system staging within the Colab container.

##### Key Technologies & External Services
- Python, Pyrogram (Telegram Bot API), google-drive API (via pydrive or direct HTTP), aria2 RPC, youtube-dl, file-system libraries, zip/split utils.
- Colab runtime environment as a Docker-like container.
- External hosts: Google Drive, Telegram servers, third-party file hosts.

a. Entry Point
- Notebook / main.py / __main__.py
- Initializes Pyrogram Bot client and command handler
b. Command & Task Handler
- utility/handler.py – maps incoming Telegram bot commands to tasks
- utility/task_manager.py – schedules and tracks download/upload tasks
c. Download Manager
- downloader/manager.py – inspects link type and dispatches to one of:
– aria2.py
– gdrive.py
– mega.py
– telegram.py
– terabox.py
– ytdl.py
d. Utilities
- utility/converters.py – video conversions (mp4/mkv)
- utility/helper.py – zipping, splitting, thumbnail generation
- utility/variables.py – configuration constants
e. Upload Module
- uploader/telegram.py – sends files to Telegram chats
- (Optionally in future: uploader/gdrive.py)
f. External Services & Storage
- Local Colab file system (staging area)
- Google Drive API
- Telegram Bot API & File servers
- Third-party file hosts (YouTube, direct links, etc.)

##### Data Flow & Interactions
1. User sends a Telegram command → Pyrogram Bot
2. Handler parses command → Task Manager
3. Task Manager invokes Download Manager → selects appropriate downloader module → fetches file(s) → writes to local Colab storage
4. After download completes → Utility modules (conversion, zipping, thumbnail) process files
5. Processed file handed to Uploader → forwarded to Telegram or Google Drive
6. Bot sends completion status or errors back to the user

##### Architectural Patterns & Principles
- Strategy Pattern in downloader modules
- Single Responsibility: each module does one thing (download, convert, upload, handle commands)
- Layered structure: Entry → Handler → Manager → Workers → External
- Pluggable extensibility: adding a new downloader is as simple as creating a new module + updating manager.py

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Colab-Leecher Package in Colab Environment"
        direction TB

        subgraph "Entry / CLI & Notebook"
            direction TB
            Notebook(("Notebook Interface")):::entry
            Main["main.py"]:::entry
            CLI["__main__.py"]:::entry
        end

        subgraph "Core Logic"
            direction TB
            Handler["handler.py"]:::core
            TaskMgr["task_manager.py"]:::core
            DLMgr["manager.py"]:::core
        end

        subgraph "Worker Modules"
            direction TB
            aria2["aria2.py"]:::worker
            gdrive_dl["gdrive.py"]:::worker
            mega["mega.py"]:::worker
            telegram_dl["telegram.py"]:::worker
            terabox["terabox.py"]:::worker
            ytdl["ytdl.py"]:::worker
            Conv["converters.py"]:::worker
            Helper["helper.py"]:::worker
            Vars["variables.py"]:::worker
            UpTele["telegram.py"]:::worker
        end
    end

    subgraph "External Services"
        direction TB
        GD(("Google Drive API")):::external
        TG(("Telegram Bot API")):::external
        Third(("Third-Party Hosts")):::external
    end

    %% Data Flows
    TG -->|"1. command"| Handler
    Notebook -->|"launch"| Main
    Main -->|"invoke"| CLI
    CLI -->|"init Pyrogram"| Handler
    Handler -->|"2. schedule"| TaskMgr
    TaskMgr -->|"3. dispatch"| DLMgr
    DLMgr -->|"select strategy"| aria2
    DLMgr --> aria2
    DLMgr --> gdrive_dl
    DLMgr --> mega
    DLMgr --> telegram_dl
    DLMgr --> terabox
    DLMgr --> ytdl
    aria2 -->|"download"| Helper
    gdrive_dl --> Helper
    mega --> Helper
    telegram_dl --> Helper
    terabox --> Helper
    ytdl --> Helper
    Helper -->|"process"| Conv
    Conv -->|"prepare"| UpTele
    UpTele -->|"upload"| TG
    UpTele -->|"upload"| GD
    Third -->|"source"| DLMgr

    %% Click Events
    click Main "https://github.com/xrontrix10/telegram-leecher/blob/main/main.py"
    click CLI "https://github.com/xrontrix10/telegram-leecher/blob/main/colab_leecher/__main__.py"
    click Handler "https://github.com/xrontrix10/telegram-leecher/blob/main/colab_leecher/utility/handler.py"
    click TaskMgr "https://github.com/xrontrix10/telegram-leecher/blob/main/colab_leecher/utility/task_manager.py"
    click DLMgr "https://github.com/xrontrix10/telegram-leecher/blob/main/colab_leecher/downlader/manager.py"
    click aria2 "https://github.com/xrontrix10/telegram-leecher/blob/main/colab_leecher/downlader/aria2.py"
    click gdrive_dl "https://github.com/xrontrix10/telegram-leecher/blob/main/colab_leecher/downlader/gdrive.py"
    click mega "https://github.com/xrontrix10/telegram-leecher/blob/main/colab_leecher/downlader/mega.py"
    click telegram_dl "https://github.com/xrontrix10/telegram-leecher/blob/main/colab_leecher/downlader/telegram.py"
    click terabox "https://github.com/xrontrix10/telegram-leecher/blob/main/colab_leecher/downlader/terabox.py"
    click ytdl "https://github.com/xrontrix10/telegram-leecher/blob/main/colab_leecher/downlader/ytdl.py"
    click Conv "https://github.com/xrontrix10/telegram-leecher/blob/main/colab_leecher/utility/converters.py"
    click Helper "https://github.com/xrontrix10/telegram-leecher/blob/main/colab_leecher/utility/helper.py"
    click Vars "https://github.com/xrontrix10/telegram-leecher/blob/main/colab_leecher/utility/variables.py"
    click UpTele "https://github.com/xrontrix10/telegram-leecher/blob/main/colab_leecher/uploader/telegram.py"

    %% Styles
    classDef entry fill:#B3E5FC,stroke:#0288D1,stroke-width:1px
    classDef core fill:#C8E6C9,stroke:#2E7D32,stroke-width:1px
    classDef worker fill:#FFF9C4,stroke:#F9A825,stroke-width:1px
    classDef external fill:#FFCDD2,stroke:#C62828,stroke-width:1px
```
