# jackaopen/jatubeplayer architecture

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

- Interactive diagram: https://gitdiagram.com/jackaopen/jatubeplayer
- Repository: https://github.com/jackaopen/jatubeplayer

## Overview

##### Project type and purpose
- JaTubePlayer is a desktop media‐player application written in Python.
- It supports both local playback (files/folders) and online playback (YouTube videos and live streams), plus features like video archiving, recommendation, and secure OAuth-based access to personal playlists, likes, and subscriptions.
- The public repository only exposes a handful of modules (e.g., get_related_video.py, sub_and_like_public.py) and summary docs—selected “open‐source” pieces—while the core player, GUI, and internal libraries remain closed/obfuscated.

##### File structure
- Top‐level:
- LICENSE.md, README.md
- get_related_video.py & get_related_video_summary.md
- sub_and_like_public.py & sub_and_like_summary.md
- The absence of folders like `frontend/` or `_internal/` in this tree indicates that this is a partial open-source slice. The full code (not in this tree) likely contains:
- GUI code (tkinter + sv_ttk)
- Playback engine integration (python-mpv + ffmpeg)
- Settings & token storage modules
- Internal bundling of `yt_dlp`, `ffmpeg.exe`, `libmpv-2.dll`
- Encryption module (Fernet-based, dual-key)

##### README for additional insights
- Core features listed under “Core Features” and “Advanced Features” reveal the major subsystems:
- Local file player
- Online video search & streaming (yt_dlp + mpv)
- Download/archive manager
- Recommendation engine (get_related_video.py)
- OAuth login & Google API client for playlists, likes, subscriptions (sub_and_like_public.py)
- Token encryption (cryptography + Fernet dual-key)
- Settings panel with version check and cookie management

a. Main components
1. User Interface (Tkinter + sv_ttk)
2. Controller / Event Handlers
3. Playback Engine
– python-mpv binding
– ffmpeg (ffmpeg.exe, ffprobe.exe)
4. Online Video Service
– yt_dlp library (in `_internal/yt_dlp`)
5. Download Manager
6. Recommendation Service
– get_related_video.py
7. Google API Client
– sub_and_like_public.py
– google-auth & google-api-python-client
8. Encryption Module
– Fernet-based dual-key store
9. Local Storage
– download_output/
– token/key store
10. Version Check Service
11. External Services
– YouTube Data API v3
– YouTube web servers (video streams)

b. Relationships & data flows
- UI ↔ Controller
- Controller → Playback Engine (play local or stream)
- Controller → yt_dlp (search metadata, stream URLs, download)
- Controller → Download Manager → Local Storage
- Controller → Recommendation Service → UI
- Controller → Google API Client ↔ External Google API → Local Storage
- Encryption Module mediates reads/writes of OAuth tokens and API keys
- Version Check Service polls GitHub releases or yt_dlp releases for updates

c. Architectural patterns & principles
- MVC-like separation:
- View = Tkinter UI
- Controller = event handlers mapping UI actions to service calls
- Model = settings, token store, local video metadata
- Service-oriented components for:
- Playback Engine
- Online Video Service
- Download Manager
- Recommendation & History
- API Client & Encryption
- Dependency isolation: bundling of external binaries/libraries under `_internal/`, root for ffmpeg & mpv DLLs

d. Key technologies
- Python 3.11+, tkinter, sv_ttk
- python-mpv, ffmpeg, ffprobe
- yt_dlp
- cryptography (Fernet), google-auth, google-api-python-client
- Pillow, requests

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        UI["User Interface\n(Tkinter + sv_ttk)"]:::ui
    end

    %% Core Controller
    Controller["Controller / Event Handlers"]:::core

    %% Core Services
    subgraph "Core Services"
        Playback["Playback Engine\n(python-mpv binding)"]:::core
        OnlineService["Online Video Service\n(yt_dlp)"]:::core
        DownloadMgr["Download Manager"]:::core
        Recommendation["Recommendation Service"]:::core
        GoogleAPI["Google API Client"]:::core
        Encryption["Encryption Module\n(Fernet dual-key)"]:::core
        VersionCheck["Version Check Service"]:::core
    end

    %% Storage
    subgraph "Storage"
        LocalStorage["Local Storage\n(download_output/, settings, tokens)"]:::storage
    end

    %% External
    subgraph "External Services"
        YouTubeAPI["YouTube Data API v3"]:::external
        YouTubeStream["YouTube Web Servers\n(video streams)"]:::external
    end

    %% Docs
    subgraph "Repository Docs"
        README["Project Overview\n(README.md)"]:::doc
        LICENSE["Project License\n(LICENSE.md)"]:::doc
        RecDoc["Recommendation Service Docs\n(get_related_video_summary.md)"]:::doc
        APIDoc["Google API Client Docs\n(sub_and_like_summary.md)"]:::doc
    end

    %% Relationships
    UI -->|interacts| Controller
    Controller -->|mpv Binding| Playback
    Controller -->|HTTP via yt_dlp| OnlineService
    Controller -->|manage downloads| DownloadMgr
    Controller -->|get recommendations| Recommendation
    Controller -->|call API| GoogleAPI
    Controller -->|check updates| VersionCheck
    DownloadMgr -->|store media| LocalStorage
    Recommendation -->|send list| UI
    GoogleAPI -->|OAuth tokens| Encryption
    GoogleAPI -->|store tokens| LocalStorage
    GoogleAPI -->|REST via google-api-python-client| YouTubeAPI
    Encryption -->|encrypt/decrypt| LocalStorage
    OnlineService -->|stream URLs| YouTubeStream
    VersionCheck -->|poll releases| YouTubeAPI

    %% Click Events
    click Recommendation "https://github.com/jackaopen/jatubeplayer/blob/main/get_related_video.py"
    click RecDoc "https://github.com/jackaopen/jatubeplayer/blob/main/get_related_video_summary.md"
    click GoogleAPI "https://github.com/jackaopen/jatubeplayer/blob/main/sub_and_like_public.py"
    click APIDoc "https://github.com/jackaopen/jatubeplayer/blob/main/sub_and_like_summary.md"
    click README "https://github.com/jackaopen/jatubeplayer/blob/main/README.md"
    click LICENSE "https://github.com/jackaopen/jatubeplayer/blob/main/LICENSE.md"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366d6,color:#0366d6
    classDef core fill:#D0F0D8,stroke:#28a745,color:#28a745
    classDef storage fill:#FFF5B1,stroke:#dbab09,color:#856404
    classDef external fill:#E2E3E5,stroke:#6c757d,color:#6c757d
    classDef doc fill:#F0E6FF,stroke:#6f42c1,color:#6f42c1
```
