# khunhtetznaing/xgetter architecture

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

- Interactive diagram: https://gitdiagram.com/khunhtetznaing/xgetter
- Repository: https://github.com/khunhtetznaing/xgetter

## Overview

##### Main Components
- Library Core (xgetter):
- Core – Contains site-specific classes (e.g., GDrive, DailyMotion, Twitter, etc.) that encapsulate the logic to process and extract video URLs.
- Model – Contains data models (e.g., XModel) used to pass around URL details and metadata.
- Sites – Groups classes for each supported video service (e.g., Facebook, FileRIO, Vidoza, etc.) ensuring extensibility for handling various source sites.
- Utils – Contains utility classes (such as JSUnpacker, GDriveUtils, etc.) used for processing data, parsing JavaScript, or facilitating network operations.

- Sample Application (app):
- A demonstration module for Android that uses the xGetter library.
- Contains the main Android manifest, UI components (Activities such as MainActivity and other layouts), and additional utilities (like XDownloader).
- Acts as an example of how to integrate and consume the library in a real-world Android environment.

- Sample Player (xplayer):
- Focused on showcasing a basic video player (XPlayer.kt) that likely ties into the video extraction library.
- Includes its own Android UI, test cases, and supporting code.

- External Dependencies:
- OkHttp3 is a crucial networking dependency (as mentioned in the README for proguard-rules). Its role is to execute HTTP requests required by the library to fetch and process video URLs.
- Gradle, along with its associated build/config files (build.gradle, settings.gradle, etc.), orchestrates the build and dependency management across these modules.

##### Relationships and Data Flow
- The Application (app) or the Player (xplayer) initiates a request when a user action (like tapping a button) seeks to fetch video content.
- This call is routed to the LowCostVideo class inside the xGetter library. This class acts as a facade/interface for the client code.
- LowCostVideo delegates the actual work to the underlying “Core” components, invoking:
- The correct extraction logic based on the target video service.
- The corresponding Site classes, which encapsulate specific API calls or data extraction algorithms.
- Utility classes that help sanitize or parse input (for example, unpacking embedded JavaScript code using JSUnpacker or decoding responses).
- Network operations (with OkHttp3) are triggered to retrieve raw HTML/JSON data from each video service.
- Once processed, the extracted video URLs (wrapped in XModel objects) are passed back upstream to the calling component (in the sample app or player), which then either displays the choice of qualities or directly plays/downloads the video.

##### Architectural Patterns/Design Principles
- Modular Architecture: The project cleanly separates functionality into different modules (xgetter for core logic, app for demonstration, xplayer for playback).
- Facade Design Pattern: LowCostVideo in the library acts as a façade distributing control to the appropriate extraction logic.
- Plugin/Extension Points: The structure within the “Sites” directory suggests that adding support for new video sources can be accomplished by adding new classes.
- Separation of Concerns: The sample app, player, and library keep UI, business logic, and site-specific extraction code distinct.

- Each module (app, xgetter, xplayer) should be a clearly defined block.
- Within the xgetter module, subdivide into:
- Core (for main processing and extraction logic)
- Sites (listing supported sites – you might add a note that there are 30+ supported sites)
- Model (for data structures like XModel)
- Utils (for helper methods and classes like JSUnpacker)
- Dependency from LowCostVideo to the Site and Util components.
- Notes on external configuration due to Gradle and proguard, to remind that proper network and obfuscation settings are important.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Library Module (xgetter)"
        LCV["LowCostVideo (Facade)"]:::facade
        subgraph "Internal Components"
            CORE["Core Extraction Logic"]:::core
            MODEL["Data Models (XModel)"]:::model
            SITES["Supported Sites Modules"]:::sites
            UTILS["Utility Classes"]:::utils
        end
    end

    APP["App UI (MainActivity)"]:::ui
    PLAYER["Player UI (XPlayer)"]:::ui
    OKHTTP["OkHttp3 (HTTP Client)"]:::external
    GRADLE["Gradle Build Config"]:::gradle

    APP -->|"API_Call"| LCV
    PLAYER -->|"API_Call"| LCV
    LCV -->|"delegates"| CORE
    LCV -->|"routesTo"| SITES
    LCV -->|"calls"| UTILS
    CORE -->|"encapsulateData"| MODEL
    CORE -->|"HTTP_Request"| OKHTTP
    SITES -->|"HTTP_Request"| OKHTTP
    OKHTTP -->|"response"| CORE
    GRADLE ---|"build/deps"| LCV

    click LCV "https://github.com/khunhtetznaing/xgetter/blob/master/xgetter/src/main/java/com/htetznaing/lowcostvideo/LowCostVideo.java"
    click CORE "https://github.com/khunhtetznaing/xgetter/tree/master/xgetter/src/main/java/com/htetznaing/lowcostvideo/Core"
    click MODEL "https://github.com/khunhtetznaing/xgetter/tree/master/xgetter/src/main/java/com/htetznaing/lowcostvideo/Model"
    click SITES "https://github.com/khunhtetznaing/xgetter/tree/master/xgetter/src/main/java/com/htetznaing/lowcostvideo/Sites"
    click UTILS "https://github.com/khunhtetznaing/xgetter/tree/master/xgetter/src/main/java/com/htetznaing/lowcostvideo/Utils"
    click APP "https://github.com/khunhtetznaing/xgetter/tree/master/app/src/main/java/com/htetznaing/xgetterexample"
    click PLAYER "https://github.com/khunhtetznaing/xgetter/blob/master/xplayer/src/main/java/com/htetznaing/xplayer/XPlayer.kt"
    click GRADLE "https://github.com/khunhtetznaing/xgetter/blob/master/build.gradle"

    classDef facade fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef core fill:#ffcccb,stroke:#000,stroke-width:2px;
    classDef model fill:#d3d3d3,stroke:#000,stroke-width:2px;
    classDef sites fill:#fdfd96,stroke:#000,stroke-width:2px;
    classDef utils fill:#c1e1c1,stroke:#000,stroke-width:2px;
    classDef ui fill:#ffa07a,stroke:#000,stroke-width:2px;
    classDef external fill:#dda0dd,stroke:#000,stroke-width:2px;
    classDef gradle fill:#87cefa,stroke:#000,stroke-width:2px;
```
