# jumblebumble/customtv architecture

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

- Interactive diagram: https://gitdiagram.com/jumblebumble/customtv
- Repository: https://github.com/jumblebumble/customtv

## Overview

##### Project type and purpose
- This is a Unity-based game mod (CustomTV) built as a Melon Loader plugin for the game “Schedule I.”
- Its purpose is to hijack in-game “TV” objects and play local MP4s or YouTube videos via Unity’s VideoPlayer.

##### File structure
- Top‐level:
- CustomTV.csproj / CustomTV.sln → C# project/solution
- MainMod.cs → mod entry point
- Utils/ → shared helpers (state, extensions, comparers, video metadata)
- Utils/YoutubeUtils/ → YouTube-specific download and UI code
- No separate “frontend” or “backend” folders – it’s a single plugin assembly loaded into the game.
- Configuration is handled via MelonPreferences.cfg (no custom config file in repo).
- External dependency: yt-dlp executable called at runtime to fetch YouTube videos.

##### README for additional insights
- Hooks into Melon Loader and Unity VideoPlayer.
- Manages shuffle/sort logic (SmartEpisodeComparer).
- Caches downloaded YouTube videos on disk (max #, auto-cleanup).
- Responds to hotkeys (Ctrl+Shift + key) to control playback and trigger downloads.

##### Detail
- Config as a distinct component (MelonPreferences.cfg) showing read/write interactions.
- Cleanup logic: on exit or cache overflow → FileManager/YouTubeManager delete old files.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Host Systems
    Unity["Unity Runtime"]:::host
    MelonLoader["Melon Loader"]:::host

    Unity -->|"Host Mod Framework"| MelonLoader

    %% Plugin Boundary
    subgraph "CustomTV Plugin" 
        direction TB
        MainMod["MainMod"]:::plugin
        SettingsManager["SettingsManager"]:::plugin
        FileManager["FileManager"]:::plugin
        VideoManager["VideoManager"]:::plugin
        InputHandler["InputHandler"]:::plugin

        %% Utils Components
        VideoModel["Video Model"]:::plugin
        SmartEpisodeComparer["SmartEpisodeComparer"]:::plugin
        Extensions["Extensions"]:::plugin

        subgraph "YouTubeUtils"
            direction TB
            YouTubeManager["YouTubeManager"]:::plugin
            VideoHandlers["VideoHandlers"]:::plugin
            Playlist["Playlist"]:::plugin
            UI["UI"]:::plugin
        end
    end

    %% Storage and Config
    ConfigFile["MelonPreferences.cfg"]:::storage
    TVFolder["Mods/TV Folder (MP4 cache)"]:::storage

    %% Video Playback
    VideoPlayerComponent["Unity VideoPlayer"]:::host

    %% External Services
    YouTube["YouTube"]:::externalService
    YtDlpProcess["yt-dlp Process"]:::externalProc

    %% Initialization Flow
    MelonLoader -->|"Load DLL"| MainMod
    MainMod -->|"Initialize"| SettingsManager
    SettingsManager -->|"Read config"| ConfigFile
    MainMod -->|"Scan folders"| FileManager
    FileManager -->|"List MP4 files"| TVFolder
    FileManager -->|"Provide playlist"| VideoManager

    %% Input & Playback Flow
    MainMod -->|"Register Input"| InputHandler
    InputHandler -->|"Hotkey events"| VideoManager
    VideoManager -->|"Control"| VideoPlayerComponent
    VideoPlayerComponent -->|"Render"| Unity

    %% YouTube Download Flow
    InputHandler -->|"Paste URL command"| YouTubeManager
    YouTubeManager -->|"Launch download"| YtDlpProcess
    YtDlpProcess -->|"Output MP4"| TVFolder
    YouTubeManager -->|"Track & serve file"| VideoManager
    YouTubeManager --> UI
    YouTubeManager --> VideoHandlers
    YouTubeManager --> Playlist

    %% Cleanup Logic
    MainMod -->|"On exit or cache overflow"| FileManager
    MainMod -->|"On exit or cache overflow"| YouTubeManager
    FileManager -->|"Delete old files"| TVFolder
    YouTubeManager -->|"Delete old files"| TVFolder

    %% Utils relations
    VideoManager --> VideoModel
    VideoManager --> SmartEpisodeComparer
    VideoManager --> Extensions

    %% Click Events
    click MainMod "https://github.com/jumblebumble/customtv/blob/master/MainMod.cs"
    click SettingsManager "https://github.com/jumblebumble/customtv/blob/master/Utils/CustomTVState.cs"
    click VideoModel "https://github.com/jumblebumble/customtv/blob/master/Utils/Video.cs"
    click SmartEpisodeComparer "https://github.com/jumblebumble/customtv/blob/master/Utils/SmartEpisodeComparer.cs"
    click Extensions "https://github.com/jumblebumble/customtv/blob/master/Utils/Extensions.cs"
    click YouTubeManager "https://github.com/jumblebumble/customtv/blob/master/Utils/YoutubeUtils/Youtube.cs"
    click VideoHandlers "https://github.com/jumblebumble/customtv/blob/master/Utils/YoutubeUtils/VideoHandlers.cs"
    click Playlist "https://github.com/jumblebumble/customtv/blob/master/Utils/YoutubeUtils/Playlist.cs"
    click UI "https://github.com/jumblebumble/customtv/blob/master/Utils/YoutubeUtils/UI.cs"

    %% Styles
    classDef host fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef plugin fill:#98FB98,stroke:#333,stroke-width:1px
    classDef storage fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef externalService fill:#FFA500,stroke:#333,stroke-width:1px
    classDef externalProc fill:#D3D3D3,stroke:#333,stroke-width:1px
```
