# ihmily/douyinliverecorder architecture

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

- Interactive diagram: https://gitdiagram.com/ihmily/douyinliverecorder
- Repository: https://github.com/ihmily/douyinliverecorder

## Overview

##### Project Type and Purpose
- This project is a multi-platform live streaming recorder that uses FFmpeg under the hood to capture and record live streams from various platforms (e.g., Douyin, TikTok, TwitchTV, etc.).
- Its purpose is to continuously monitor live-streaming URLs (configured through files like URL_config.ini) and record them while also supporting additional features like live status push notifications.

##### File Structure
- At the top level you have configuration files (e.g., “config/config.ini”, “config/URL_config.ini”), build and container orchestration files (Dockerfile, docker-compose.yaml, .dockerignore), and various deployment scripts (StopRecording.vbs, ffmpeg_install.py).
- Multiple Python scripts are present (e.g., main.py, demo.py, msg_push.py, i18n.py) along with dependency management files (requirements.txt, pyproject.toml, poetry.toml, setup.py).
- The “streamget” directory appears to be the core package containing modules that handle HTTP requests (async_http.py, sync_http.py), logging (logger.py), room info, stream grabbing, decryption (javascript folder with several JS files), as well as utility functions.
- Internationalization resources are stored under “i18n” for language translations.
- Docker and GitHub actions files indicate containerization, CI/CD, and deployment workflows.

##### Key Components and Their Captured Roles
- Configuration & Initialization: Config directory (URL_config.ini, config.ini) plus initializer.py or initializer-like calls ensure environment setup (nodejs check, proxy settings, etc.).
- Core Recording Engine:
- Main Controller: main.py, responsible for launching the overall recording process.
- Platform-specific Modules: In “streamget”, modules like spider.py (retrieves live stream data), room.py (fetches room info), stream.py (retrieves streaming address), and proxy.py which likely manages connection proxies.
- HTTP Clients: Both asynchronous and synchronous HTTP interactions are handled in the “http_clients” module.
- FFmpeg Integration: ffmpeg_install.py and the presence of ffmpeg.exe highlight the integration of the FFmpeg engine to perform actual streaming capture.
- Logging & Utilities: logger.py manages logging, and utils.py provides support functions.
- JavaScript Decryption: The “javascript” folder holds scripts to decrypt certain platform-specific streaming parameters (haixiu.js, liveme.js, etc.).
- Message Push Notifications: msg_push.py handles the live status notifications.
- Internationalization: The “i18n” folder, along with i18n.py, relates to providing multi-language support.

##### Relationships and Data Flow
- The main controller (main.py) coordinates the overall workflow:
– It reads configuration files from the config directory.
– It initializes the environment (using initializer.py) and sets up dependencies.
– It leverages the modules from the “streamget” package to fetch live video stream data, coordinate with appropriate HTTP clients, and then interface with FFmpeg to record streams.
- The recorded streams are saved into output directories (e.g., “downloads”) as indicated in the README.
- Status updates and potential notifications are pushed using the msg_push.py module.
- The system’s modular approach (separate modules for HTTP requests, logging, and platform-specific processing) signals a loosely coupled design.

##### Architectural Patterns & Technologies
- Modular Design: The project is partitioned into self-contained components (configuration, stream fetching, processing, notifications). This separation aids in maintenance and extensibility.
- Client-Server-Like Flow: While not a full microservice architecture, the separation of tasks (fetching with HTTP clients, processing with spiders, and controlling with main.py) can be conceptualized as “components talking” via well-defined interfaces.
- Use of Third-Party Tools: Integration with FFmpeg for processing and Docker for containerization are key points.
- Internationalization support and CI/CD pipelines (GitHub workflows) highlight additional concerns managed by the project.

##### Final Reminders for the Principal Software Engineer
- Be very detailed: It’s best to break down the application into as many logical components as possible based on the roles of each module.
- Configuration/Initialization → Orchestration (main.py) → Platform-specific data fetching → Stream processing (via FFmpeg) and logging/notification.
- Highlighting design principles like modularity and separation of concerns.
- You capture essential dependencies such as:
- Python version requirement (≥3.10)
- FFmpeg installation and integration
- Docker container orchestration (Dockerfile, docker-compose)
- External live streaming platforms (as inputs).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Configuration & Initialization
    subgraph "Configuration & Initialization"
        A1["config.ini"]:::config
        A2["URL_config.ini"]:::config
        A3["initializer.py"]:::config
    end

    %% Main Controller
    B["Main Controller (main.py)"]:::controller

    %% Platform-specific Modules
    subgraph "Platform-specific Modules"
        P1["Live-stream Data Fetcher (spider.py)"]:::platform
        P2["Room Information Fetcher (room.py)"]:::platform
        P3["Stream Address Retriever (stream.py)"]:::platform
        P4["Proxy Manager (proxy.py)"]:::platform
        P1 --- P2
        P2 --- P3
        P3 --- P4
    end

    %% HTTP Client Layer
    subgraph "HTTP Client Layer"
        H1["Asynchronous HTTP Client (async_http.py)"]:::http
        H2["Synchronous HTTP Client (sync_http.py)"]:::http
        H1 --- H2
    end

    %% Decryption Logic
    subgraph "Decryption Logic"
        J["Decryption Scripts (javascript)"]:::decryption
    end

    %% FFmpeg Integration
    F["FFmpeg Integration (ffmpeg_install.py)"]:::ffmpeg

    %% Logging & Utilities
    subgraph "Logging & Utilities"
        L1["Logger (logger.py)"]:::logging
        L2["Utilities (utils.py)"]:::logging
        L1 --- L2
    end

    %% Message Push Notifications
    N["Message Push Notifications (msg_push.py)"]:::notification

    %% Internationalization Support
    subgraph "Internationalization"
        I1["Internationalization Script (i18n.py)"]:::i18n
        I2["Language Resources (i18n)"]:::i18n
        I1 --- I2
    end

    %% Containerization & CI/CD
    subgraph "Containerization & CI/CD"
        D1["Dockerfile"]:::container
        D2["docker-compose.yaml"]:::container
        D3[".dockerignore"]:::container
        D4[".github Workflows"]:::container
        D1 --- D2
        D2 --- D3
        D3 --- D4
    end

    %% Data Flow Connections
    A1 --> B
    A2 --> B
    A3 --> B

    B -->|"triggers"| P1
    B -->|"calls"| H1
    B -->|"invokes"| J
    B -->|"integrates"| F
    B -->|"logs via"| L1
    B -->|"notifies"| N
    B -->|"supports"| I1

    %% Containerization as external dependency
    D1 -.-> B

    %% Class Definitions for Colors and Styles
    classDef config fill:#FAD7A0,stroke:#C0392B,stroke-width:2px;
    classDef controller fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef platform fill:#D5F5E3,stroke:#28B463,stroke-width:2px;
    classDef http fill:#FCF3CF,stroke:#F1C40F,stroke-width:2px;
    classDef decryption fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef ffmpeg fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef logging fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px;
    classDef notification fill:#FADBD8,stroke:#C0392B,stroke-width:2px;
    classDef i18n fill:#E8F8F5,stroke:#1ABC9C,stroke-width:2px;
    classDef container fill:#F0F3F4,stroke:#95A5A6,stroke-width:2px;

    %% Click Events for Configuration & Initialization
    click A1 "https://github.com/ihmily/douyinliverecorder/blob/main/config/config.ini"
    click A2 "https://github.com/ihmily/douyinliverecorder/blob/main/config/URL_config.ini"
    click A3 "https://github.com/ihmily/douyinliverecorder/blob/main/streamget/initializer.py"

    %% Click Event for Main Controller
    click B "https://github.com/ihmily/douyinliverecorder/blob/main/main.py"

    %% Click Events for Platform-specific Modules
    click P1 "https://github.com/ihmily/douyinliverecorder/blob/main/streamget/spider.py"
    click P2 "https://github.com/ihmily/douyinliverecorder/blob/main/streamget/room.py"
    click P3 "https://github.com/ihmily/douyinliverecorder/blob/main/streamget/stream.py"
    click P4 "https://github.com/ihmily/douyinliverecorder/blob/main/streamget/proxy.py"

    %% Click Events for HTTP Client Layer
    click H1 "https://github.com/ihmily/douyinliverecorder/blob/main/streamget/http_clients/async_http.py"
    click H2 "https://github.com/ihmily/douyinliverecorder/blob/main/streamget/http_clients/sync_http.py"

    %% Click Event for Decryption Logic
    click J "https://github.com/ihmily/douyinliverecorder/tree/main/streamget/javascript"

    %% Click Event for FFmpeg Integration
    click F "https://github.com/ihmily/douyinliverecorder/blob/main/ffmpeg_install.py"

    %% Click Events for Logging & Utilities
    click L1 "https://github.com/ihmily/douyinliverecorder/blob/main/streamget/logger.py"
    click L2 "https://github.com/ihmily/douyinliverecorder/blob/main/streamget/utils.py"

    %% Click Event for Message Push Notifications
    click N "https://github.com/ihmily/douyinliverecorder/blob/main/msg_push.py"

    %% Click Events for Internationalization
    click I1 "https://github.com/ihmily/douyinliverecorder/blob/main/i18n.py"
    click I2 "https://github.com/ihmily/douyinliverecorder/tree/main/i18n"

    %% Click Events for Containerization & CI/CD
    click D1 "https://github.com/ihmily/douyinliverecorder/tree/main/Dockerfile"
    click D2 "https://github.com/ihmily/douyinliverecorder/blob/main/docker-compose.yaml"
    click D3 "https://github.com/ihmily/douyinliverecorder/blob/main/.dockerignore"
    click D4 "https://github.com/ihmily/douyinliverecorder/blob/main/.github"
```
