# nrafinia/emby.subtitle.subscene architecture

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

- Interactive diagram: https://gitdiagram.com/nrafinia/emby.subtitle.subscene
- Repository: https://github.com/nrafinia/emby.subtitle.subscene

## Overview

The Emby.Subtitle.Subscene project is a plugin designed to integrate with the Emby media server, providing subtitle support by retrieving subtitles from the Subscene service. The README makes it clear that the primary purpose is to offer subtitle support for a wide range of languages, while the file tree reveals a focused structure with a single solution that encapsulates models, providers, and integration entry points.

##### Main Components
- Plugin Interface: At the heart is the Plugin (Plugin.cs) which acts as the integration point with Emby.
- Models: The Models folder holds data entities such as FindMovie, MovieInformation, TvEpisodeResult, etc. These represent the key data structures used throughout the plugin.
- Providers: The Providers folder contains the logic to interact with external services, split into components for movies (SubsceneSubtitleProviderMovie) and TV shows (SubsceneSubtitleProviderTV) along with general utilities (Tools.cs). Additionally, there is a MovieDb component which likely handles interactions with a movie database.
- Test Suite: The Test folder contains various tests targeting the providers and overall functionality, which is useful for verifying the integration and functionality of the plugin.

##### Relationships and Interactions
- The Plugin component acts as the entry point and orchestrates operations using functions provided by the underlying providers.
- The Providers (movie and TV specific) are responsible for fetching and processing subtitles, relying on Models to structure any data retrieved.
- Utility functions in Tools (and possibly MovieDb) support these providers by handling external API calls or additional data processing.
- The Tests section, although not part of the runtime architecture, verifies that the internal interactions (Plugin → Providers → Models) are behaving as expected.

##### Architectural Patterns and Design Principles
- Plugin Architecture: This module-based architecture supports the dynamic addition of features within the Emby ecosystem.
- Separation of Concerns: Models, Providers, and the Plugin itself are clearly separated, allowing for modular development and easier testing.
- Abstraction: Each Provider abstracts the interaction with the external subtitle sources by splitting the concerns for movies and TV episodes.
- Testability: The presence of a dedicated Test project emphasizes the importance of isolated testing of components.

##### Relevant Technologies and Frameworks
- .NET Framework: The project is implemented in C# (as evident from the .csproj and solution files).
- NCrunch: Configuration files (.ncrunchproject) indicate usage of NCrunch for continuous testing.
- (Implicit) HTTP or Web Request Components: Providers likely use HTTP calls to interact with Subscene, although the implementation details might be abstracted away.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Plugin Layer
    subgraph "Plugin Layer"
        P["Plugin Interface"]:::plugin
    end

    %% Business Logic Layer
    subgraph "Business Logic"
        subgraph "Providers"
            BP["Base Subtitle Provider"]:::providers
            MP["Movie Subtitle Provider"]:::providers
            TVP["TV Subtitle Provider"]:::providers
            MDB["Movie Database Handler"]:::providers
            TLS["Utility Functions (Tools)"]:::providers
        end
        M["Models"]:::models
    end

    %% External Services
    subgraph "External Services"
        SUB["Subscene Service"]:::external
    end

    %% Test Suite
    subgraph "Test Suite"
        T["Test Suite"]:::test
    end

    %% Connections
    P -->|"SubtitleRequest"| BP
    P -->|"SubtitleRequest"| MP
    P -->|"SubtitleRequest"| TVP

    BP -->|"DataRetrieval"| M
    MP -->|"DataRetrieval"| M
    TVP -->|"DataRetrieval"| M

    MP -->|"UsesMovieDb"| MDB
    TVP -->|"UsesMovieDb"| MDB

    MP -->|"UsesUtility"| TLS
    TVP -->|"UsesUtility"| TLS

    BP -->|"HTTPCall"| SUB
    MP -->|"HTTPCall"| SUB
    TVP -->|"HTTPCall"| SUB

    T -->|"Validates"| P
    T -->|"Validates"| BP
    T -->|"Validates"| MP
    T -->|"Validates"| TVP
    T -->|"Validates"| M

    %% Click Events
    click P "https://github.com/nrafinia/emby.subtitle.subscene/blob/master/src/Emby.Subtitle.Subscene/Plugin.cs"
    click M "https://github.com/nrafinia/emby.subtitle.subscene/tree/master/src/Emby.Subtitle.Subscene/Models"
    click BP "https://github.com/nrafinia/emby.subtitle.subscene/blob/master/src/Emby.Subtitle.Subscene/Providers/SubsceneSubtitleProvider.cs"
    click MP "https://github.com/nrafinia/emby.subtitle.subscene/blob/master/src/Emby.Subtitle.Subscene/Providers/SubsceneSubtitleProviderMovie.cs"
    click TVP "https://github.com/nrafinia/emby.subtitle.subscene/blob/master/src/Emby.Subtitle.Subscene/Providers/SubsceneSubtitleProviderTV.cs"
    click MDB "https://github.com/nrafinia/emby.subtitle.subscene/blob/master/src/Emby.Subtitle.Subscene/Providers/MovieDb.cs"
    click TLS "https://github.com/nrafinia/emby.subtitle.subscene/blob/master/src/Emby.Subtitle.Subscene/Providers/Tools.cs"
    click T "https://github.com/nrafinia/emby.subtitle.subscene/tree/master/src/Test"

    %% Styles
    classDef plugin fill:#f9e79f,stroke:#b7950b,stroke-width:2px;
    classDef providers fill:#aed6f1,stroke:#2980b9,stroke-width:2px;
    classDef models fill:#abebc6,stroke:#27ae60,stroke-width:2px;
    classDef external fill:#f5b7b1,stroke:#c0392b,stroke-width:2px;
    classDef test fill:#f7c6c7,stroke:#a93226,stroke-width:2px;
```
